importing dynamic files, unimporting

Mike Fletcher mfletch at tpresence.com
Tue Oct 17 23:13:19 EDT 2000


First part:

module = __import__( "modulename", {}, {}, [] )
last arg is a list of "from" string...

e.g.
>>> __import__( 'mcf.vrml.loader', {}, {}, ["mcf", "vrml"] )
<module 'mcf.vrml.loader' from '/mcf\vrml\loader.pyc'>

Second part, I don't think so. As far as I know, the module type doesn't get
garbage collected, but someone who's actually checked would probably have a
more authoritative answer.  You do know about the reload command, right?

Enjoy,
Mike


-----Original Message-----
From: Alex McHale [mailto:daimun at home.com]
Sent: Tuesday, October 17, 2000 10:54 PM
To: python-list at python.org
Subject: importing dynamic files, unimporting


Hi there,
  I was just wondering if there is a way to import a module where the module
name is dynamic (basically contained in a string).  The idea is that the
module will contain specific functions (ie def foobar( arg1, arg2 ) in all
such modules).
  The second part is removing these imports.  Is there a way to 'unimport' a
module?  The python website seems to be very lacking on such topics.

  Daimun
  daimun at home.com


-- 
http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list