global name is not defined - error

a a at tempinbox.com
Wed Jun 28 07:25:53 EDT 2006


i changed it to append and it started working but once in a while
i m getting
l_code.append( len(d_list_code[i]['entries']) )
IndexError: list index out of range

but it is not permanent if i refresh, it goes away!
Marco Wahl wrote:
> "a" <a at tempinbox.com> writes:
>
> > What I want
> > ---------------
> > I want to create a list of items from a function operating on an array
> > of strings
>
> Ok.
>
> > What I did
> > -----------------
> > list=["s0","s1","s2"]
> > l=len(list)
> >       for i in range(l):
> >                               d_list[i]=f.do(list[i])
> >                               print d_list[i]
>
> Aha!
>
> > Error:
> > ------
> > global name 'd_list' is not defined
> > Python        c:\test.py in newClass, line 30
>
> Just as the error message tells: 'd_list' is not
> defined which is an error.
>
> Try
>
> list=["s0","s1","s2"]
> d_list = []
> l=len(list)
>         for i in range(l):
> #                               d_list[i]=f.do(list[i])
>                                 d_list.append(f.do(list[i]))
>                                 print d_list[i]
>
> This is just one suggestion there may be more elegant
> ways.  Have you heard about list comprehension?
> 
> 
> HTH




More information about the Python-list mailing list