2010-01-15 4 views
0

이 내 코드의 일부입니다왜 나는이 추적을 받는가?

if ind_1<>0:    
rbrcol=[] 
brdod1=[] 
for i in range(27): 
    if Add_Cyc_1[1,i]!=0: 
     rbrcol.append(Add_Cyc_1[0,i]) 
     brdod1.append(Add_Cyc_1[1,i]) 
    Probrani_1=vstack((rbrcol,brdod1)) 


pok=0 
for i in (rbrcol): 
pok+=1   
broj1=0 
for j in range(21): 
    if SYS_STATE_1[i,j]==0: 
     broj1+=1      
     if broj1 <= Probrani_1[1,pok-1]: 
      SYS_STATE_1[i,j]=123456 

그리고 난이 프로그램을 실행할 때이 얻을 :

내가 잘못된 일을
Traceback (most recent call last): 
    File "C:/Python26/pokusaj2.py", line 157, in <module> 
    for i in (rbrcol): 
NameError: name 'rbrcol' is not defined 

???

답변

2

오류와 마찬가지로 "rbrcol"에는 값이 없습니다. for 루프를 확인하십시오.

for i in range(27): 
    if Add_Cyc_1[1,i]!=0: <----- this part doesn't get through 
     rbrcol.append(Add_Cyc_1[0,i]) 
     brdod1.append(Add_Cyc_1[1,i]) 
    Probrani_1=vstack((rbrcol,brdod1)) 

도 Add_Cyc_1이 무엇입니까? 다차원 목록을

Add_Cyc_1[1,i] should be Add_Cyc_1[1][i] 

if ind_1<>0: <<--- if this is not true, then rbrcol will not be defined 
    rbrcol=[]  << --- <> should be != , although <> its also valid, but now ppl use != 
    brdod1=[] 
4

를 지정하려면 내가 진짜 문제가 생각하는 바로 그 상단 경우. 들여 쓰기가 올바르지 않습니다. if 뒤에 줄이 들여 쓰여져 있지 않기 때문에 작성된 코드는 실행되지 않습니다. IND_1 0이고 if 문이 결코 발사하지 않는 경우 ghostdog 말한대로, 다음 rbrcol이 전혀 설정되지 않을 경우

가 원래 코드에서 들여 쓰기 가정하면, 다음 rbrcol가 초기화되지 않습니다.

관련 문제