You just met one of the many reasons why it is better to never import an object from the modules "inside" - only the modules themselves (possibly from packages). We made this rule part of our style rules on Google (published here ), and I wholeheartedly recommend it to every Python programmer.
To say what you need to do is take foomodule.foo, which you just replaced with the layout and paste it into the current module. I donβt remember enough doctrine to confirm
>>> import foomodule >>> foo = foomodule.foo
enough for this - try, and if that doesn't work, do instead
>>> import foomodule >>> import sys >>> sys.modules[__name__].foo = foomodule.foo
Yes, this is a mess, but the reason for this mess is that looking innocently from foomodule import foo is to avoid it and your life will be simpler and more productive; -).
Alex martelli
source share