dynamic import/reload of modules

Thomas Weholt thomas at gatsoft.no
Tue Aug 7 06:54:34 EDT 2001


Say I got a folder-structure like this :

/home/thomas/dev/modules/test1
/home/thomas/dev/modules/test2

they both contain two files:
__init__.py
handler.py

The handler.py contains a class handlerclass, that's different for each of
the handler files

How can I import the handler.py module for each folder, be able to reload it
and create object-instances from them?
I want to be able to say 'mymodules.reload()' and reload them too.

The point is to be able to easily create and import several modules into a
server without stopping the server itself. I want to be able to create a
folder in the /home/thomas/dev/modules-folder, put to files into it, call
reload on the server and have the modules available inside the running
server. I cannot know what the folder inside /home/thomas/dev/modules will
be called, but it will contain a handler.py defining a handlerclass-object
and a __init__.py ( if that's necessary ).

Any clues or pointers?

It's for use in medusa. I want to be able to dynamically define handlers
that processes requests, and reload them.

Thomas





More information about the Python-list mailing list