Load a module twice ... or not ???

pnpayne at swissonline.ch pnpayne at swissonline.ch
Tue Mar 21 13:57:18 EST 2000


Hi,

Can anyone by any chance give me a definitive explanation to the
following (Python 1.5.2).

In the book 'Internet Programming with Python', by Watters, van Rossum
and Ahlstrom, in the section 'How to Load a Module Twice, and Why You
Shouldn't', on page 199/200 (my edition, anyway), it states that you
shouldn't  have module interrelationships that result in a module
running as a main program and also being imported by another module in
the same interpreter. More specifically, it states: 'In more complex
cases, this can cause grief, because any class C defined in A.py will be
created twice, once as __main__.C and another time as A.C. Without going
into great detail let it suffice to say that it is best to avoid this
possibility by using a "stub module" to launch any application that has
complex interrelationships amoung modules'.

Now I have a reasonably complex Web application with just this
structure, since I've modified PyApache to have a persistent interpreter
to avoid the massive overhead of importing modules. Modules run as main
programs and they also get imported by other modules running as main
programs. All the modules have classes defined in them (I'm using more
or less WvRA's cgiBase class structure). It works perfectly - never a
problem.

Since I don't, in practice, encounter any problems doing what WvRA say I
shouldn't do, is this in fact an issue? Is the above quote relevant to
current Python versions?? And if so, can someone tell me in detail under
what circumstances there might be a problem?

Regards,
Philip Payne






More information about the Python-list mailing list