elegant way to switch from python to python3 automatically -


i have python code want stick python3. forget python3 code , run that:

$ python foo.py 

i adopt strategy this:

#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys,os,warnings  if sys.version_info < (3,0):     sys.argv.insert(0,__file__)     warnings.warn("switch python3 automatically")     os.execv("/usr/bin/python3",sys.argv) 

is there elegant way same thing?

if don't want make executable, can create small script run_foo.sh

#!/bin/sh python3 foo.py 

then

./run_foo.sh 

i think it's still better execv in code personal convenience.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -