scope of variables
Gary Wessle
phddas at yahoo.com
Wed May 3 18:25:01 EDT 2006
"Steve R. Hastings" <steve at hastings.org> writes:
> On Thu, 04 May 2006 07:02:43 +1000, Gary Wessle wrote:
> > b = 3
> > def adding(a)
> > print a + b
> >
> > it seams not to see the up-level scope where b is defined.
>
> Assuming you put a ':' after the "def adding(a)", this should work in
> recent versions of Python. In Python 2.0 and older, this will not work.
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"
More information about the Python-list
mailing list