我正在尝试将列表列表格式化为表格。它主要工作,但如果一个元素太长,它似乎打破了桌子。知道为什么会发生这种情况或如何使用此方法确保此处的表格格式正确吗?
table_data = [['vlan1', '0013.F200.0058', '192.168.2.2'],
['vlan20', '0013.F200.0058', '192.168.30.2'],
['vlan20', '0010.600a.7026', '192.168.30.4'],
['vlan20', '70ca.9b99.6a82', '192.168.30.1'],
['vlan21', '0013.F200.0058', '192.168.222.222'],
['vlan100', '0013.F200.0058', '192.168.110.2'],
['vlan2100', '0013.F200.0058', '192.168.222.223']]
for i in table_data:
interface,mac,ip = i
print "Internet {}\t {:>18s}\t{:>7s}\t {:<8s}".format(ip, mac,'ARPA' ,interface)
Protocol Address Hardware Addr Type Interface
-------- ------- ------------- ---- ---------
Internet 192.168.2.2 0013.F200.0058 ARPA vlan1
Internet 192.168.30.2 0013.F200.0058 ARPA vlan20
Internet 192.168.30.4 0010.600a.7026 ARPA vlan20
Internet 192.168.30.1 70ca.9b99.6a82 ARPA vlan20
Internet 192.168.222.222 0013.F200.0058 ARPA vlan21
Internet 192.168.110.2 0013.F200.0058 ARPA vlan100
Internet 192.168.222.223 0013.F200.0058 ARPA vlan2100