我正在尝试用python程序编写一个文件。当我执行所有动作命令行时,它们都可以正常工作。该文件已创建。 当我在python脚本中执行操作时,脚本终止后该文件不存在。 我创建了一个演示行为的小脚本。
import os
import os.path
current_dir = os.getcwd()
output_file = os.path.join(current_dir, "locations.js")
print output_file
f = open(output_file, "w")
f.write("var locations = [")
f.write("{lat: 55.978467, lng: 9.863467}")
f.write("]")
f.close()
if os.path.isfile(output_file):
print output_file + " exists"
exit()
从命令行运行脚本,我得到以下结果:
D:\Temp\GeoMap>python test.py
D:\Temp\GeoMap\locations.js
D:\Temp\GeoMap\locations.js exists
D:\Temp\GeoMap>dir locations.js
Volume in drive D is Data
Volume Serial Number is 0EBF-9720
Directory of D:\Temp\GeoMap
File Not Found
D:\Temp\GeoMap>
因此,文件实际上已创建,但在脚本终止时被删除。
保存文件需要做什么?
答案 0 :(得分:0)
通过更改防火墙设置解决了问题。