因此,我正在编写一个 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 - 当尝试从另一个 python 脚本中运行 python 脚本时,我得到 'permission denied' !,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29106339/