Created
April 17, 2012 21:08
-
-
Save davedash/2409061 to your computer and use it in GitHub Desktop.
wtfpython.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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??? | |
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
I have the following tree:
├── test.py
└── testing
├──
__init__.py
└── mocks
├──
__init__.py
├── email.py
└── user.py
I'm only able to import mocks.email and mocks.users if I ask python to import them by name.