Non-caching import?

Michael Hudson mwh at python.net
Mon May 7 12:47:58 EDT 2001


Kevin.Smith at sas.com (Kevin Smith) writes:

> Is it possible to implement an import mechanism that will not use
> the caching mechanism?

Don't think so.  Could be wrong though - I haven't checked.

[snip]
> After the second import, there are no changes to foo.  Class Bar is
> still the class definition from site-packages/foo.py.  I can get Bar
> from the second import to act the way I would like by doing a "del
> sys.modules['foo']" after the first import, but this has no effect
> on the "from more import *" in foo.py.

Well, you'd need to "del sys.modules['more']" to do that...

[snop]
> P.S. Keep in mind that this is a very simple example case and that I am not 
> trying to use the above code verbatim, so please refrain from simply 
> correcting poor programming practices in this example.

Noted, but this is is a REALLY REALLY bad idea, in many ways (eg. any
instances instantiated from the old version of more.Blah will no
longer pass isinstance(obj, more.Blah), etc).  My heartfelt
recommendation is to find some other way to do what you want to do.

Cheers,
M.

-- 
  MGM will not get your whites whiter or your colors brighter.
  It will, however, sit there and look spiffy while sucking down
  a major honking wad of RAM.              -- http://www.xiph.org/mgm/



More information about the Python-list mailing list