[Tutor] sys.argv[1: ] help
Richard gelling
uselinux34 at yahoo.co.uk
Sun Feb 27 18:55:54 CET 2005
Hi,
No What I get if I was to type in
./arg1.py a b c
All I get is
[]
If i type at the command prompt
python arg1.py a b c
I get ['a','b','c'] as expected
All the other programs and examples I have typed in work fine just by
typing in the file name, I don't have to preced the file name with
python, only this example. I hope this makes it clearer
Richard G.
Nick Lunt wrote:
>Richard,
>
>if you try to print sys.argv[1:] when sys.argv only contain sys.argv[0]
>then you are bound to get an empty list returned, [] .
>
>Im not sure I understand the problem you think you've got but here's
>what happens with sys.argv for me, and it's correct.
>
>[argl.py]
>
>$ cat argl.py
>#!/usr/bin/python
>
>import sys
>print sys.argv[1:]
>
>
>./argl.py
>[]
>
>./argl.py a b c
>['a', 'b', 'c']
>
>Is that what your getting ?
>
>
>
>
>
>
>>Sorry for the late response, I tried all of the the suggestions,
>>including correcting my typo of print sys[1:] and tried print
>>sys,argv[1:], this does now work as long as I run 'python test.py fred
>>joe' it returns all the arguments. If I try just test.py all I get is
>>'[]' . Is there something wrong with my environmental variables in
>>Windows XP, I would like to be able to just use the file name rather
>>than having to type python each time. Any help would be gratefully received.
>>
>>Richard G.
>>_______________________________________________
>>Tutor maillist - Tutor at python.org
>>http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>
More information about the Tutor
mailing list