Python Forum

Full Version: switch to python3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.