python格式字符串TypeError : not all arguments converted during string formatting

标签 python

有很多条目,根据:"TypeError: not all arguments converted during string formatting"但我没有找到原因,为什么会这样:

print("File: %30s "%("name"))

正在工作,但不是这个:

leng=30
print("File: %"+ str(leng) +"s "%("name"))    

最佳答案

由于操作顺序,您的代码评估为:

"File: %" + str(leng) + ("s "%("name"))

要解决此问题,只需将字符串括起来,如:

("File" + ...)%("name")

关于python格式字符串TypeError : not all arguments converted during string formatting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47594101/

相关文章:

python - Sklearn kNN 使用用户定义的指标(再次)

python Selenium : Firefox auto download everything

python - GridSearchCV 分数结果是否应该等于使用相同输入的 cross_validate 分数?

python - 在 Anaconda : "ImportError: No module named django.core.wsgi" 中的 Python 上使用 mod_wsgi 配置 Django 时出错

python - 类型错误 : as_view() - Django

python - 如何在 python 中的线程之间安全地传递变量值

python - 对象保留来自先前循环迭代的信息

Python 打印语句不带回车符打印任何内容

python - 使用 Python 打印到 CSV 文件

python - 将 Excel 转换为 TIFF 文件