基本上,我在一行中有两个字节串,如下所示:
b'\xe0\xa6\xb8\xe0\xa6\x96 - \xe0\xa6\xb6\xe0\xa6\x96\n'
这是一个 Unicode我使用 urllib 从在线文件导入的字符串,我想比较各个字节串,以便我可以替换错误的字节串。但是,我找不到任何方法来解析字符串,以便得到 \xe0\xa6\xb8\xe0\xa6\x96 和 \xe0\xa6\xb6\xe0\xa6\x96 在两个不同的变量中。
我尝试将其转换为原始字符串,如 str(b'\xe0\xa6\xb8\xe0\xa6\x96') 并且索引确实有效,但在那种情况下我不能'首先恢复为原始字节串。
这可能吗?
请您参考如下方法:
我建议尝试这样的事情......
arr = b'\xe0\xa6\xb8\xe0\xa6\x96 - \xe0\xa6\xb6\xe0\xa6\x96\n'
splt = arr.decode().split(' - ')
b_arr1 = splt[0].encode()
b_arr2 = splt[1].encode()
我在 Python 3 终端中试用了它,它工作正常。
