Created
January 26, 2011 19:47
-
-
Save erikkaplun/797294 to your computer and use it in GitHub Desktop.
Maagiline muutuja __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
print('Inside file foo.py; and __name__ is %s' % __name__) | |
# ekraanile ilmub tekst: | |
# Inside file foo.py; and __name__ is foo | |
# kui foo.py käivitatakse otse, ilmub foo asemel: | |
# Inside file foo.py; and __name__ is __main__ | |
def do_something_cool(): | |
print('Doing something cool...') |
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 foo | |
# ekraanile ilmub tekst: foo | |
# sest foo.py's on kohe alguses vastav rida, mis käivitub | |
# kui me foo impordime. | |
print('Inside file main.py; and __name__ is %s' % __name__) | |
# ekraanile ilmub tekst: __main__ | |
foo.do_something_cool() | |
foo.do_something_cool() | |
# ekraanile ilmub 2x tekst: Doing something cool... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
foo.py
jamain.py
tuleb panna samasse kausta ning seejärel käivitada skriptmain.py
.Seejärel käivitada skript
foo.py
ning vaadata, mis siis erinevat juhtub.