小编Nin*_*Sun的帖子

如何在Arch Linux上使用Pacman下载源代码?

我正在使用Arch Linux.我想做同样的事情apt-get source coreutils; 可以用Pacman下载资源吗?我没有在手册页中找到解决方案.

如何获取包的源代码?

archlinux

40
推荐指数
2
解决办法
3万
查看次数

python3 unicode-escape不能用于非ascii字节?

在python2中,有string-escapeunicode-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字节并解码所有转义字符?

python python-3.x

11
推荐指数
1
解决办法
3013
查看次数

标签 统计

archlinux ×1

python ×1

python-3.x ×1