GetOption PERL to Python -
how write perl line in python?
getoptions('help|?' => \$help, 'man' => \$man, 'debug!' => \$debug, 'devpath:s' => \$devpath, 'dev2:s' => \$dev2,'rev1:s' => \$prj_rev1, 'rev2:s' => \$prj_rev2, 'prj:s' => \$prj)
thanks!
there module in python called argparse
. can use module solve 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
Comments
Post a Comment