Re: [Tutor] pass arg to list
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 > 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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pass arg to list
On 18/07/2019 19:34, Anirudh Tamsekar wrote: > # User Args > > version = sys.argv[1] > build = sys.argv[2] > > add_file = (... > ) > Traceback (most recent call last): > > File "/Users/atamsekar/Projects/PulseSO/trunk/swrelease/samplexls.py", > line 5, in > > version = sys.argv[1] > > IndexError: list index out of range The obvious thing to do is add a print statement before the asignments print(sys.argv) and check that it contains your expected values. If that doesn't help show us your full code (including import statements) and your full execution output, including whree you call the program. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] pass arg to list
Hi, I'm trying to pass arguments to list. This script needs to generate csv files. I want to pass the version and build number to the script and it should be passed to the list. My script below is blowing index out of range after adding the args. However, if I hardcode the version, it works fine. Kindly advise. # User Args version = sys.argv[1] build = sys.argv[2] add_file = ( ['AddFile', 109102010, 'Product-'+version + 'Package (Build' + build + ')', 'Product-'+version+'-b'+build+'-package.pkg', 'Product-'+version + 'Service Package (Build' + build + ')', version, ''], ) Traceback (most recent call last): File "/Users/atamsekar/Projects/PulseSO/trunk/swrelease/samplexls.py", line 5, in version = sys.argv[1] IndexError: list index out of range Process finished with exit code 1 -Thanks, Anirudh Tamsekar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor