[Python-ideas] Make py.exe default to Python 3
Mark Lawrence
breamoreboy at yahoo.co.uk
Sat Mar 12 20:25:50 EST 2016
On 12/03/2016 23:38, Oscar Benjamin wrote:
> On 9 March 2016 at 21:25, Chris Angelico <rosuav at gmail.com> wrote:
>> On Thu, Mar 10, 2016 at 8:20 AM, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
>>> I do not believe that this needs a PEP, a tracker item should be fine IMHO.
>>> We should just ensure that the original authors of the PEP are aware, as
>>> missing out their opinions would be a disservice to the Python Windows
>>> community, as small as that may be when compared to *nix.
>>
>> Given that this is basically a Windows-only change, it doesn't matter
>> how large or small the Windows community is - they're the people who
>> primarily matter :) If someone proposed a change to the way things are
>> done on OS/2, it'd be worth getting the opinions of both of the Python
>> OS/2 users... :P
>
> Although it is a change to Windows-only I think it is important to
> think about the consistency between the way that this works on Windows
> compared with other operating systems. Inconsistencies here can be
> awkward for novices. Allow me to spell out my scenario...
>
> I teach a couple of University programming units in which students
> learn to program in Python, C and Java. The cohort for these units
> this year was 160 students. I often find myself giving the students
> instructions such as you can run this script I've given you with
>
> $ python myscript.py
>
> Now imagine that you've given that instruction to 160 students mostly
> using Windows and OSX (and a few Linux users). I find it very annoying
> that this could invoke Python 2 or 3 depending on the OS etc that the
> students are using. py.exe should solve this since I can write py -3
> and then (I assume) it would lead to an error if no Python 3 version
> is available. However that doesn't work on OSX or Linux.
>
> Okay so maybe we should just use the shebangs. I can explain to all my
> students what shebangs are and instruct the OSX students to set the
> executable bit. Then I can say so just run
>
> $ ./myscript.py
>
> however on Windows this uses file associations which is flaky. In the
> past I've seen bugs where e.g. input/output redirection didn't work
> for scripts run in this way. It also may not work in myriad other
> contexts where a command line may be used. One example is from
> Makefiles. So when my students are working in C I can give them a
> Python script that will test the output of their C program and I can
> tell them to add this to their Makefile e.g.:
>
> test: myprog.exe
> ./myscript.py
>
> At this point (on Windows) various failures are possible. If make
> simply calls CreateProcess it fails since myscript.py isn't an exe
> file (I believe it also accepts .bat files but does not observe file
> associations). If make inspects the shebang it may come to a very
> different conclusion from the one that py.exe would have (e.g. that
> python3 does not exist since it is not on PATH). Over time I've seen
> this go wrong in a number of ways and have ultimately concluded that
> anything involving using file associations is fragile.
>
> Personally I would really like it if we could have improved
> consistency across OSes when it comes to invoking Python. So I would
> really like it if we can either have py (and maybe py3) *everywhere*
> or if that's not possible find some solution that does work
> everywhere. Can we have a single command line that guarantees to run
> Python 3 (or error out)?
>
> --
> Oscar
The thing that drives me nuts is that a shebang line screws up running a
pyw file on windows.
--
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-ideas
mailing list