title: python 2 code: if python 3 then sys.exit()
body: <p>I have a large piece of Python 2 only code. It want to check for Python 3 at the beginning, and exit if python3 is used. So I tried:</p>
  
  <pre><code>import sys
  
  if sys.version_info &gt;= (3,0):
      print("Sorry, requires Python 2.x, not Python 3.x")
      sys.exit(1)
  
  print "Here comes a lot of pure Python 2.x stuff ..."
  ### a lot of python2 code, not just print statements follows
  </code></pre>
  
  <p>However, the exit does not happen. The output is:</p>
  
  <pre><code>$ python3 testing.py 
    File "testing.py", line 8
          print "Here comes a lot of pure Python 2.x stuff ..."
                                                          ^
  SyntaxError: invalid syntax
  </code></pre>
  
  <p>So, it looks like python checks the <em>whole</em> code before executing anything, and hence the error.</p>
  
  <p>Is there a nice way for python2 code to check for python3 being used, and if so print something friendly and then exit?</p>