python - How to store argparse values in variables? -


i trying add command line options script, using following code:

import argparse  parser = argparse.argumentparser('my program') parser.add_argument('-x', '--one') parser.add_argument('-y', '--two') parser.add_argument('-z', '--three')  args = vars(parser.parse_args())  foo = args['one'] bar = args['two'] cheese = args['three'] 

is correct way this?

also, how run idle shell? use command 'python myprogram.py -x foo -y bar -z cheese' , gives me syntax error

that work, can simplify bit this:

args = parser.parse_args()  foo = args.one bar = args.two cheese = args.three 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -