the global keyword:
Rick Johnson
rantingrickjohnson at gmail.com
Tue Jun 21 19:50:53 EDT 2016
On Tuesday, June 21, 2016 at 5:20:53 PM UTC-5, Rick Johnson wrote:
> py> import sys
> py> def foo():
> ... print 'My name is Foo!'
> py> sys.modules['__builtin__'].__dict__['foo_func'] = foo
> py> foo()
> My name is Foo!
> py> foo = 'bar'
> py> foo
> 'bar'
> py> sys.modules['__builtin__'].__dict__['foo_func']
> <function foo at 0x02810330>
Oops. Made a innocent boo-boo here. Let me try again.
py> import sys
py> def foo():
... print "Hey, my name is foo!"
py> sys.modules['__builtin__'].__dict__['foo_func'] = foo
py> foo_func()
Hey, my name is foo!
py> foo_func = 'bar'
py> foo_func
'bar'
py> sys.modules['__builtin__'].__dict__['foo_func']
<function foo at 0x026C0330>
More information about the Python-list
mailing list