当尝试从另一个 python 脚本中 运行 一个 python 脚本时,我得到 'permission denied'!
When attempting run a python script from within another python script, I get 'permission denied'!
所以,我写了一个 python 脚本,它会在脚本开头自动下载更新。好的,所以?因此,当我尝试覆盖它时,它给我 sh: /Users/<user>/Desktop/<scriptname>.py: Permission denied
使用 CodeRunner 2.0.2、IDLE 2.7.9 和 PythonLauncher。这是受影响的代码片段:
cwd = os.getcwd()
cwd = (str(cwd) + "/<scriptname>.py")
update = urllib.URLopener()
cwd = str(cwd)
print "Downloading Update..."
update.retrieve("http://<site_domain>/<scriptname>.py",cwd)
time.sleep(1.25)
print "Update Dowloaded! Please Wait..."
time.sleep(2.5)
os.system(cwd)
我发现这很奇怪,因为人们说它应该覆盖没问题,但是,当没有兄弟 .pyc
时我发现它很奇怪,这意味着它可能一直在尝试同时读取和写入, 更不用说它工作得很好,然后突然就崩溃了。
os.system(cmd)
会调用 [current directory]/<scriptname>/py
.
不要直接调用脚本(它可能无法执行),而是将其传递给 Python:
cwd = os.path.join(os.getcwd(), "<scriptname>.py")
...
os.system('{} {}'.format('python', cmd))
所以,我写了一个 python 脚本,它会在脚本开头自动下载更新。好的,所以?因此,当我尝试覆盖它时,它给我 sh: /Users/<user>/Desktop/<scriptname>.py: Permission denied
使用 CodeRunner 2.0.2、IDLE 2.7.9 和 PythonLauncher。这是受影响的代码片段:
cwd = os.getcwd()
cwd = (str(cwd) + "/<scriptname>.py")
update = urllib.URLopener()
cwd = str(cwd)
print "Downloading Update..."
update.retrieve("http://<site_domain>/<scriptname>.py",cwd)
time.sleep(1.25)
print "Update Dowloaded! Please Wait..."
time.sleep(2.5)
os.system(cwd)
我发现这很奇怪,因为人们说它应该覆盖没问题,但是,当没有兄弟 .pyc
时我发现它很奇怪,这意味着它可能一直在尝试同时读取和写入, 更不用说它工作得很好,然后突然就崩溃了。
os.system(cmd)
会调用 [current directory]/<scriptname>/py
.
不要直接调用脚本(它可能无法执行),而是将其传递给 Python:
cwd = os.path.join(os.getcwd(), "<scriptname>.py")
...
os.system('{} {}'.format('python', cmd))