Newbie: How to touch "global" variables
John Hunter
jdhunter at ace.bsd.uchicago.edu
Mon Jul 29 12:38:13 EDT 2002
>>>>> "Jeff" == Jeff Layton <jeffrey.b.layton at lmco.com> writes:
Jeff> Hello, I've got a defeinite newbie question (I searched
Jeff> some, but to be honest I don't know what keywords to search
Jeff> on - which has brought me here :). I want a module to be
Jeff> able to "touch" a variable defined globally (from the main
Jeff> script). I don't necessarily want to change the value ofthe
Jeff> variable, but to query it. For example, get the length. How
Jeff> do I do this?
The received wisdom is that you rarely if every want/need to use a
global variable. Singletons/Borgs can do anything you'll want your
global variable to do, and will be cleaner, easier to maintain and
will win you friends, women and respect.
Search google for 'singleton design pattern'
And take a look at Alex Martelli's "Singleton? We don't need no
stinkin' singleton: the Borg design pattern"
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531
John Hunter
More information about the Python-list
mailing list