forcing future re-import from with an imported module
wolfgang.lipp at gmail.com
Wed Dec 10 23:53:12 CET 2008
On Dec 10, 1:46 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> En Tue, 09 Dec 2008 23:27:10 -0200, _wolf <wolfgang.l... at gmail.com>
> > how can i say, approximately, "re-import the present module when it is
> > imported the next time, don’t use the cache" in a simple way? i do not
> > want to "reload" the module, that doesn’t help.
> I'd say you're using modules the wrong way then. The code inside a module
> is executed *once*, and that's by design. If you want to execute something
> more than once, put that code inside a function, and call it as many times
> as you want.
> Gabriel Genellina
thanks for your answer. i am aware that imports are not designed to
have side-effects, but this is exactly what i want: to trigger an
action with `import foo`. you get foo, and doing this can have a side-
effect for the module, in roughly the way that a `from __future__
import with_statement` changes the interpretation of the current
module (of course, i do not intend to effect syntactic changes---my
idea is to look into the module namespace and modify it). think of it
as ‘metamodule programming’ (à la metaclass programming).
maybe import hooks are the way to go? somtimes it would be good if
there was a signalling system that broadcasts all kinds of system
cheers & ~flow
ok so the question is: how to make it so each import of a given module
has a side-effect, even repeated imports?
More information about the Python-list