Check Python version from inside script? Run Pythons script in v2 compatibility mode?

Ben S. bxstover at yahoo.co.uk
Fri Jul 7 02:30:31 EDT 2017


Can I somehow check from inside a Python script if the executing Python engine is major version v2 or v3?

I am thinking about a code similar to

if (os.python-majorversion<3)
  print hello
else
  print (hello)


Additional question:
Is there a way to execute a python script with v3 python engine in v2 compatibility mode?
I am thinking about a command parameter like (python.exe is v3.*):

  python.exe -execute_as_v2 myscript.py 



More information about the Python-list mailing list