Error when running Python file:
SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3:truncated \UXXXXXXXX escape
The reason for this error is the problem of escape
For example, the error path is as follows:
DAQdll = ctypes.windll.LoadLibrary('C:\Users\Python\add.dll')
Cause analysis: in Windows system, you can use \, but in Python string, \ \ has the meaning of escape. For example, \ \ T represents tab, and \ \% n represents newline. Therefore, you need to take some measures to prevent \ \% from being interpreted as escape character. There are currently three solutions
1. Add r in front of the path to keep the original value of the character
DAQdll = ctypes.windll.LoadLibrary(r'C:\Users\Python\add.dll')
2. Replace with double backslashes
DAQdll = ctypes.windll.LoadLibrary('C:\\Users\\Python\\add.dll')
3. Replace with forward slash
DAQdll = ctypes.windll.LoadLibrary('C:/Users/Python/add.dll')
Similar Posts:
- Python Files Error: SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: tr
- Python Open File SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in …
- [Solved] json.decoder.JSONDecodeError: Expecting ‘,‘ delimiter: line xx column xx (char xxx)
- [Solved] SyntaxError: unexpected character after line continuation character
- [Solved] SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position …
- [Solved] Expected linebreaks to be ‘LF’ but found ‘CRLF’.
- Android System.Load vs System.LoadLibrary
- One line command / usr / bin / Perl ^ m: bad interpreter
- MySQL: invisible empty symbol char (9) char (10) char (13)
- [How to Solve Error] warning: LF will be replaced by CRLF in README.md.