Reputation: 151
I normally use argparse for parsing arguments,but it looks like its introduced since 2.7,am currently on 2.6.5,I cant upgrade to newer due to company policy,i need someinputs on how else can I parse the options given below,is there an easier and quick way to convert to below to parse options for 2.6.5?please suggest
import os
import sys, getopt
import argparse
def main ():
parser = argparse.ArgumentParser(description='Test script')
parser.add_argument('-sau','--set',action='store',dest='set',help='<Required> Set flag',required=True)
parser.add_argument('-bg','--base_g',action='store',dest='base_g',help='<Required> Base g',required=True)
results = parser.parse_args()# collect cmd line args
set = results.set
base_g = results.base_g
if __name__ == '__main__':
main()
Upvotes: 0
Views: 357
Reputation: 11707
I also love argparse
and built-in modules in general. However, when it comes to CL-args parsing, I've come to like docopt. Since you just include it alongside your source files, you no longer need to worry about deprecated modules. The current source code at GitHub is in Python3 though but tweaking it for Python 2.x shouldn't be too much work.
Upvotes: 1