0

Maybe this isn't the best way to frame my problem. Right now, I have a program that already uses argparse to enter my class in 'manual' mode. So for example, if I type python parser.py --m, I go to Parse(args), which is my class. This all works fine.

Once this is done, the class parses the file for its table of contents list and prints it to the screen. The table of contents is an OrderedDict with the page number as the key and the page title as the value. The idea is that you could press a number and it would print out the text on that respective page, and that you could do this until you type any command that doesn't correspond to a number in the dict.

I was wondering if this would be possible to do with argparse or sys?

1
  • 1
    If you want something "interactive", you might consider using raw_input and a while loop Commented Jul 13, 2017 at 2:47

1 Answer 1

1

args = parser.parse_args() parses sys.argv[1:], the list like structure that the command line produced and gave to the Python interpreter. You can also call parse_args with any similar list of strings.

How to split a string like the shell in python?

ipython uses a modified argparse to handle its main input. It uses the config files to populate the parser, giving the user a last minute way of fiddling with the configuration. But its magic commands also parse their arguments with a form of argparse. For that it has its own REPL, rather than using input/raw_input.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.