I have a Python script that uses Python syntax version 2.6 (except for error as value :), which version 2.5 refers to. Therefore, in my script, I included some code to check the version of the Python interpreter before proceeding so that the user does not get an unpleasant error, however, no matter where I place this code, it does not work. When it gets into weird syntax, it throws a syntax error, not paying attention to any version checking attempts.
I know that I can just place the try / except block over the area in which SyntaxError is raised and throw a message there, but I wonder if there is a more βelegantβ way. Since I'm not really trying to place try / except blocks all over my code to solve the version problem. I was looking for the use of the __ init__.py file, but the user will not import / use my code as a package, so I donβt think this route will work if I donβt miss something ...
Here is my version verification code:
import sys def isPythonVersion(version): if float(sys.version[:3]) >= version: return True else: return False if not isPythonVersion(2.6): print "You are running Python version", sys.version[:3], ", version 2.6 or 2.7 is required. Please update. Aborting..." exit()
python interpreter
Stunner
source share