Skip to content

Instantly share code, notes, and snippets.

@davedash
Created April 17, 2012 21:08
Show Gist options
  • Save davedash/2409061 to your computer and use it in GitHub Desktop.
Save davedash/2409061 to your computer and use it in GitHub Desktop.
wtfpython.py
from testing import mocks
mocks.email # works
# mocks.user doesn't work even though there's a testing/mocks/user.py files
import testing.mocks.user # works fine
mocks.user # now works: wtf???
@davedash
Copy link
Author

@oremj, @kumar303,

Okay interesting - so it seems like it's a side effect of having had imported it elsewhere in the code.

@kumar303
Copy link

sys.modules is just a dict with keys like sys.modules['testing.mocks.email'] -- it's available to all modules everywhere in python. This is useful for many things like shared memory but is not useful for things like isolated dependency trees (the way npm install does that in node.js). As far as I can tell, you cannot implement isolated dependencies a la node in Python. setuptools tried to do this with crazy hacks but ultimately failed. It was too much magic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment