PythonL: invalid syntax file “<fstring>”, line 1

一曲冷凌霜 提交于 2019-12-05 05:11:45

I just spent 1 hour reviewing my code with the same issue. In my case I started removing parts of the code to narrow down the problem.

Finally I to the root cause of the problem.

in my case I was printing an f"string" and inside the f string I had a space in the name of the variable I was calling example print(f"This is a statement {Var 23} "

That space, generated my problem.

I hope this helps :)

This happens when anything inside {} is not valid, in a string formatted using the f string formatting prefix. Python 3.7 in my case. The upside is you get the string causing the problem on the error message. You don't get the line number, but it's still easy to figure out once you acknowledge that line number 1 is not the correct line number of the error.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!