Python File as the Default PDF handler for Windows

Mark Lawrence breamoreboy at yahoo.co.uk
Tue Jun 23 16:20:21 EDT 2015


On 23/06/2015 21:12, Dennis Lee Bieber wrote:
> On Tue, 23 Jun 2015 16:26:28 +0200 (CEST), Jean-Michel Pichavant
> <jeanmichel at sequans.com> declaimed the following:
>
>>> Just to update, you are correct, Chris, the file short name is passed
>>> into sys.argv. didn't need to add anything to the path. But a gotcha
>>> -- Windows didn't like my .py, clicking on the pdf causes Windows to
>>> complain about 'file x' is not a valid windows executable.
>>
>> I'm not an expert of windows but you probably need to specify the python interpreter, not the script itself.
>>
>> something like
>>
>> C:\Python2.7\python.exe yourscript.py %*
>>
>> in the windows file association panel.
>>
> 	Need to check the specific install, I've seen two or three different
> assoc names used in the past...
>
> Microsoft Windows [Version 6.1.7601]
> Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
>
> C:\Users\Wulfraed\Documents>assoc .py
> .py=Python.File
>
> C:\Users\Wulfraed\Documents>ftype python.file
> python.file="C:\Python_x64\Python27\python.exe" "%1" %*
>
> 	ftype links a "file type" handler to the executable path (note the "%1"
> is the placeholder for the script name itself, and arguments to the script
> are collected with %*). Assoc then links the extension to the handler (so
> you can also assoc .pyc files to the same interpreter).
>

With Python 3.4 or if you've installed the pylauncher independantly.

C:\Users\Mark\Documents\MyPython>assoc .py
.py=Python.File

C:\Users\Mark\Documents\MyPython>ftype python.file
python.file="C:\Windows\py.exe" "%1" %*

C:\Users\Mark\Documents\MyPython>assoc .pyw
.pyw=Python.NoConFile

C:\Users\Mark\Documents\MyPython>ftype python.noconfile
python.noconfile="C:\Windows\pyw.exe" "%1" %*

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list