Parametrized module import

Heather Coppersmith me at privacy.net
Thu Jul 8 12:12:37 EDT 2004


On 08 Jul 2004 14:22:25 +0200,
Jacek Generowicz <jacek.generowicz at cern.ch> wrote:

> 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.

Oops--yes, you are correct.  I apologize.  My quickie tests were
apparently less than sufficient.  [slaps self on wrist, and then
on forehead]

Regards,
Heather

-- 
Heather Coppersmith
That's not right; that's not even wrong. -- Wolfgang Pauli



More information about the Python-list mailing list