I have a python program that can be run both: with python
or python3
:
# that
python app.py
# or that
python3 app.py
How to detect inside app.py
program which command was used?
I tried to use sys.argv
, but it doesn't contains such info.
Any ideas?
Try sys.version_info
, specifically sys.version_info.major
, which should be 2 or 3, respectively.
A different way is using the six
package, with the booleans six.PY2
and six.PY3
. This package should give other useful utilities for 2/3 compatibility.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With