It's a bug!....but is it me or the script? (Global var assign)

Peter Hansen peter at engcorp.com
Wed Nov 19 17:19:28 CET 2003


Halfdan Holger Knudsen wrote:
> 
> Why doesn't the variable enc behave globally (the admin function turns 
> up a "local var referenced before assignment" error, when inputting 's')? 

To use a variable globally, *if you're going to rebind it* (as in, assign to it)
you need to put a "global" statement at the top of each function which uses it.

If all you ever do is read the value, you don't need this, but you are trying
to rebind the name "enc" in some of those functions, so you must have a 
"global enc" statement before you do that.

-Peter




More information about the Python-list mailing list