0

I've tested the script with spyder on Windows 10 and it worked perfectly. Now I'm trying to run it on an ubuntu virtual host and it's giving me an invalid syntax error.

The python version is Python 3.5.2 (latest version I get after updating it). The Ubuntu version is

Description:    Ubuntu 16.04.7 LTS
Release:        16.04
Codename:       xenial

I know it's outdated but I can't update it myself...

The code snipped giving problems to begin with is just a simple:

# Begin of time period. Format: YYYY-mm-dd
date_from = f'{year}-01-01'

I'm testing it with "python my_file.py"

1 Answer 1

2

F-strings can only be used Python 3.6 and above as mentioned in the new features of Python 3.6:

New Features PEP 498 introduces a new kind of string literals: f-strings, or formatted string literals. Formatted string literals are prefixed with 'f' and are similar to the format strings accepted by str.format(). They contain replacement fields surrounded by curly braces. The replacement fields are expressions, which are evaluated at run time, and then formatted using the format() protocol:

To fix this you can use str.format() instead: date_from = '{}-01-01'.format(year) or you could upgrade your Python: sudo apt install python3.7

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.