global name is not defined - error
Marco Wahl
marco.wahl at gmail.com
Wed Jun 28 01:37:01 EDT 2006
"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