Skip to content

Instantly share code, notes, and snippets.

@erikkaplun
Created January 26, 2011 19:47
Show Gist options
  • Save erikkaplun/797294 to your computer and use it in GitHub Desktop.
Save erikkaplun/797294 to your computer and use it in GitHub Desktop.
Maagiline muutuja __name__
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...')
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...
@erikkaplun
Copy link
Author

foo.py ja main.py tuleb panna samasse kausta ning seejärel käivitada skript main.py.

Seejärel käivitada skript foo.py ning vaadata, mis siis erinevat juhtub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment