【发布时间】:2019-03-07 10:51:17
【问题描述】:
trhe 代码从 txt 中获取 IP 地址。当服务器在线时写入新的txt文件。但是这段代码只写了txt文件中的最后一个文件。而且永远不会有时间进入else。我需要帮助
tahnks
import os
file = open("IPs.txt","r+")
with open("IPs.txt","r") as file:
for line in file:
response = os.system("ping " + line)
if response == 0:
with open("IPsCheck.txt","w") as file:
print(line)
file.write(line)
else:
print("server not available ")
【问题讨论】:
标签: python operating-system ping