multiple import of a load of variables

Fuzzyman fuzzyman at
Wed Mar 16 11:19:22 CET 2005

Torsten Bronger wrote:
> Hallöchen!
> I have a file that looks a little bit like a C header file with a
> long list of variables (actually constants) definitions, e.g.
> VI_ATTR_TIMO = 0x54378
> ...
> Actually I need this in a couple of low-level modules that are
> imported into the main module, and in the main module itself.  They
> may be also used in the programs that import the main module.
> Probably it doesn't mean a significant loss of performance anyway
> since all of it is done only at startup, but I wonder whether it's
> better to keep everything that depends on this "header" file
> together so that it must be looked over by Python only once.  Is
> this correct, or is there some sort of implicit optimisation that
> makes both variants almost equivalent?

I'm not entirely clear what you are trying to do *but* - if you import
the same module in several places (per interpreter instance of course)
the import will only be done *once*. The other import statments just
make that namespace available from the namespace that does the import.

This means there is little extra overhead for importing a module that
has already been imported elsewhere.




> Tschö,
> Torsten.
> -- 
> Torsten Bronger, aquisgrana, europa vetus

More information about the Python-list mailing list