How to Lock Globar Variables across Modules?

Alex the_brain at mit.edu
Thu Sep 28 15:58:37 CEST 2000


> I wish python had a reference feature to make it more efficient:
> 
>     sv& = main_module.sv
> 
> Whatever 'main_module.sv' points to, 'sv' will also point to.  If
> possible in the implementation, hopefully a reference like this will
> not involve a dictionary look-up at all.

Sorry, python just doesn't work this way at the moment.  I think you
would have to change variable name lookups to check for such
'privileged' names.  That may or may not involve a lot of work.

One thing that I do to avoid having to import commonly used objects in
every module that uses them is modify the python __builtins__ module.
In main_module, you could do something like

import main_module
__builtins__.m = main_module

...and from then on, you could refer to sv as m.sv throughout your
program.  It still seems like a bad idea to me on the face of it,
though. 

Alex.

-- 
Speak softly but carry a big carrot.




More information about the Python-list mailing list