1

I'm writing a python (v. 3.9) program intended to be run in interactive mode. Program needs an argument to run properly. So, I try to check if the argument is present or if it is not in order to continue with the following lines:

import sys

if (len(sys.argv) >= 2):
    prefix=sys.argv[1]
else : 
    print(" Usage: python -i my_program.py one_argument")
    quit()

But it just shows an error message and does not exit. I have tried also exit() sys.exit() type(quit()) (in place of quit()) with the same result.

Is it possible to program in advance quitting in interactive mode?

Carlos
  • 11
  • 2
  • 3
    Instead of requiring the user to use a certain flag, you can start the REPL yourself: https://docs.python.org/3/library/code.html#code.interact – Wombatz Jul 21 '22 at 07:45

0 Answers0