【问题标题】:Access denied in python call在 python 调用中访问被拒绝
【发布时间】:2015-02-27 02:45:47
【问题描述】:

我正在尝试通过 Python 脚本进行 SVN 忽略。

我正在尝试运行如下命令:

call(['"C:\Program Files\TortoiseSVN\bin\svn.exe" propset svn:ignore "C:\dir\file.dcu" "C:\dir"'])

这是我收到的 Python 错误消息:

这是说我无权执行此操作。但是,当我尝试在 CMD.EXE shell 中运行此命令时,一切正常。


编辑

也许这是一个线索,也许我无法逃脱这样的字符

【问题讨论】:

  • 我似乎在 os.system os.system(r'"C:\Program Files\TortoiseSVN\bin\svn.exe" propset svn:ignore "C:\dir\文件.dcu" "C:\dir"')

标签: python svn call


【解决方案1】:

问题是您没有正确处理转义序列。 \b 表示退格字符,\f 表示换页:

>>> '\b'
'\x08'
>>> '\f'
'\x0c'
>>>

这会使您的路径无效。要解决此问题,只需使用raw-string:

call([r'"C:\Program Files\TortoiseSVN\bin\svn.exe" propset svn:ignore "C:\dir\file.dcu" "C:\dir"'])

通过在字符串文字前加上 r 前缀,我们告诉 Python 不要解释转义序列。

【讨论】:

  • 谢谢,好主意,不幸的是这并没有什么不同
猜你喜欢
  • 1970-01-01
  • 2017-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-09
  • 1970-01-01
  • 2015-12-21
  • 1970-01-01
相关资源
最近更新 更多