Python 其他工作程序中的元组问题

Python 其他工作程序中的元组问题,python,tuples,Python,Tuples,我不断得到以下错误: Traceback (most recent call last): File "G:\Data\Box Sync\Box Sync\run9.py", line 122, in <module> print "%11s %11s %10.f %17.f %1.2f %7.f %2.2f %2.2f %2.2f" %(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) IndexError:

我不断得到以下错误:

Traceback (most recent call last):
  File "G:\Data\Box Sync\Box Sync\run9.py", line 122, in <module>
    print  "%11s %11s %10.f %17.f %1.2f %7.f %2.2f %2.2f %2.2f" %(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8])
IndexError: tuple index out of range
这意味着你的对象i是一个元组,它只有不到9个元素。这是一条从元组引发的错误消息。\uuu getitem\uuuuu:

如果使用常规的%格式化方法,即放置元组本身,则会看到一条不同且可能更有用的错误消息:

>>> '%s %s %s' % (0, 1)
TypeError: not enough arguments for format string

n的值是多少?如何计算sortedlist?它的维度是什么?n是一个列表的行数-在本例中,它是12。该列表以前使用排序命令进行排序。排序列表按照比率的顺序进行排序。这一部分很好,但增加了列表项6、7和8,这是印刷品中出现问题的地方。正如wim i在回答中提到的,这超出了范围。尝试在打印语句之前显示i的长度,即leni
>>> ('a', 'b')[3]
IndexError: tuple index out of range
>>> '%s %s %s' % (0, 1)
TypeError: not enough arguments for format string