-
-
Save kms70847/496802a4954f2f1f2cbdf29062079d07 to your computer and use it in GitHub Desktop.
Quirk of the import system
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
W = 1 | |
print("a.py says: about to import b") | |
import b | |
print(f"a.py says: b imported with values {[name for name in dir(b) if '__' not in name]}") | |
X = 2 |
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
Y = 3 | |
print("b.py says: about to import a") | |
import a | |
print(f"b.py says: a imported with values {[name for name in dir(a) if '__' not in name]}") | |
Z = 4 |
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
import a |
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
C:\Users\Kevin\Desktop>a.py | |
a.py says: about to import b | |
b.py says: about to import a | |
a.py says: about to import b | |
a.py says: b imported with values ['Y'] | |
b.py says: a imported with values ['W', 'X', 'b'] | |
a.py says: b imported with values ['Y', 'Z', 'a'] | |
C:\Users\Kevin\Desktop>c.py | |
a.py says: about to import b | |
b.py says: about to import a | |
b.py says: a imported with values ['W'] | |
a.py says: b imported with values ['Y', 'Z', 'a'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment