How to pass python command line argument? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to pass python command line argument? [duplicate]



This question already has an answer here:



I am a python beginner. Trying to pass some command line arguments.
I have used the following codes. But getting errors... transaction_file = argv[1]
IndexError: list index out of range.


import itertools
import re
from sys import argv


print ('Computing frequent item sets.')
transaction_file = argv[1]
parameter_file = argv[2]
output_file = argv[3]



Any help is greatly appreciated. Thanks......



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





In your cmd, the command to run should be like: python filename.py parameters
– Jacob Celestine
Aug 10 at 6:26






Take a look at this tutorial on CLI arguments in python : tutorialspoint.com/python/python_command_line_arguments.htm
– Chuk Ultima
Aug 10 at 6:27





You should run from terminal
– Joe
Aug 10 at 6:27






how are you executing your python file?
– juanpa.arrivillaga
Aug 10 at 6:31




1 Answer
1



Supped of call:



python aaa.py a1 a2 a3


python aaa.py a1 a2 a3



sys.argv len 4 -> sys.argv[3] return the value



or



python aaa.py a1 a2


python aaa.py a1 a2



sys.argv len 3 -> sys.argv[3] going in error



How you call the script?

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard