[英]TypeError: unsupported format string passed to tuple.__format__
I want to display this:我想显示这个:
Number Name号码名称
1 Jane 1 简
2 Linda 2 琳达
3 Vladimir 3 弗拉基米尔
but when I put row in the last line its giving me an error.但是当我把行放在最后一行时,它给了我一个错误。
output = cursor.fetchall()
for row in output:
print("{0:20}\t{1:20}".format("Number", "Name"))
print("{0:20}\t{1:20}".format(row, row[0]))
Based on my limited testing, Python's f-strings and .format (tested with 3.8) do not support strings like "{:2}".format([0])
(ie with arguments of list type).根据我有限的测试,Python 的 f-strings 和 .format(用 3.8 测试)不支持像
"{:2}".format([0])
这样的字符串(即带有列表类型的参数)。 If you do need a list printed out, convert it to str
:如果您确实需要打印出列表,请将其转换为
str
:
rows = [[1, "Jane"], [2, "Linda"], [3, "Vladimir"]]
print("{0:16}{1:8}".format("Number", "Name"))
for row in rows:
print("{0:<16}{1:8}".format(str(row), row[1]))
Or just pass each element separately:或者只是分别传递每个元素:
rows = [[1, "Jane"], [2, "Linda"], [3, "Vladimir"]]
print("{0:8}{1:8}".format("Number", "Name"))
for row in rows:
print("{0:<8}{1:8}".format(row[0], row[1]))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.