【发布时间】:2015-04-15 17:54:48
【问题描述】:
我已经尝试了很多不同的方法来实现这一点,只是我想要这个:
import requests
path1 = 'D:\test\Files\/results.txt'
lines1 = open(path1).readlines()
ctr = 0
for i in lines1:
try:
r = requests.get(i)
if r.status_code != 200:
ctr += 1
print(i, " Status Code: ", r.status_code)
except requests.ConnectionError:
ctr += 1
print(i, " Failed to connect")
print("Counter", ctr)
这样输出:
URL Status Code: xyz
但我得到的是:
URL
Status Code: xyz
那么,用 Python 打印出同一行中的内容的最佳方法是什么?
【问题讨论】:
-
相信我,我已经试过了。不工作
-
Python 3.x 还是 Python 2.7.X?
-
'这是 Python 版本 3.4.3'
-
i = 文件中的 URL。
-
只看
i的内容就会告诉你是什么导致了问题。 . .
标签: python