There is a module in python called argparse
. You can use the module to solve your problem.
Code example : test.py
import argparse
import os
commandLineArgumentParser = argparse.ArgumentParser()
commandLineArgumentParser.add_argument("-fname", "--fname", help="first name")
commandLineArgumentParser.add_argument("-lname","--lname", help="last name")
commandLineArguments = commandLineArgumentParser.parse_args()
fname = commandLineArguments.fname
lname = commandLineArguments.lname
print "%s\n%s" %(fname,lname)
Run example
python test.py -fname ms -lname = dhoni
Output
ms
dhoni
solved GetOption PERL to Python