you need to use sys.argv
sys.argv
The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c'. If no script name was passed to the Python interpreter, argv[0] is the empty string.
it should be :
python test.py your_file
sys.argv[0], its the script name that is test.py
sys.argv[1], will have your_file
now you can use open
built-in to open file:
my_file = open(sys.argv[1], 'r')
suppose you entered the file and number both:
python test.py your_file 2
here :
sys.argv[0] -> test.py
sys.argv[1] -> your_file
sys.argv[2] -> number that is 2