Skip to content

Instantly share code, notes, and snippets.

Embed
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])
func()
# Then run with:
# python cmd-line-function.py some_name
# python cmd-line-function.py some_other_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.