每行不显示输出

时间:2014-06-28 13:08:11

标签: python multiple-columns

我写了一个简单的python脚本:

#!/usr/bin/python
import sys
import urllib

if len(sys.argv) < 2:
        print 'usage: python %s <file-urls>' % (sys.argv[0])
        sys.exit(2)

print '%-15s %15s' % ('URL_PAGE', 'STATUS')

FileName = sys.argv[1]
InputFile = open(FileName)
for url in InputFile:
    out = urllib.urlopen(url)
    status = out.getcode()
    print '%-15s %15s' % (url, status)

输出是这样的:

URL_PAGE                 STATUS
http://test.com
             200

但我想要这个输出:

URL_PAGE                 STATUS
http://test.com           200

1 个答案:

答案 0 :(得分:2)

strip来自url的换行符(以及无用的空格):

print '%-15s %15s' % (url.strip(), status)