[英]What does "Unknown format code 'f' for object of type 'str' mean in my case?
This is part of a sort function I defined in a test file -- and it ran fine.这是我在测试文件中定义的 function 的一部分——它运行良好。 Then I transferred it to my main file and I'm getting all sorts of errors, mostly about mixing ints with strs, but also including this "f"-ing one, so to speak.
然后我把它转移到我的主文件中,我得到了各种各样的错误,主要是关于将 int 与 strs 混合,但也包括这个“f”-ing 一个,可以这么说。 Could this mean that pygame doesn't support the f-string formatting of newer Python versions?
这是否意味着 pygame 不支持较新 Python 版本的 f 字符串格式?
table = stat_font.render(
f"{teams[team][0]:12}{str(teamstats[team][0]):>2} - {str(teamstats[team][1]):>2} "
f"{str(teamstats[team][4]):6.3f} {str(ptdif):>}", True, white)
```
It means exactly what the error message says: You are trying to use the :6.3f
format specifier on a string, which doesn't support it.这正是错误消息所说的意思:您正在尝试在不支持它的字符串上使用
:6.3f
格式说明符。 Just remove the call to str
in the f-string field.只需在 f-string 字段中删除对
str
的调用。 It is called automatically.它是自动调用的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.