sách gpt4 ăn đã đi

python :转义 "\xXX"

In lại 作者:太空狗 更新时间:2023-10-29 17:26:42 31 4
mua khóa gpt4 giày nike

我有一个带有转义数据sợi dây

escaped_data = '\\x50\\x51'
print escaped_data # gives '\x50\x51'

什么 Python 函数会对其进行反转义以便我得到

raw_data = unescape( escaped_data)
print raw_data # would print "PQ"

câu trả lời hay nhất

Bạn có thể sử dụngstring-escape 进行解码。

>>> escaped_data = '\\x50\\x51'
>>> escaped_data.decode('string-escape')
'PQ'

hiện hữuPython 3.0KHÔNG string-escape,但您可以使用 unicode_escape

từ byte 对象:

>>> escaped_data = b'\\x50\\x51'
>>> escaped_data.decode("unicode_escape")
'PQ'

来自 Unicode đường 对象:

>>> import codecs
>>> escaped_data = '\\x50\\x51'
>>> codecs.decode(escaped_data, "unicode_escape")
'PQ'

关于 python :转义 "\xXX",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10944907/

31 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress