Answer the question
In order to leave comments, you need to log in
python error SyntaxError: invalid syntax how to solve?
Hello. There is a small python script, I run it on windows, everything works ok.
Took an Ubuntu 18.04 server.
Installed python 3.7.9 (the same version on Windows)
I run the script there and the script gives me errors:
print(f'DEBUG: {e}')
^
SyntaxError: invalid syntax
self.file_name = f'{self.base_name}.json '
^
SyntaxError: invalid syntax
What could be wrong?
Thank you in advance
Answer the question
In order to leave comments, you need to log in
This is because Python 2.7 is installed by default on your system.
You installed the third version, but it doesn’t replace the second one (you didn’t even specify how you run the script) - that’s why the second Python doesn’t like print(), because in the second print is a statement, and in the third the print statement was replaced by the print function ().
Python2:
Python3
print "Дважды два: ", 2*2
print("Дважды два: ", 2*2)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question