我学习了下面的代码,它通过从我的列表.txt“文件,现在我正在寻找一种方法来打印输出,在每个输出的顶部都有一个非常人性化的from Like列标题,然后是名称(在下面)。。在
有没有办法在打印时设置列宽。。。在
#!/usr/bin/python
import sys
import socket
with open("mylabList.txt", 'r') as f:
for host in f:
print("{0[0]}\t{0[2][0]}".format(socket.gethostbyname_ex(host.rstrip())))
电流输出如下:
^{pr2}$预期产量为:
Server Name IP ADDRESS
===================================
mylab1.example.com 172.10.1.1
mylab2.example.com 172.10.1.2
mylab3.example.com 172.10.1.3
mylab4.example.com 122.10.1.4
只是个便条。。在我的输出中,Srever Name的lenghth最长可达30个字符。在
你可以用ljust和rjust
http://www.tutorialspoint.com/python/string_ljust.htmhttp://www.tutorialspoint.com/python/string_rjust.htm
结果
^{pr2}$这是一种可能的方法:
相关问题 更多 >
编程相关推荐