I want to inform the user which python version they should use:
import sys
assert sys.version_info >= (3, 6), "Use Python 3.6 or newer"
print(f"a format string")
But instead, running the above file makes a syntax error:
$ python fstring.py. # default python is 2.7
File "fstring.py", line 3
print(f"a format string")
^
SyntaxError: invalid syntax
Is it possible to do this per-file, without wrapping all the f-strings inside of try blocks?
SyntaxError
s are raised when the code is being compiled – Severancef"If you see this in an error message, use Python 3.6 or newer"
? :-P Wouldn't be pretty, but might serve the purpose. – Zischke