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
Post a Comment