Please tell me how to execute python file in Ubuntu by double

eryk sun eryksun at gmail.com
Wed Dec 13 16:43:51 EST 2017


On Wed, Dec 13, 2017 at 9:04 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Thu, Dec 14, 2017 at 7:56 AM, eryk sun <eryksun at gmail.com> wrote:
>> On Wed, Dec 13, 2017 at 5:43 AM, Chris Angelico <rosuav at gmail.com> wrote:
>>>
>>> A Windows equivalent would be to have a .py file associated normally
>>> with the regular console, but some individual ones associated with
>>> pythonw.exe - without renaming them to .pyw. AFAIK there is no way to
>>> do this on Windows short of renaming the files.
>>
>> If using another file is ok, then a shell shortcut or hard link would
>> work.A symbolic link doesn't work because it seems the shell resolves
>> the link before querying the file association.
>
> As workarounds go, a hardlink isn't too bad. (A shell shortcut has its
> own problems and limitations.) But you still need to be able to define
> a filename pattern, usually by specifying an extension, that catches
> the alternates. So it's definitely a workaround, not a true feature.

I think a shell shortcut is a good workaround. It's less obtrusive
than a hard link since the script still has the same name. The command
line would be something like `"C:\Windows\pyw.exe"
"path\to\script.py"`. Clear the shortcut's "start in" field to make
pyw.exe inherit the working directory of the parent process. Add .LNK
to the PATHEXT environment variable to support executing "script.lnk"
as "script".



More information about the Python-list mailing list