global variable

Joe Francia usenet at
Mon Jul 21 19:13:00 CEST 2003

Tom wrote:
> Hi,
> I have one "master" program which calls a small program. In this small 
> program I want to work with a value from the "master" program. But I 
> always get this error: NameError: global name 'T' is not defined
> How can I define a global variable?
> Thanks for your help.
> Regards, Tom

You can't (well, there is a way, but you probably don't want to be 
messing with that).

By "program" I assume you mean "module".  You can do something like:
T = 'Some value'
import master

However, if is also importing, you'll get a circular 
reference, which may cause hard to track bugs, in which case it's best 
to have a third module for common (global) variables (and functions, if 
you'd like), and have both and import that.


More information about the Python-list mailing list