Monday, February 8, 2016

Globals in python

If your code is so bad that you're using globals, here's what you need to know:

Modules can read the global all they want, but the moment you set a value to it without first declaring in the module that it is a global, you're creating a local variable and not setting the global. Use the statement "global varname" in the code somewhere before the set. Modules which do not set it don't need this declaration. A reference: