Created
April 25, 2018 10:46
-
-
Save jwg4/a7cedb446beed7c47a8d5dd0f94893f6 to your computer and use it in GitHub Desktop.
Python import weirdness
This file contains 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
(venv)jack@neptune-vm:~/z/imports$ python | |
Python 2.7.12 (default, Nov 20 2017, 18:23:56) | |
[GCC 5.4.0 20160609] on linux2 | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> from a import foo | |
>>> foo | |
<module 'a.foo' from 'a/foo.py'> | |
>>> foo.MY_THING | |
'THIS IS A STRING DEFINED IN THE MODULE' | |
>>> exit() | |
(venv)jack@neptune-vm:~/z/imports$ python | |
Python 2.7.12 (default, Nov 20 2017, 18:23:56) | |
[GCC 5.4.0 20160609] on linux2 | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> from b import foo | |
>>> foo | |
'THIS IS A STRING DEFINIED IN __init__.py' | |
>>> exit() | |
(venv)jack@neptune-vm:~/z/imports$ python | |
Python 2.7.12 (default, Nov 20 2017, 18:23:56) | |
[GCC 5.4.0 20160609] on linux2 | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> from c import foo | |
>>> foo | |
'THIS IS A STRING DEFINIED IN __init__.py' | |
>>> c.foo | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
NameError: name 'c' is not defined | |
>>> import c | |
>>> c.foo | |
'THIS IS A STRING DEFINIED IN __init__.py' | |
>>> from c.foo import MY_THING | |
>>> MY_THING | |
'THIS IS A STRING DEFINED IN THE MODULE' | |
>>> import c.foo | |
>>> c.foo | |
<module 'c.foo' from 'c/foo.py'> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment