[Tutor] pass arg to list
Steven D'Aprano
steve at pearwood.info
Thu Jul 18 17:24:24 EDT 2019
On Thu, Jul 18, 2019 at 11:34:09AM -0700, Anirudh Tamsekar wrote:
> My script below is blowing index out of range after adding the args.
> version = sys.argv[1]
> Traceback (most recent call last):
> File "/Users/atamsekar/Projects/PulseSO/trunk/swrelease/samplexls.py",
> line 5, in <module>
> version = sys.argv[1]
> IndexError: list index out of range
The obvious question is, are you passing command line arguments to your
script?
How are you calling your script? If you are running it from an IDE you
need to tell the IDE to include command line arguments.
If you run it like this, from the operating system's command line:
python samplexls.py
then there are no command line arguments and sys.argv[1] will be out of
range. You need to run something like this:
python samplexls.py argument1 argument2
Try putting:
print(sys.argv)
at the start of your script and see what is there.
--
Steven
More information about the Tutor
mailing list