Skip to content

Instantly share code, notes, and snippets.

@jtatum
Created October 31, 2013 00:50
Show Gist options
  • Save jtatum/7242826 to your computer and use it in GitHub Desktop.
Save jtatum/7242826 to your computer and use it in GitHub Desktop.
# Why not to just put all your code under if __name__ == '__main__':
# (AKA why you should use a main(argv) function)
import sys
def my_func(param):
print param
# You'd think this would fail, but it works, because new_param is in the
# parent level scope. It will fail if you import this file and call
# my_func, of course.
print new_param
if __name__ == '__main__':
# I am adding a new param, so let's unpack it into a new variable
(param, new_param) = sys.argv[1:2]
# Here, I should call my func with this exciting new parameter,
# but I forgot
my_func(param)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment