[英]DISCORD // 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
I'm trying to open discord with this script我正在尝试使用此脚本打开不和谐
import subprocess
subprocess.call(['C:\Users\xerxe\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Discord Inc\\Discord.exe'])
but only get this this error但只会得到这个错误
'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
The \\
character is an escape character - \\n
means a newline character, \\t
is a tab character, etc. \\U
is used to denote the beginning of a Unicode escape sequence, like \\U000145d3
, where the 8 chars following \\U
are hex digits ( 0-9a-f
). \\
字符是转义字符 - \\n
表示换行符, \\t
是制表符等。 \\U
用于表示 Unicode 转义序列的开头,例如\\U000145d3
,其中\\U
后面的 8 个字符是十六进制数字 ( 0-9a-f
)。 Since \\Users\\xer
is not a valid Unicode escape sequence, you got an error.由于\\Users\\xer
不是有效的 Unicode 转义序列,因此您会收到错误消息。 For Windows paths, you either need to escape the escape character:对于 Windows 路径,您需要对转义字符进行转义:
subprocess.call(['C:\\Users\\xerxe\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Discord Inc\\Discord.exe'])
use a raw string literal (note the r
just before the opening '
):使用原始字符串文字(注意开头'
之前的r
):
subprocess.call([r'C:\Users\xerxe\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Discord Inc\Discord.exe'])
or use /
characters as path delimiters:或使用/
字符作为路径分隔符:
subprocess.call(['C:/Users/xerxe/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Discord Inc/Discord.exe'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.