forcing future re-import from with an imported module

_wolf wolfgang.lipp at gmail.com
Fri Dec 12 16:44:32 EST 2008


On Dec 11, 12:43 am, rdmur... at bitdance.com wrote:
> "Why can't you have the code that is doing the import [...]
> call a function [...] to produce [the] side effect [...]?
> Explicit is better than implicit.  A python programmer is
> going to expect that importing a module is idempotent"

you’re completely right that `import foo` with side effects may break
some expectations, but so do all `from __future__` imports. you’re
also right that another solution would be to come in from the other
side and explicitly call a function from the importing module. all of
this does not answer one question tho: why does deleting a module work
most of the time, but not in the case outlined in my first post,
above? why do we get to see this slightly strange error message there
complaining about ‘not finding’ a module ‘in sys.modules’—well, most
of the time, when a module is not in that cache, it will be imported,
but not in this case. why?

cheers & ~flow



More information about the Python-list mailing list