【发布时间】:2011-08-16 12:57:55
【问题描述】:
我有一个运行良好的 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'
我该如何解决。
PS。它尝试 os.chmod 更改文件夹权限,但没有帮助
【问题讨论】:
-
@agf 你是对的。无论如何这很奇怪,当我将它作为独立的
os.getcwd()运行时,在整个过程中都是正确的。但是当我将它用作脚本时,os.getcwd()在我开始监控它时是正确的,但之后有所不同......无论如何我使用:os.chdir(good_cwd)并且它工作正常
标签: python permissions path