Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Specify which function to run in a module from the command line
import sys
def some_name():
print("function 1")
def some_other_name():
print("function 2")
if __name__ == "__main__":
func = getattr(sys.modules[__name__], sys.argv[1])
# Then run with:
# python some_name
# python some_other_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment