Alex
Alex

Reputation: 23

why i get this traceback?

This is part of my code:

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  

And when i run program i get this:

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

What i do wrong???

Upvotes: 0

Views: 144

Answers (2)

Graeme Perrow
Graeme Perrow

Reputation: 57248

I think the real problem is the if at the very top. Your indenting is incorrect - the code as written won't run because the line after the if is not indented.

Assuming it is indented in the original code, then rbrcol is not initialized if ind_1 is 0 and as ghostdog says if the if statement never fires, then rbrcol would not be set at all.

Upvotes: 4

ghostdog74
ghostdog74

Reputation: 342363

just as the error says, "rbrcol" doesn't have value. check your for loop

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))

also, what is Add_Cyc_1 ? To assign multidimension list

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

further, this

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=[]

Upvotes: 2

Related Questions