Newbie question - calling external Python programs
jepler epler
jepler.lnk at lnk.ispi.net
Sun Aug 20 09:38:46 EDT 2000
On Sat, 19 Aug 2000 22:21:16 GMT, Stephen Ferg
<stephen_ferg at worldnet.att.net> wrote:
>My name is Steve Ferg. I am a newbie convert to Python from Rexx. I want
>to port a big Rexx application to Python, and I need some guidance on Python
>design philosophy for moderately large applications.
While the code is probably not the easiest to understand, I seem to recall
that PMW (Python Megawidgets for Tk) provides a way to defer mdoule loading
until it is needed. You might want to take a look at this code and evalute
whether you can re-use it to get the results you want.
Also, you could try code like the following:
class LazyImporter:
def __getattr__(self, item):
self.__dict__[item] = __import__(item)
return self.__dict__[item]
>>> l = LazyImporter
>>> dir(l)
[]
>>> l.sys.stdin
<open file '<stdin>', mode 'r' at 80a0f50>
>>> dir(l)
['sys']
A provision to unload a module is more difficult. Even if you delete a key
from l's dict, the module remains in sys.modules. It seems to me that if you
>>> del l.somemodule
>>> del sys.modules['somemodule']
>>> l.somemodule
but somebody has stored a reference to somemodule, you will end up with two
copies of it, which is not desirable.
Jeff
More information about the Python-list
mailing list