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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -