scopes of local and global variable
Max Wilson
wilson.max at gmail.com
Fri Dec 22 20:18:41 EST 2006
Pyenos wrote:
> does class WORK inherit t_len=0 from line1?
>
> does def getwork() inherit t_len=0 from line1?
>
> does def formattable(table_to_process,type) inherit t_len=0 from line1?
>
> does def format_t() inherit t_len=0 from line1?
Not really, no. The global t_len is different than the local t_len--two
variables with the same name. You need to declare "global t_len" inside
your function so it knows that "t_len=..." is assigning to the old,
global variable instead of creating a new one.
See #6 here: http://zephyrfalcon.org/labs/python_pitfalls.html
-Max
More information about the Python-list
mailing list