SyntaxError: f-string: expecting '}'

Viewed 9623

I have a problem here.

I don't know why this code does not work.

newline = '\n'
tasks_choosen = ['markup', 'media', 'python_api', 'script', 'style', 'vue']
print(f'{ newline }### Initializing project with the following tasks: { ' '.join(tasks_choosen) }.{ newline }')

Error:

File "new-gulp-project.py", line 85

print(f'{ newline }### Initializing project with the following tasks: { ' '.join(tasks_choosen) }.{ newline }')

SyntaxError: f-string: expecting '}'

Can anyone help me?

Thanks

2 Answers

Because you use single quotes twice you get: print(f'{ newline }### Initializing project with the following tasks: { ' instead of

print(f'{ newline }### Initializing project with the following tasks: { ' '.join(tasks_choosen) }.{ newline }')

Use double quotes inside:

print(f'{ newline }### Initializing project with the following tasks: { " ".join(tasks_choosen) }.{ newline }')

Python is getting confused as you are using ' ' (single-quotes) for the f-string and ' ' (single-quotes) just before the join, so its getting confused as to where your f-string actually ends. Replace the ' ' with " " just before the .join() and it should work :)

Related