Created
October 31, 2013 00:50
-
-
Save jtatum/7242826 to your computer and use it in GitHub Desktop.
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
# 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