使用文件路径而不会出现 utf5 错误

Using filepath without getting utf5 error

以下代码行生成 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 57-58: malformed \N character escape:

self.le1 = QLineEdit('\S24014\file.xlsx', self)

这是我需要保留的文件路径。 Spyder 表明 \S24014 是问题所在。该文件的顶部有 # -*- coding: utf-8 -*-。如何解决问题?

我将 Spyder 2 与 Python 3.5 和 PyQt4

一起使用

听起来好像您需要将字符串作为 raw string literal 传递,即 r'\S24014\file.xlsx.

Both string and bytes literals may optionally be prefixed with a letter r or R; such strings are called raw strings and treat backslashes as literal characters.