Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
code to run in python3
#9
but what about distributing such code?  i may sometimes need it, but if i put it in the code, it will always be in there.  i'm trying to teach interactive bash how to run .py code in the correct version of python when it runs the code not in the context of an executable but has to specify which interpreter.  in the command_not_found_handle() i have it check for existence of $name.py and if it exists and is readable, read one line to see if it has a #! line.  if it has one that has "py" in it then it is a python command.  if it also has a '2' and not a '3' then use python2.  if it has a '3' and not a '2' then use python3.  execute it (passing the args) under the selected python.  if it has neither '2' nor '3' or has both (yeah, odd) an environment variable PYTHON_DEFAULT_VERSION is not set, it tries guess.  it can pick the wrong version.  but there are also cases where the version does not matter (most of my code).  where it does not matter, i want a way to be specific about that (like maybe "#!/usr/bin/env pythonx") so it can always run under whatever is there.  but there is no standard for this.

fyi, the thing mentioned above lets me create "foo.py" and do "foo bar" to run it passing "bar" as an argument, if i included the #! in it.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
code to run in python3 - by Skaperen - Nov-05-2017, 01:30 AM
RE: code to run in python3 - by heiner55 - Nov-11-2017, 06:12 PM
RE: code to run in python3 - by Larz60+ - Nov-11-2017, 07:45 PM
RE: code to run in python3 - by Skaperen - Nov-12-2017, 04:23 AM
RE: code to run in python3 - by heiner55 - Nov-12-2017, 01:44 PM
RE: code to run in python3 - by Skaperen - Nov-13-2017, 02:44 AM
RE: code to run in python3 - by snippsat - Nov-12-2017, 06:55 PM
RE: code to run in python3 - by heiner55 - Nov-13-2017, 03:16 AM
RE: code to run in python3 - by Skaperen - Nov-13-2017, 04:03 AM
RE: code to run in python3 - by wavic - Nov-13-2017, 08:47 AM
RE: code to run in python3 - by Skaperen - Nov-13-2017, 09:44 AM
RE: code to run in python3 - by wavic - Nov-13-2017, 10:15 AM
RE: code to run in python3 - by Skaperen - Nov-14-2017, 01:02 AM
RE: code to run in python3 - by metulburr - Nov-14-2017, 02:19 AM
RE: code to run in python3 - by Skaperen - Nov-14-2017, 07:07 AM
RE: code to run in python3 - by metulburr - Nov-14-2017, 06:48 PM
RE: code to run in python3 - by Skaperen - Nov-15-2017, 01:15 AM
RE: code to run in python3 - by metulburr - Nov-15-2017, 01:41 AM
RE: code to run in python3 - by Skaperen - Nov-15-2017, 02:47 AM
RE: code to run in python3 - by metulburr - Nov-15-2017, 04:41 AM
RE: code to run in python3 - by Skaperen - Nov-16-2017, 03:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  What the difference between python2 and python3 when they running my code. lpangfeic 1 1,856 Nov-19-2019, 04:44 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020