如何使用 python 设置应用程序附加组件的文件夹写入权限

发布于 2024-11-30 05:37:44 字数 834 浏览 0 评论 0 原文

我有 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 更改文件夹权限但没有帮助

I have python script that works fine but only when run as stand-alone, while I need it as a script. It uses external .exe compiled C library in such manner:

# 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')

It works all right when I run it as stand-alone.

But my program needs to be a script that works from inside another application (PTV Visum: http://www.ptvag.com/software/transportation-planning-traffic-engineering/software-system-solutions/visum/).

When I run it as a script from there it seems I cannot get permissions to write files (results.txt). Thats the error message:

IOError: [Errno 2] No such file or directory: 'results.txt'

How can I solve it.

PS. It tried os.chmod to change folder permissions but It didnt help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两仪 2024-12-07 05:37:44

尝试打印 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 for results.txt.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文