P
P
peterfarmer2020-11-02 18:25:13
Python
peterfarmer, 2020-11-02 18:25:13

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

2 answer(s)
H
Hanneman, 2020-11-02
@peterfarmer

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)

T
Timtaran, 2020-11-02
@Timtaran

By default, ubuntu on the pythonUbuntu command runs the code for python2.7, python3- python3.5 (installed by default too).
To run the code on version 3.7.9 you need a command python3.7(if you only have one python 3.7)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question