Question: I need help with python and argparse. How do I set it up so that it separates the input on spaces. I'm working on a

I need help with python and argparse. How do I set it up so that it separates the input on spaces. I'm working on a rpn calculator, and I just have it set up like this:

parser = argparse.ArgumentParser(description = "Enter a valid postfix expression.") parser.add_argument("userIn") args = parser.parse_args()

and I have a function that takes the userIn and does the calculation. But using argparse, when I enter in something like "12 3 +" it reads it as "1 2 3 +" so the 2 and 3 get added not 12 and 3. Entering "37+" is even a valid input since it splits each element up. Without using argparse, doing a simple .split() on the input works and separates the input on spaces, but we are required to use argparse and now I have this problem.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!