这就是我要做的:
LAYOUT = "{!s:4} {!s:11} {!s:10} {!s:10} {!s:15} {!s:10} {!s:10} {!s:15} {!s:10} {!s:10}"
Item_1 = [002,"Cucharas",12.3,12.5,"4/5/16",200,12.5,"4/6/16",150,140]
print LAYOUT.format("UPC", "Item", "Cost", "Price", "F_Comp", "QTY", "Profit", "F_Venta", "QTY_Sold", "QTY_Alm")
print LAYOUT.format[Item_1]
我想用LAYOUT
打印几个列表。实际上,我从这里的另一个答案中采用了这种格式化方法,但我不断得到以下错误:
Traceback (most recent call last):
File "main.py", line 6, in <module>
print LAYOUT.format[Item_1]
TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
方括号
[]
通常用于索引和切片,它调用对象的__getitem__
方法,而str.format
函数没有该方法。像上一行一样使用括号,并用*
解压iterable:相关问题 更多 >
编程相关推荐