为什么你不能在 python 中对字节对象进行异或?

cow*_*cks 7 python byte bit-manipulation bytearray bitwise-xor

我想我了解 python 字节对象,但支持字节字符串的按位操作似乎是一个如此明显的功能。我不明白为什么它不受支持。

>>>'abcdefg'.encode('ascii')
b'abcdefg'
Run Code Online (Sandbox Code Playgroud)

好的。我从一个字符串变成了像我的字符串在 ascii 中的字节表示。

所以当我尝试:

>>> a = 'abcdefg'.encode('ascii')
>>> a ^ a
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for ^: 'bytes' and 'bytes'
Run Code Online (Sandbox Code Playgroud)

为什么?为什么python不支持这个?关于字节对象,我有什么不明白的地方使这不可行或不明确吗?

cow*_*cks 5

此功能已在 python 错误跟踪器上提出。并且有提议的补丁(这是我在对此感到恼火后写的)。但目前的反馈是负面的,如果要包括在内,还需要更多。