如何使用 python 设置应用程序附加组件的文件夹写入权限
我有 python 脚本,可以正常工作,但仅当作为独立运行时,而我需要它作为脚本。它以这种方式使用外部 .exe 编译的 C 库:
# trigger the shell command
import subprocess
p = subprocess.Popen('qvoronoi TI data.txt TO results.txt p FN Fv QJ', shell=True)
p.wait()
# open the results file and parse results
results = open('results.txt','r')
当我独立运行它时,它工作正常。
但我的程序需要是一个可以在另一个应用程序内部工作的脚本(PTV Visum:http://www.ptvag.com/software/transportation-planning-traffic-engineering/software-system-solutions/visum/)。
当我从那里将其作为脚本运行时,似乎我无法获得写入文件的权限(results.txt)。这就是错误消息:
IOError: [Errno 2] No such file or directory: 'results.txt'
我该如何解决它。
附言。它尝试 os.chmod 更改文件夹权限但没有帮助
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试打印 os.getcwd() 。
您当前的工作目录不是创建
results.txt
的目录。IOError
位于您读取文件的行,而不是写入文件的行,因为您没有指定在哪里查找results.txt
。Try
print os.getcwd()
.Your current working directory is not the directory where
results.txt
is being created.The
IOError
is on the line where you read the file, not write it, because you're not specifying where to look forresults.txt
.