def parseCommand():
args = None
if len (sys.argv) < 2:
print('no command entered')
return
command = sys.argv[1]
print ('command executed: %s' %command)
if len(sys.argv) == 3:
args = sys.argv[2]
if len(sys.argv) > 3:
args = sys.argv[2:]
commandList = {
'fA' : fA(),
'fB' : fB(),
}
if args == None:
return commandList[command]
else:
return commandList[command](args)
if __name__ == "__main__":
parseCommand()
I am running this script from linux. However when I run python scriptname.py fA or python scriptname.py fB, the script seems to run just from top to bottom, executing both functions When I change it to
if __name__ == "__main__":
fA()
or
if __name__ == "__main__":
fB()
and run python scriptname.py frtom linux it only executes the function I am calling.
Could anyone tell me what s wrong with my approach? Thanks