-2

really simple question,

Okay so I have a python file, how can i run it so i can call it in the terminal like so:

python3 my_program -1

Where because ive used the number 1 afterwards in runs something different to if i ran the same thing with -2.

This is the type of funcionality I am looking for, to be able to run code depending on what the user chooses, I dont really want an interactive python file.

I apologise in advanced if this is a bad question, I am unsure as to what to google to get what I am looking for.

Cladish
  • 9
  • 3

1 Answers1

0

Just read the args correctly (use of the argv parameter), I give you this link that explains better but in resume will be like this:

import sys

print("This is the parameter of the program:", sys.argv[0])

print("Argument List:", str(sys.argv))

(make an if elif statement when the input is one or two to make different actions)

https://www.tutorialspoint.com/python/python_command_line_arguments.htm