List1 = [('100.20.300.400', 'varagu', 'success'), ('100.20.300.500', 'thinai', 'success')]
List2 = [('100.20.300.600', 'Ragi', 'Failed')]
table = PrettyTable(['IP', 'Name', 'Result'])
for IP, Name, Result in succeed_ip.__getitem__():
table.add_row([IP, Name, Result])
print table
Error: for IP, Name, Result in succeed_ip.__getitem__():
TypeError: __getitem__() takes exactly one argument (0 given)
我得到了预期的结果,我提到索引 分别显示在表格中。而不是提到List1 索引,我可以得到相同的结果。我尝试了这个选项 table.add_row(List1),但我没有得到结果。我打算 将来包含更多列表,所以我不想提及索引 每次。请帮忙。谢谢!!!
答案 0 :(得分:0)
List1 = [('100.20.300.400', 'varagu', 'success'), ('100.20.300.500', 'thinai', 'success')]
List2 = [('100.20.300.600', 'Ragi', 'Failed')]
table = PrettyTable(['IP', 'Name', 'Result'])
for IP, Name, Result in List1:
table.add_row([IP, Name, Result])
print table
ftable = PrettyTable(['IP', 'Name', 'Result'])
for IP, Name, Result in List2:
ftable.add_row([IP, Name, Result])
print ftable
Above script gave me the result for me. Issue is resolved. Thanks for the support.