2017-04-13 2 views
0

아래와 같은 오류가 나타납니다. 그것은 공간으로 인해 경로 문제처럼 보입니다.Windows 경로의 공백 문자가 WindowsError : [오류 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)> 
+1

원시 문자열에서 백 슬래시를 두 번 사용하지 마십시오. 단일 백 슬래시에서 원시 문자열을 끝낼 수 없습니다. – eryksun

+0

winreg.exe 또는 reg.exe를 사용하여 경로가 존재하는지 확인한 경우 아마도 32 비트 Python을 사용하고있을 것입니다. 'hKey = OpenKey (HKEY_LOCAL_MACHINE, r "SOFTWARE \ Microsoft \ Windows \ Windows 오류보고 \ LocalDumps", 0, KEY_READ | KEY_WOW64_64KEY)'와 같이 64 비트 키를 명시 적으로 열도록 액세스를 설정하십시오. – eryksun

+1

[왜 파이썬에서 단일 백 슬래시 원시 문자열로 인해 구문 오류가 발생합니까?] (http://stackoverflow.com/questions/30283082/why-does-the-single-backslash-raw-string-in-python -cause-a-syntax-error) –

답변

1

원시 문자열과 이스케이프 백 슬래시를 모두 사용하지 마십시오. 같은 것을 표현하는 두 가지 다른 방법은 "a\\b == r"a\b"입니다.

from _winreg import * 
aReg = ConnectRegistry(None, HKEY_LOCAL_MACHINE) 
hKey = OpenKey(aReg, r'SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps') 

을하지만,이 없기 때문에 내가 먼저 키 LocalDumps를 추가했다 : 그래서, 내 컴퓨터에 하나

r'SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps' 

또는

'SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting\\LocalDumps' 

이 오류없이 작동합니다.

관련 문제