0
我收到如下所示的错误。由于空间的原因,它看起来像一个路径问题。Windows文件路径获取WindowsError的路径中的空白:[Error 2]
>>> from _winreg import *
>>> aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)
>>> print aReg
<PyHKEY at 03216070 (000001C8)>
>>> hKey = OpenKey(aReg, r"SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting\\LocalDumps")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
WindowsError: [Error 2] The system cannot find the file specified
它正在正确地启动到“Windows”。
>>> hKey = OpenKey(aReg, r"SOFTWARE\\Microsoft\\Windows\\")
>>> print hKey
<PyHKEY at 03216050 (000001A0)>
不要在原始字符串中反斜杠。您不能在单个反斜杠上结束原始字符串。 – eryksun
如果您使用winreg.exe或reg.exe确认路径存在,那么您可能使用的是32位Python。尝试设置访问以明确打开64位密钥:'hKey = OpenKey(HKEY_LOCAL_MACHINE,r“SOFTWARE \ Microsoft \ Windows \ Windows Error Reporting \ LocalDumps”,0,KEY_READ | KEY_WOW64_64KEY)''。 – eryksun
[为什么Python中的单个反斜杠原始字符串会导致语法错误?](http://stackoverflow.com/questions/30283082/why-does-the-single-backslash-raw-string-in-python -cause-A-语法错误) –