Turn off globals in a function?

Ron_Adam radam2 at tampabay.rr.com
Sun Mar 27 04:49:00 CEST 2005


>If you put the above def b in e.g. a_module.py,
>and do a (untested ;-)
>
>    from a_module import b
>
>instead of defining it locally, then the global references
>from b (and whatever else you import from a_module)
>should be to the global dict defined for a_module (i.e., its
>outermost scope),  not to the globals where you do the import.
>
>>y = True
>>
>>>>>a(False):
>>True
>Should work if you define a in place having same scope as the y assignment
>>
>>>>>b(False):
>>*** name error here ***
>>
>UIAM it should do this if you import b as above.
>
>Regards,
>Bengt Richter

Good suggestion. Thanks. I was somewhat aware of the modular scope,
but was looking for way to apply it on a more local level. Michael's
suggestion looks interesting for that.

Ron_Adam






More information about the Python-list mailing list