11 May 19:16
scope in nested function calls
From: Joseph Mack NA3T <jmack@...>
Subject: scope in nested function calls
Newsgroups: gmane.org.user-groups.zope.trizpug
Date: 2008-05-11 17:20:30 GMT
Subject: scope in nested function calls
Newsgroups: gmane.org.user-groups.zope.trizpug
Date: 2008-05-11 17:20:30 GMT
I've just moved a piece of code out of a long function into another (lower
nested) function and I'd like the lower nested function to still access (write
to) variables in the calling function. I'm doing this for readability and so
that I can test a couple of different versions of the lower nested function by
commenting out calls in the calling function.
Here's an example piece of code
-------------------------------
#! /usr/bin/python
def foo():
print "foo: bar_value %d" %bar_value
def bar():
bar_value=1
print "bar: bar_value %d" %bar_value
foo()
#main()
bar()
---------
the output is
# ./test_scope.py
bar: bar_value 1
Traceback (most recent call last):
File "./test_scope.py", line 12, in ?
(Continue reading)
RSS Feed