I want to dynamically reload a module...

Martin von Loewis loewis at informatik.hu-berlin.de
Sat Mar 24 06:33:46 EST 2001


Benoit Dupire <bdupire at seatech.fau.edu> writes:

> My goal is to dynamically import  a module called 'func' and to get the
> references to the objects that 'func' created.
> It works like this:
> prog1.py  dynamically imports func.py.

[by doing]

> class foo:
>     def __init__(self, module):
>         self.aa=__import__(module)          # dynamically import func

That won't reload module if it is already loaded. If you want to be
sure that you have the latest reference to module all the time, you
should add

          self.aa = reload(self.aa)

Regards,
Martin



More information about the Python-list mailing list