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
    If you want something "interactive", you might consider using [`raw_input`](https://docs.python.org/2/library/functions.html#raw_input) and a `while` loop – Daniel Corin Jul 13 '17 at 02:47

1 Answers1

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.

hpaulj
  • 221,503
  • 14
  • 230
  • 353