I have a script that should only be run with Python 3. I want to give a nice error message saying that this script should not be run with python2 if a user tries to run it with Python 2.x
How do I do this? When I try checking the Python version, it still throws an error, as Python parses the whole file before executing my if condition.
If possible, I'd rather not make another script.
SyntaxError, you can't avoid it; as you say, the error comes before any code you've written runs. You have to write code that is syntactically valid in both versions.