Re: advanced module/import/namespace idioms
- From: Scott David Daniels <scott.daniels@xxxxxxx>
- Date: Sat, 31 Dec 2005 11:25:17 -0800
chuck wrote:
Every once in awhile I run across a python module that might have statements like:
for c in sys.modules[module].__dict__.values():
Straight-forwardly imported modules wind up in sys.modules, keyed by their module name. So "t = sys.modules['name']" is like "import name as t".
Work it out in an interactive session, and you can get to know what is going on here. If you discover something wonderful you wish were written up, write it up.
import __builtin__ __builtin__.__dict__['_'] = lambda x: x
The __builtin__ module is magical -- the source of predefined names. _Do_not_muck_about_with_it_in_delivered_code_ (I know it is tempting). The reason to avoid playing with it is that you are slightly breaking the Python environment all code runs in.
--Scott David Daniels scott.daniels@xxxxxxx .
- References:
- advanced module/import/namespace idioms
- From: chuck
- advanced module/import/namespace idioms
- Prev by Date: Re: Vector math library
- Next by Date: Application architecture (long post - sorry)
- Previous by thread: advanced module/import/namespace idioms
- Next by thread: Problem compiling an extension with MS Visual C++ Toolkit 2003
- Index(es):