[Tutor] sys.argv[1: ] help

Richard gelling uselinux34 at yahoo.co.uk
Mon Feb 28 20:21:05 CET 2005


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:uselinux34 at yahoo.co.uk] 
>Sent: Sunday, February 27, 2005 1:41 PM
>To: tutor at 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 +0000, Richard gelling 
>><uselinux34 at yahoo.co.uk> 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 +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. _______________________________________________
>>>>>>>              
>>>>>>>
>
>  
>



More information about the Tutor mailing list