How to Lock Globar Variables across Modules?

William Djaja Tjokroaminata billtj at y.glue.umd.edu
Thu Sep 28 09:46:49 EDT 2000


Alex <cut_me_out at hotmail.com> wrote:

:> In the main module, all the code will look like
:> 
:>     schedule (sv.current_time)
:> 
:> But the same code in other modules will have to look like
:> 
:>     schedule (main_module.sv.current_time)
:> 
:> I want something that is consistent across all the simulation modules.

: Well, perhaps you could import the main_module into itself, so that you
: can refer to main_module.sv in there as well.  At least it'd be
: consistent. 

: Alex.

: -- 
: Speak softly but carry a big carrot.

---------------------------------------------------------------------------

I think there are two disadvantages of importing the main_module into
itself to make the code consistent:

    1) It is longer to type
    2) It is probably less efficient

In 1), typing 'main_module.sv' is more tedious than just typing 'sv'.  I
wish python had some macro just like in C/C++ with its pre-processor:

    #define sv main_module.sv

The macro will solve the typing problem, but does not increase
efficiency.  I have read that every dot operator results in a dictionary
look-up.  Therefore 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.

So for now I guess I have to live in the world that python has
defined.  Any possible way to express my wish list, to Guido maybe?

Thanks for all the reply.


Regards,

Bill



More information about the Python-list mailing list