I have a python script which contains many functions.
Currently, I’m using the if statement to call the right function whereas the function name is passed as argument.
import sys
def myfunction(mystring):
print(mystring)
def myfunction2():
print('This Function 2')
if __name__ == '__main__':
if (sys.argv[1] == 'myfunction'):
myfunction('test myfunction')
elif(sys.argv[1] == 'myfunction2'):
myfunction2()
elif ....
So, in cmd I just call
python.exe pyscript.py myfunction(‘test’)
The cmd command is fine, but is there a straighter way in python so that I can avoid the if statement and the rewriting of the function names in the script itself?
Thank you 🙂