Can Python learn from Perl? Perl 5 can now run Perl 6 code

Jussi Piitulainen jussi.piitulainen at helsinki.fi
Thu Jul 28 03:59:29 EDT 2016


Lutz Horn writes:

> Hi,
>
> Am 07/28/2016 um 09:21 AM schrieb Steven D'Aprano:
>> But Perl has a feature that if you tell it to run a file with a
>> hashbang line, it will call the given executable to run that
>> file. That's now been improved to recognise Perl6 as an external
>> executable, instead of trying to run it as Perl 5 code.
>
>> Should Python do something similar? At least for Python 2/3 code?
>
> Do you mean something like
>
> #!/usr/bin/env python2.7
>
> # here comes Python 3 code
>
> should be run using python3, if installed? Why not just put the
> python3 executable into the hashbang line?

No, he means that something like

#!/usr/bin/env python3.5

# here comes Python 3 code

should be run using python3.5 (the "given executable") when invoked with
a python, whether that python happens to be a python2 or a python3, and
something like

#!/usr/bin/env python2.7

# here comes Python 2 code

should be run using python2.7 (the "given executable") when invoked with
a python, whether that python happens to be a python2 or a python3.

I suppose it would solve the mess in systems that associate scripts to
interpreters based on file extensions and cannot distinguish between
foo.py and bar.py that need different interpreters. Assuming there are
such systems. I seem to remember that some have a problem deciding
whether to run the script or to open it in the editor that was used to
write it.

It might need to be smart to use python3.5 for scripts that call for
python3.4 when the former is installed and the latter not. Perhaps not
call python3.4 when explicitly invoked with python3.5 even when both are
installed. And so on.



More information about the Python-list mailing list