我正在使用Arch Linux.我想做同样的事情apt-get source coreutils; 可以用Pacman下载资源吗?我没有在手册页中找到解决方案.
如何获取包的源代码?
在python2中,有string-escape和unicode-escape.对于utf-8字节字符串,string-escape可以转义\并保留非ascii字节,如:
"??\\n".decode('string-escape')
'\xe4\xbd\xa0\xe5\xa5\xbd\n'
Run Code Online (Sandbox Code Playgroud)
但是,在python3中,string-escape被删除.我们必须将字符串编码为字节并使用以下方法解码unicode-escape:
"This\\n".encode('utf_8').decode('unicode_escape')
'This\n'
Run Code Online (Sandbox Code Playgroud)
它适用于ascii字节.但是非ascii字节也将被转义:
"??\\n".encode('utf_8')
b'\xe4\xbd\xa0\xe5\xa5\xbd\\n'
"??\\n".encode('utf_8').decode('unicode_escape').encode('utf_8')
b'\xc3\xa4\xc2\xbd\xc2\xa0\xc3\xa5\xc2\xa5\xc2\xbd\n'
Run Code Online (Sandbox Code Playgroud)
所有非ascii字节都被转义,这会导致编码错误.
那么有解决方案吗?在python3中是否可以保留所有非ascii字节并解码所有转义字符?