I want to write script with logic like below
if <script invoked by python3>:
do A
elif <script invoked by python2>:
do B
How can I achieve this?
I want to write script with logic like below
if <script invoked by python3>:
do A
elif <script invoked by python2>:
do B
How can I achieve this?
You are most likely after something similar to this (refer to original question and answer):
import sys
if sys.version_info.major >= 3:
# Python 3 code
else:
# Python 2 code
.major) of sys.version_info were introduced in 2.7/3.1. If, for some terrible reason, you need to support 2.6 or earlier, or 3.0, you'd test if sys.version_info >= (3,):