Parametrized module import

Jacek Generowicz jacek.generowicz at cern.ch
Thu Jul 8 14:22:25 CEST 2004


Heather Coppersmith <me at privacy.net> writes:

> Upon import, a module's "top level" code is executed,

Yes, but only on the _first_ import. On subsequent imports the system
notices that the module has already imported, and doesn't execute
anything in the module, it just binds a name to the already imported
module ...

> so try a variation on this theme at the top level of your module:
> 
>     i_am_configured = False
> 
>     if i_am_configured:
>         print 'i am already configured'
>     else:
>         import my_configuration_module
>         configure_myself( )
>         i_am_configured = True

... so the first branch will _never_ get executed.

My question is exactly about this problem: nothing gets executed on
the second import, so there's nowhere for me to put the "already
configured" message.




More information about the Python-list mailing list