Last active
May 26, 2019 17:34
-
-
Save diogobaltazar/ca946163a09ee8aafff379e4f530ae89 to your computer and use it in GitHub Desktop.
modules
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
if __name__ == '__main__': | |
print('mod1 is executing by having been called directly') | |
else: | |
print('mod1 is executing by having been imported by module ' + __name__) | |
def f(): | |
if __name__ == '__main__': | |
print('mod1.f is executing from module mod1') | |
else: | |
print('mod1.f is executing from module' + __name__) | |
f() | |
# > python mod1.py | |
# mod1 is executing by having been called directly | |
# mod1.f is executing from mod1 |
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
from mod1 import f | |
f() | |
# > python mod2.py | |
# mod1 is executing by having been imported by module mod1 | |
# mod1.f is executing from module mod1 | |
# mod1.f is executing from module mod1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment