"Alex Martelli" <aleaxit at yahoo.com> wrote in message news:20031022161137.96353.qmail at web40513.mail.yahoo.com... > Inside a module M's body ("toplevel" in it, not nested inside > a def &c) I can write > x = 23 > and it means M.x = 23 (unconditionally). Once the module > object M is created, if I want to tweak that attribute > of M I have to write e.g. M.x = 42 after getting ahold of > some reference to M (say by an "import M", or say in a function > of M by sys.modules[__name__].x = 42, etc). > Inside a module M's body ("toplevel" in it, not nested inside > a def &c) I can write > x = 23 > and it means M.x = 23 (unconditionally). Once the module > object M is created, if I want to tweak that attribute > of M I have to write e.g. M.x = 42 after getting ahold of > some reference to M (say by an "import M", or say in a function > of M by sys.modules[__name__].x = 42, etc). I somehow overlooked that this would work inside modules also. >>> import __main__ as m # I know, not general, just for trial >>> m.c=3 >>> c 3 >>> def e(): ... m.x='ha' ... >>> e() >>> x 'ha' So I really *don't* need global. Perhaps a new builtin def me(): import sys return sys.modules[__name__] or an addition to my template.py file. Terry J. Reedy
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4