Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
switch to python3
#1
if bytes == str:
    import os,sys
    for p in os.environ.get('PATH','').split(':'):
        if p and os.path.exists(p+'/python3'):
            os.execvp(p+'/python3',['python3']+sys.argv)
this snippet of code is how i make scripts that really, really, really need to run in python3 do so. i run it at the top of the script before anything happens since everything above it will be run again under python3. note that if the system does not have python3 it just goes on and lets the script crash. you can add an else or another test if you don't want that to happen. i wrote a similar snippet that switches to python2 but no one would ever need that.
Tradition is peer pressure from dead people

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Roshambo with only 1 if switch Clunk_Head 12 5,691 Jan-28-2019, 08:59 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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