我创建了一个脚本,该脚本将比较负载平衡服务器的文件,并将其与迁移服务器的文件进行比较,以找到需要新的负载平衡配置的文件。我将脚本打印到输出文件,但所有IP地址都捆在一起。我尝试了" n",但是我收到了错误消息'f.writelines(lb_servers,' n')我给了一个参数。
with open('output.txt', 'w') as f:
ME06 = set(open("LB_server_IP.txt").read().split())
lb = set(open('mig_svrip.txt').read().split())
LB_Servers = ME06.intersection(lb)
uniques = ME06.difference(lb).union(lb.difference(ME06))
print(len(LB_Servers), (LB_Servers,))
f.writelines(LB_Servers, 'n')
在Python3中,您可以将打印功能的输出重定向到文件:
for server in LB_Servers:
print(server, file=f)