Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't you xor bytes objects in python?

I think I understand python bytes objects, but supporting bitwise operations on byte strings seems like such an obvious feature. I don't understand why it is not supported.

>>>'abcdefg'.encode('ascii')
b'abcdefg'

Okay. I went from a string to something like the byte representation of my string in ascii.

So when I try:

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

Why? Why doesn't python support this? Is there something I don't understand about bytes objects that makes this unfeasible or ambiguous?

like image 318
cowlicks Avatar asked Sep 18 '15 18:09

cowlicks


1 Answers

This feature has been proposed on the python bug tracker. And there is proposed patch (which I wrote after being annoyed by this). But the current feedback is negative, and more is needed if it is to be included.

like image 99
cowlicks Avatar answered Sep 20 '22 16:09

cowlicks