scope of variables
Gary Wessle
phddas at yahoo.com
Thu May 4 05:50:17 EDT 2006
Ryan Forsythe <ryan at cs.uoregon.edu> writes:
> Gary Wessle wrote:
> > the example was an in-accuretlly representation of a the problem I am
> > having. my apologies.
> >
> > a = []
> > def prnt():
> > print len(a)
> >
> >>>> prnt
> > <function prnt at 0xb7dc21b4>
> >
> > I expect to get 0 "the length of list a"
>
> You want prnt(), not prnt:
>
I finally was able to duplicate the error with a through away code
as follows,
****************************************************************
acc = [1,2,3]
def a():
b = [4, 5, 6]
acc = acc + b
print len(acc)
a()
**************** error ****************
Traceback (most recent call last):
File "a.py", line 12, in ?
a()
File "a.py", line 9, in a
acc = acc + b
UnboundLocalError: local variable 'acc' referenced before assignment
More information about the Python-list
mailing list