将变量中的值打印为三列

2024-05-21 00:45:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我有三个变量保存数据,我想把它打印成三列。数据目前是这样保存的: [“VLAN0001”,“VLAN0005”,“VLAN0006”,“VLAN0007”,“VLAN0009”,“VLAN0010”,“VLAN0020”,“VLAN0022”,“VLAN0025”,“VLAN0026”,“VLAN0027”,“VLAN0029”,“VLAN0036”,“VLAN0037”,“VLAN0039”,“VLAN0040”,“VLAN0042”,“VLAN0043”,“VLAN0046”,“VLAN0047”,“VLAN0050”,“VLAN0051”,“VLAN0055”,“VLAN0056”,“VLAN0058”,“VLAN0059”,“VLAN0060”,“VLAN0064”、“VLAN0066”、“VLAN0068”、“VLAN0072”、“VLAN0074”、“VLAN0075”、“VLAN0077”、“VLAN0080”、“VLAN0090”、“VLAN0100”、“VLAN0101”、“VLAN0102”、“VLAN0103”、“VLAN0104”、“VLAN0105”、“VLAN0106”、“VLAN0107”、“VLAN0108”、“VLAN0109”、“VLAN0110”、“VLAN0111”、“VLAN0112”、“VLAN0116”、“VLAN0118”、“VLAN0143”、“VLAN0170”、“VLAN0198”、“VLAN0201”,'VLAN0202','VLAN0203','VLAN0204','VLAN0205','VLAN0206','VLAN0207','VLAN0210','VLAN0299','VLAN0801','VLAN0802','VLAN0803','VLAN0899','VLAN0900','VLAN0901','VLAN0902','VLAN0903','VLAN0904','VLAN0999'] ['GigabitEthernet9/11\r'、'GigabitEthernet9/11\r'、'GigabitEthernet9/11\r'、'GigabitEthernet9/15\r'、'GigabitEthernet9/15\r'、'Port-channel1\r'、'GigabitEthernet9/19\r'、'Port-channel1\r'、'Port-channel1\r'、'GigabitEthernet12/1\r'、'Port-channel1\r'、'Port-channel1\r'、'Port-channel16\r'、'Port-channel1\r','Port-channel1\r'、'gigabitehernet9/29\r'、'gigabitehernet9/29\r'、'gigabitehernet9/29\r'、'gigabitehernet9/10\r'、'Port-channel1\r'、'Port-channel1\r'、'Port-channel16\r'、'Port-channel1\r'、'gigabitehernet9/23\r'、'gigabitehernet12/1\r'、'Port-channel1\r'、'Port-channel1\r'、'Port-channel16\r'、'Port-channel14\r','Port-channel1\r'、'Port-channel16\r'、'Port-channel3\r'、'Port-channel14\r'、'Port-channel1\r'、'Port-channel14\r'、'Port-channel1\r'、'gigabit以太网9/17\r'、'gigabit以太网9/2\r'、'gigabit以太网9/3\r'、'Port-channel1\r'、'gigabit以太网9/6\r'、'Port-channel1\r'、'gigabit以太网9/8\r'、'gigabit以太网9/10\r','千兆以太网9/13\r'、'千兆以太网9/29\r'、'千兆以太网9/15\r'、'千兆以太网9/16\r'、'千兆以太网9/27\r'、'千兆以太网9/17\r'、'千兆以太网9/29\r'、'端口通道1\r'、'端口通道16\r'、'端口通道1\r'、'千兆以太网9/17\r'、'千兆以太网9/18\r'、'千兆以太网9/19\r'、'千兆以太网9/24\r','Port-channel1\r'、'GigabitEthernet9/23\r'、'Port-channel1\r'、'Port-channel1\r'、'Port-channel1\r'、'Port-channel1\r'、'Port-channel1\r'、'Port-channel1\r'、'Port-channel1\r'、'Port-channel1\r'、'Port-channel1\r'、'Port-channel1\r'、'Port-channel1\r'、'Port-channel1\r'] ['1d04h','1d04h','1d04h','1d04h','1w0d','1w0d','5w5d','3w3d','12w6d','4w3d','1w0d','30w3d','17w3d','30w3d','3w6d','2w6d','4d00h','12w6d','12w6d','12w6d','4d01h','1w0d','30w3d','2w0d','17w3d','12w6d']

我希望它像这样出现: ('VLAN0001','GigabitEthernet9/11\r','1d04h')

我是用itertools.izip来做的,但是在输入了大约20个条目之后,它就最大化了,并没有显示所有的数据。有什么建议可以解决这个问题吗


Tags: 数据端口portchannel1vlan0005vlan0007gigabitvlan0009
1条回答
网友
1楼 · 发布于 2024-05-21 00:45:58

试试内置的^{}。如果您的列表是ABC,那么:

rows = zip(A, B, C)

这样,您就可以使用for循环打印:

for row in rows:
    print row  # ('VLAN0001', 'GigabitEthernet9/11\r', ' 1d04h')
    # or you can format somehow:
    "%s %s %s" % row  # Change the formatting codes as you please
    "{0:s} {1:s} {2:s}".format(*row)  # or use new-style formatting

相关问题 更多 >