The global statement

Nick Vargish nav+posts at
Fri Jul 25 21:29:19 CEST 2003

"David Hitillambeau" <edavid at> writes:

> I want to enable some sharing between the two functions (foo and bar)
> using one global variable in such a way that each function can have read
> and write access over it.

Using the "global" statement seems unpythonic to me, for reasons I'm
too lazy to come up with good ways to express. :^) This is what I do,
if I need something like this: 

class Global:
    """Generic container for shared variables."""

def foo():
    Global.somevar = 'set in foo'

def bar():
    print Global.somevar




#  sigmask  ||  0.2  ||  20030107  ||  public domain  ||  feed this to a python
print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?')

More information about the Python-list mailing list