0

I want to write a simple python program that will take a file as an argument and an integer. I would want it to look like this: simple.py myJ.json 5

After that I want to have access to myJ.json and 5arguments within my code. Basically something that would allow me to store them as variables that I can refer to for the rest of the execution of my code within simple.py.

my_json = command.arg[1] #something like that
integer = commmand.arg[2]

integer = integer + 1
: doing things with them afterwards.
:
:
BreezeWind
  • 618
  • 1
  • 9
  • 18

1 Answers1

1

To solve your problem you can use method in library called (sys) just typefrom sys import argv at the front of your code. And know that argv[0] is equal to your python file name and argv[1] is equal to first argument and argv[2] is equal to second argument. For summary of all that in this case simple.py myJ.json 5

from sys import argv

argv[1] = myJ.json argv[2] = 5

I hope that I could help you :)