Module loading trickery

Jean-Michel Pichavant jeanmichel at
Tue Oct 5 17:49:09 CEST 2010

Jonas Galvez wrote:
> Is there a way to "inject" something into a module right before it's 
> loaded?
> For instance, defines "foo". print()s "foo". 
> I want to load into, but I need to let know about "foo" 
> before it can execute.
> Is this any way to achieve this?
> -- Jonas
No that would mean that a imports b which imports a => circular imports.

Usually it's a cue for bad design.
People solve it by either merging the 2 modules into 1 or defining 'foo' 
in a 3rd module.

You can do also something like :

import b
foo = 'I am foo'

def printThat(something):
    print something


More information about the Python-list mailing list