
May 7, 2007
12:13 a.m.
what about: if __module__ is __main__: ... __module__ is a reference to "this module" and __main__ is a reference to the module which stated execution this would have the sideeffect that: def f(): __module__.x = 42 equals: def f(): global x x = 42 etc. Off Topic: a __func__ would also be nice: def foo(): print __func__.__name__ prints "foo" def foo(): x = 1 def bar(): __func__.parent.x += 1 return __func__.parent.x return bar print bar() prints "2" well, on second thought this is looks a bit cluttered.