Posts: 4,550
Threads: 1,458
Joined: Sep 2016
something i am trying to come up with is a
hash bang string to begin Python scripts with, that will try to run Python3, but will fall back to the version specified by the name without a version number on it, and if that is not available, fall further back to Python2, without setting up or installing any files or doing any config changes on the system that the script with this
hash bang string is being run on.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,550
Threads: 1,458
Joined: Sep 2016
yes, for
linux, or
bsd, or
unix. i do write lots of version-agnostic code. i have used
os.execvp()
often enough. but i would like to do it with no more files than the one that uses the
clever hash bang ... e.g. the whole solution on that one line.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,550
Threads: 1,458
Joined: Sep 2016
putting all the code in a literal would still be on the limited hash bang line. so it sounds like a separate file will be needed.
or somehow we need to get python packaged so some particular name always references the latest installed version. too bad they (whoever they is) didn't make "python" do that everywhere. on ubuntu 16.04.3 it references python2 (2.7.12), not python3 (3.5.2). this may be because a lot of ubuntu init code references "python" expecting it to be python2 and they don't want to update their hash bang lines in all that old code (so ubuntu users are still experiencing older python). i should inventory what python usage exists in ubuntu.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,550
Threads: 1,458
Joined: Sep 2016
(Feb-17-2018, 10:31 AM)Gribouillis Wrote: Why is it a problem to add a separate file?
because this will be part of an initialization system being run on AWS EC2 instances at launch time via user data.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,550
Threads: 1,458
Joined: Sep 2016
when launching a fresh new instance, it gives you a field called "userdata" which is available to the instance. a package call "cloud-init" checks for it, and if available, and begins with #!/bin/bash (or maybe some other shell, but i have not gotten it to run python, yet), then it runs it (apparently under the selected shell interpreter). the other way to customize a launch is to build your own AMI with the files in that and launch it. but lots of people prefer to launch generic AMIs and use userdata.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.