I am working on issue that I was thinking is a minor thing but I cannot get it to work. As in the title - I wrote a program that requires usage of python3.6+ due to f-strings presence. My intention is to catch the SyntaxError when user for example have python3.5 on his OS.
My initial idea:
def main():
var = "more"
print(f'I like f-strings a lot and {var}')
if __name__ == "__main__":
if (sys.version_info.major == 3) and (sys.version_info.minor < 6):
print("This program requires python3.6 or newer")
print(old_python_error_message)
else:
print("Program starts...")
main()
The problem is that I still got that error before script even starts.
Reason - as far as I researched - is:
You can only catch SyntaxError if it's thrown out of an eval, exec, or import operation.
Link: Failed to catch syntax error python
I still have no idea how can I do that in f-strins usage case.
Thanks for your time