Hello People,
I am trying to use argparse to get raw input data which is similar to raw_input() function
My program:
Code:
#!/usr/bin/env python
#test.py
import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--my-foo', help='foobar')
args = parser.parse_args()
print(args.my-foo)
when I execute
test.py -f testing 123, it give me unwanted result which is
error: unrecognized arguments: 123
then, I change my code to:
Code:
#!/usr/bin/env python
#test.py
import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--my-foo', nargs='*', action='store', help='foobar')
args = parser.parse_args()
print(args.my-foo)
when I execute it this time, again, it give unwanted result which is
['testing', '123']
what I wanted was when I execute
test.py -f testing 123, it will produce an output of
testing 123 as string... which is similar to the raw_input() function, such as the program mention at below:
Code:
#!/usr/bin/env python
#raw_input.py
import sys
args = raw_input()
print(args)
Thanks