Created
October 3, 2017 17:17
-
-
Save Audhil/a2358cf393956f0a24e9a8ac9932e6a9 to your computer and use it in GitHub Desktop.
what is __name__ in python?
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
print ('top level in one.py') | |
def matter(): | |
print ('this is matter() in one.py') | |
if __name__ == '__main__': | |
print("one.py is being run directly and __name__ is : ", __name__) | |
matter() | |
else: | |
print("one.py is being imported in another module and __name__ is : ", __name__) |
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
$ python two.py | |
top level in one.py | |
('one.py is being imported in another module and __name__ is : ', 'one') | |
this is matter() in one.py | |
this is top level in two.py | |
('two.py is being run directly and __name__ is : ', '__main__') |
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 one | |
one.matter() | |
print ('this is top level in two.py') | |
if __name__ == '__main__': | |
print("two.py is being run directly and __name__ is : ", __name__) | |
else: | |
print("two.py is being imported in another module and __name__ is : ", __name__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment