RE: [Tutor] sys.argv[1: ] help
Richard, I have no problems running your example. It would be helpful in the future ot let us know which version and variant of Python you are running. I am using the canonical (as oppose to ActiveState) Python 2.4. From the command prompt, type assoc .py and you should see .py=Python.File Then type ftype Python.File which should return Python.File=C:\Python24\python.exe %1 %* If the last one isn't correct (with approriate path and assoc type associations) then you can correct it with ftype ASSOCTYPE=PATHSTUFF As an added bonus, you can also create a system environment variable called PATHEXT and set it to .py and you won't even have to type the .py to execute the script. I added all the following to my PATHEXT: .py;.pyw;.pys;.pyo;.pyc While you're at it, you should also check the assoc/ftype for .pyw as .pyw=Python.NoConFile Python.NoConFile=C:\Python24\pythonw.exe %1 %* Good luck, Jeff -Original Message- From: Richard gelling [mailto:[EMAIL PROTECTED] Sent: Sunday, February 27, 2005 1:41 PM To: tutor@python.org Subject: Re: [Tutor] sys.argv[1: ] help Hi, It is actually associated with just 'python', changed it to associate with 'pythonw' and I got nothing on the same example not even the [], so I am assuming that 'python' is the correct one? Liam Clarke wrote: Yeah, right click on a .py and check if it's associated with pythonw or python.exe GL, Liam Clarke On Sun, 27 Feb 2005 18:28:18 +, Richard gelling [EMAIL PROTECTED] wrote: Hi, Yes, I use both Wndows XP and Linux( at work ) . I left that in by mistake I am actually just typing in arg1,py a b c at the windows XP command prompt Sorry for the confusion. Liam Clarke wrote: 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 +, Richard gelling [EMAIL PROTECTED] 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@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
Hi, Thanks a lot to everyone that replied. I was missing the %* in the following line, in the File associations I just had upto the %1. Adding %* cured my problem. Python.File=C:\Python24\python.exe %1 %* Sorry for the typos in some of my examples, every keyboard I've tried appears to have the same fault on it! Anyway thanks a lot again, Richard G. Smith, Jeff wrote: Richard, I have no problems running your example. It would be helpful in the future ot let us know which version and variant of Python you are running. I am using the canonical (as oppose to ActiveState) Python 2.4. From the command prompt, type assoc .py and you should see .py=Python.File Then type ftype Python.File which should return Python.File=C:\Python24\python.exe %1 %* If the last one isn't correct (with approriate path and assoc type associations) then you can correct it with ftype ASSOCTYPE=PATHSTUFF As an added bonus, you can also create a system environment variable called PATHEXT and set it to .py and you won't even have to type the .py to execute the script. I added all the following to my PATHEXT: .py;.pyw;.pys;.pyo;.pyc While you're at it, you should also check the assoc/ftype for .pyw as .pyw=Python.NoConFile Python.NoConFile=C:\Python24\pythonw.exe %1 %* Good luck, Jeff -Original Message- From: Richard gelling [mailto:[EMAIL PROTECTED] Sent: Sunday, February 27, 2005 1:41 PM To: tutor@python.org Subject: Re: [Tutor] sys.argv[1: ] help Hi, It is actually associated with just 'python', changed it to associate with 'pythonw' and I got nothing on the same example not even the [], so I am assuming that 'python' is the correct one? Liam Clarke wrote: Yeah, right click on a .py and check if it's associated with pythonw or python.exe GL, Liam Clarke On Sun, 27 Feb 2005 18:28:18 +, Richard gelling [EMAIL PROTECTED] wrote: Hi, Yes, I use both Wndows XP and Linux( at work ) . I left that in by mistake I am actually just typing in arg1,py a b c at the windows XP command prompt Sorry for the confusion. Liam Clarke wrote: 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 +, Richard gelling [EMAIL PROTECTED] 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@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
Danny Yoo wrote: I am reading ' Learning Python second edition' by Mark Lutz and David Ascher, and I trying the code examples as I go along. However I am having a problem with the following, which I don't seem to be able to resolve :- # test.py import sys print sys[ 1: ] This I believe is supposed to print the 1st argument passed to the program. However if I try test.py fred All I get at the command line is [] Hi Jay, Are you sure that is what your program contained? I'm surprised that this didn't error out! The program: ## import sys print sys[1:] ## should raise a TypeError because 'sys' is a module, and not a list of elements, and modules don't support slicing. Just out of curiosity, can you confirm that you aren't getting an error message? (I know I'm being a bit silly about asking about what looks like a simple email typo, but computer programming bugs are all-too-often about typos. *grin* When you write about a program, try using cut-and-paste to ensure that the program that you're running is the same as the program you're showing us.) Best of wishes to you! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Hi, 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@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
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@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
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 +, Richard gelling [EMAIL PROTECTED] 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@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@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. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
Yeah, right click on a .py and check if it's associated with pythonw or python.exe GL, Liam Clarke On Sun, 27 Feb 2005 18:28:18 +, Richard gelling [EMAIL PROTECTED] wrote: Hi, Yes, I use both Wndows XP and Linux( at work ) . I left that in by mistake I am actually just typing in arg1,py a b c at the windows XP command prompt Sorry for the confusion. Liam Clarke wrote: 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 +, Richard gelling [EMAIL PROTECTED] 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@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@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. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
Hi, It is actually associated with just 'python', changed it to associate with 'pythonw' and I got nothing on the same example not even the [], so I am assuming that 'python' is the correct one? Liam Clarke wrote: Yeah, right click on a .py and check if it's associated with pythonw or python.exe GL, Liam Clarke On Sun, 27 Feb 2005 18:28:18 +, Richard gelling [EMAIL PROTECTED] wrote: Hi, Yes, I use both Wndows XP and Linux( at work ) . I left that in by mistake I am actually just typing in arg1,py a b c at the windows XP command prompt Sorry for the confusion. Liam Clarke wrote: 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 +, Richard gelling [EMAIL PROTECTED] 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@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
Hi, It is actually associated with just 'python', changed it to associate with 'pythonw' and I got nothing on the same example not even the [], so I am assuming that 'python' is the correct one? Liam Clarke wrote: Yeah, right click on a .py and check if it's associated with pythonw or python.exe GL, Liam Clarke On Sun, 27 Feb 2005 18:28:18 +, Richard gelling [EMAIL PROTECTED] wrote: Hi, Yes, I use both Wndows XP and Linux( at work ) . I left that in by mistake I am actually just typing in arg1,py a b c at the windows XP command prompt Sorry for the confusion. Liam Clarke wrote: 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 +, Richard gelling [EMAIL PROTECTED] 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@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
Yeah, python.exe is the right one... bizarre... I'll have a poke at it when I get home from work. Sorry I haven't been more helpful. Cheers, Liam Clarke On Sun, 27 Feb 2005 18:57:30 +, Richard gelling [EMAIL PROTECTED] wrote: Hi, It is actually associated with just 'python', changed it to associate with 'pythonw' and I got nothing on the same example not even the [], so I am assuming that 'python' is the correct one? Liam Clarke wrote: Yeah, right click on a .py and check if it's associated with pythonw or python.exe GL, Liam Clarke On Sun, 27 Feb 2005 18:28:18 +, Richard gelling [EMAIL PROTECTED] wrote: Hi, Yes, I use both Wndows XP and Linux( at work ) . I left that in by mistake I am actually just typing in arg1,py a b c at the windows XP command prompt Sorry for the confusion. Liam Clarke wrote: 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 +, Richard gelling [EMAIL PROTECTED] 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@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@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. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
(I know I'm being a bit silly about asking about what looks like a simple email typo, but computer programming bugs are all-too-often about typos. *grin* 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:], Hi Richard, Please, please copy and paste your code literally whenever you're talking about code. You have another email typo here, when you put a comma instead of a period in: sys,argv[1:] I know that's not what you meant, but I'm really trying to stress the idea that computers are not forgiving of typos. There are actually a large class of programming bugs that are simple typos. Make things easier for us: just copy and paste the code that you're talking about, and we'll be better able to replicate the situation that's on your side. I think there's been a lot of confusion on this thread, so let's backtrack again and make sure we're on the same page. I'll assume for the moment that your program looks like this: ## import sys print sys.argv[1:] ## this does now work as long as I run 'python test.py fred joe' it returns all the arguments. I expect to see: ### ['fred', 'joe'] ### because sys.argv should contain the list: ['test.py', 'fred', 'joe'] If I try just test.py all I get is '[]'. Ok, this is also expected. If we give no command line arguments to our program, then we should get back an empty list from sys.argv[1:]. So at the moment, I actually have no clue what problem you're running into. *grin* What exactly are you getting stuck on? 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. Wait. Ok, I think I understand the question now. I think you are trying to say that if you enter the command: ### C:\ test.py fred joe ### at your Windows command prompt, that Python responds with: ### [] ### Does this sound right? If so, then you are asking a question that's specific to Windows. The Windows command shell has a bug that has bitten folks before: Windows doesn't appear to correctly pass command line arguments to Python programs if we try to call the program directly. A workaround is to create a '.CMD' wrapper for your Python program. Add a file called 'test.cmd' in the same directory as your 'test.py' program with the following content: ### python test.cmd %* ### Once you have this file, try: ### C:\ test fred joe ### at your command line. You may find the discussion underneath: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/366355 useful, as the folks there further discuss this issue. Let's backtrack for a moment again: the reason we were not able to answer your question better was precisely because you were paraphrasing way too much: ... as I run 'python test.py fred joe' it returns all the arguments. If I try just test.py all I get is '[]'. If you had shown us exactly what you were entering into the command line, we would have caught the real cause of the problem much earlier. Ok, I'll stop ranting about this now. *grin* Best of wishes to you. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
Add a file called 'test.cmd' in the same directory as your 'test.py' program with the following content: ### python test.cmd %* ### Scratch that! *grin* Sorry, meant to write that the test.cmd should contain: ### python test.py %* ### Darn it, but I don't have a Windows box handy to test this. Can someone double check this to make sure I haven't screwed up again? Sorry about that; I should never post anything without testing it first. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
On Sun, 27 Feb 2005 17:55:54 +, Richard gelling [EMAIL PROTECTED] wrote: No What I get if I was to type in ./arg1.py a b c All I get is [] It sounds as though the command shell is not passing along the additional parameters. Try opening Windows Explorer, and go to the Folder Options (in the Tools menu, IIRC). Go to the File Types tab, find PY (Python File), and click the Advanced button. In the resulting dialog, select the open action and click edit, then look at the command line that it's using. You want something that looks like: C:\Python23\python.exe %1 %* The '%*' bit at the end is what I suspect may be missing in your settings. (There's some chance that cmd.exe uses a different set of settings than Windows Explorer does, in which case you'll have to research that independently. I know that you can use the assoc command to associate the .py extension with the Python.File filetype, but I'm not sure how to create filetypes or change actions that are taken upon filetypes if it's different from the Explorer settings) Jeff Shannon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
Should be: import sys def main(): '''prints out the first command line argument''' print sys.argv[1] main() On Friday 25 February 2005 04:35 pm, Richard gelling wrote: Hi, I am reading ' Learning Python second edition' by Mark Lutz and David Ascher, and I trying the code examples as I go along. However I am having a problem with the following, which I don't seem to be able to resolve :- # test.py import sys print sys[ 1: ] This I believe is supposed to print the 1st argument passed to the program. However if I try test.py fred All I get at the command line is [] If I try :- python test.py fred I get ['fred'] as I believe you are supposed to. I can run other examples,I have typed in by just using the file name, but not this particular example. Could anyone shine any light on what I am missing or have not configured correctly. I am runnung Python 2.4 on a windows XP box. Thanks a lot Richard G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
Remember computers count from 0, so sys[1] is the 2nd argument, sys[0] is always the filename. On Fri, 25 Feb 2005 22:33:50 -0500, Jay Loden [EMAIL PROTECTED] wrote: Should be: import sys def main(): '''prints out the first command line argument''' print sys.argv[1] main() On Friday 25 February 2005 04:35 pm, Richard gelling wrote: Hi, I am reading ' Learning Python second edition' by Mark Lutz and David Ascher, and I trying the code examples as I go along. However I am having a problem with the following, which I don't seem to be able to resolve :- # test.py import sys print sys[ 1: ] This I believe is supposed to print the 1st argument passed to the program. However if I try test.py fred All I get at the command line is [] If I try :- python test.py fred I get ['fred'] as I believe you are supposed to. I can run other examples,I have typed in by just using the file name, but not this particular example. Could anyone shine any light on what I am missing or have not configured correctly. I am runnung Python 2.4 on a windows XP box. Thanks a lot Richard G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@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. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.argv[1: ] help
I am reading ' Learning Python second edition' by Mark Lutz and David Ascher, and I trying the code examples as I go along. However I am having a problem with the following, which I don't seem to be able to resolve :- # test.py import sys print sys[ 1: ] This I believe is supposed to print the 1st argument passed to the program. However if I try test.py fred All I get at the command line is [] Hi Jay, Are you sure that is what your program contained? I'm surprised that this didn't error out! The program: ## import sys print sys[1:] ## should raise a TypeError because 'sys' is a module, and not a list of elements, and modules don't support slicing. Just out of curiosity, can you confirm that you aren't getting an error message? (I know I'm being a bit silly about asking about what looks like a simple email typo, but computer programming bugs are all-too-often about typos. *grin* When you write about a program, try using cut-and-paste to ensure that the program that you're running is the same as the program you're showing us.) Best of wishes to you! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor