【问题标题】:When attempting run a python script from within another python script, I get 'permission denied'!尝试从另一个 python 脚本中运行 python 脚本时,我得到“权限被拒绝”!
【发布时间】:2015-05-20 07:25:37
【问题描述】:

所以,我正在编写一个 python 脚本,它会在脚本开头自动下载更新。好的,那么?因此,当我尝试覆盖它时,它会使用 CodeRunner 2.0.2、IDLE 2.7.9 和 PythonLauncher 给我sh: /Users/<user>/Desktop/<scriptname>.py: Permission denied。这是受影响的代码段:

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时我觉得很奇怪,这意味着它可能一直在尝试同时读取和写入,更不用说它工作得很好,然后突然失败了。

【问题讨论】:

    标签: python python-2.7 download sh permission-denied


    【解决方案1】:

    os.system(cmd) 将调用[current directory]/&lt;scriptname&gt;/py

    不要直接调用脚本(它可能无法执行),而是将其传递给 Python:

    cwd = os.path.join(os.getcwd(), "<scriptname>.py")
    ...
    os.system('{} {}'.format('python', cmd))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-24
      • 1970-01-01
      • 2019-02-07
      • 1970-01-01
      • 1970-01-01
      • 2018-12-25
      • 2013-07-08
      • 1970-01-01
      相关资源
      最近更新 更多