我在列表列表中有一些数据。我试图将它均匀地打印在一个有格式的表格中,但是不同的长度真的把它扔掉了。有没有办法简单地做到这一点?还是我必须做一些尴尬的事情,比如计算每列的最大值并用空格填充其他列?
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'],
['vlan100', '0013.F200.0058', '192.168.110.2']]
for i in table_data:
interface,mac,ip = i
print "Internet {} {:>18s} {:>7s} {:>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.110.2 0013.F200.0058 ARPA vlan100