这就是我要做的事情:
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__'
答案 0 :(得分:3)
方括号get_model
通常用于索引和切片,它调用[]
函数所没有的对象__getitem__
方法。像上一行中那样使用括号,并使用str.format
解压缩iterable:
*