请详细说明为什么要解压缩太多(我的for循环中的ValueError).Have试过deb
naislist = [('CONTROL FILE', '0', '0', '0'),
('REDO LOG', '0', '0', '0'),
('ARCHIVED LOG', '.69', '.59', '3'),
('BACKUP PIECE', '46.54', '0', '192'),
('IMAGE COPY', '0', '0', '0'),
('FLASHBACK LOG', '10.15', '6.31', '82'),
('FOREIGN ARCHIVED LOG', '0', '0', '0')]
print "size of naislist is ",len((naislist))
heading = ('MAIN MENU', 'LEVELS', 'LEVEL2', 'LEVEL3')
rearrange = dict(zip((0, 1, 2, 3), (len(str(x)) for x in heading)))
for tu, x in naislist:
rearrange.update((i, max(rearrange[i], len(str(el)))) for i, el in enumerate(tu))
rearrange[4] = max(rearrange[4], len(str(x)))
forkit = '|'. join('%%-%ss' % rearrange[i] for i in xrange(0, 4))
print '\n'.join((forkit % heading,
'-|-'.join(rearrange[i] * '-' for i in xrange(4)),
'\n'.join(forkit % (a, b, c, d) for (a, b, c), d in naislist)))
答案 0 :(得分:4)
因为naislist
中每个项目有四个元素,而你的循环只指定两个变量(tu, x
)来解压缩它们。