我想导入 d:\pyusb-1.0.0a2\usb 中的 pyusb 库的一个模块。所以首先我必须将它的路径添加到 sys.path
。但我收到以下错误。
注意:我可以成功导入 d:\pyusb-1.0.0a2
!!!
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import sys
>>> sys.path.append('d:\pyusb-1.0.0a2\usb')
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 16-17: truncated \uXXXX escape
最佳答案
你需要使用原始字符串
>>> sys.path.append(r'd:\pyusb-1.0.0a2\usb')
或者转义反斜杠
>>> sys.path.append('d:\\pyusb-1.0.0a2\\usb')
或使用正斜杠
>>> sys.path.append('d:/pyusb-1.0.0a2/usb')
否则,Python 将尝试将 \usb
解释为 Unicode 转义序列(如 \uBEEF
),但由于显而易见的原因而失败。
关于python - (unicode 错误) 'unicodeescape' 编解码器无法解码位置 16-17 : truncated\uXXXX escape 中的字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25608450/