title: Checking Version of Python Interpreter Upon Execution of Script With Invalid Syntax
body: <p>I have a Python script that uses Python version 2.6 syntax (Except <em>error</em> as <em>value</em>:) which version 2.5 complains about. So in my script I have included some code to check for the Python interpreter version before proceeding so that the user doesn't get hit with a nasty error, however, no matter where I place that code, it doesn't work. Once it hits the strange syntax it throws the syntax error, disregarding any attempts of mine of version checking. </p>
  
  <p>I know I could simply place a try/except block over the area that the SyntaxError occurs and generate the message there but I am wondering if there is a more "elegant" way. As I am not very keen on placing try/except blocks all over my code to address the version issue. I looked into using an __ init__.py file, but the user won't be importing/using my code as a package, so I don't think that route will work, unless I am missing something...</p>
  
  <p>Here is my version checking code:</p>
  
  <pre><code>import sys
  def isPythonVersion(version):
      if float(sys.version[:3]) &gt;= 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()
  </code></pre>