[Tutor] sys.argv[1: ] help
Liam Clarke
cyresse at gmail.com
Sun Feb 27 19:22:49 CET 2005
Are you using XP still? I've never seen this before -
> ./arg1.py a b c
But anyhoo, I tried out just
'c:\python23\foo.py'
as opposed to
'c:\python23\python foo.py' and
while foo.py will run, it doesn't echo to the console, as on my
machine running a .py file runs it through pythonw.exe - I'd check it
out for your machine, it's probably the same. You'd need to change the
association to python.exe, but that would mean that you always got a
DOS box for every Python script you ran, which is annoying with GUIs.
Erm, if you don't want to type in python each time, either change the
association or create a batch file called x or a or something that
runs Python and stick it in a directory that's in your PATH system
variable. Only problem with that is passing command line variables....
...might just be better to type python....
Good Luck,
Liam Clarke
On Sun, 27 Feb 2005 17:55:54 +0000, Richard gelling
<uselinux34 at yahoo.co.uk> wrote:
>
> 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
> >
> >
> >
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
More information about the Tutor
mailing list