[Python-ideas] bitwise operations on bytes

Guido van Rossum guido at python.org
Sun Aug 9 00:27:46 CEST 2009


I think it's a very rarely used feature that is more likely to baffle
the casual reader. The question of what to do with byte strings of
unequal length is just the first issue that crops up. The (still
legitimate) question why we would support | and & but not << and >> is
another.

It's a slippery slope...

--Guido

On Sat, Aug 8, 2009 at 3:09 PM, Georg Brandl<g.brandl at gmx.net> wrote:
> Guido van Rossum schrieb:
>
>> In the grander scheme of things, I worry that interpreting byte
>> strings as integers and implementing bitwise operators on them is
>> going to cause more confusion and isn't generally useful enough to
>> warrant the extra code.
>
> What about operations that don't require the bytes to be interpreted
> as anything else?
>
> The OP proposed
>
> bytes_a | bytes_b
>
> to mean
>
> bytes(b_a | b_b for (b_a, b_b) in zip(bytes_a, bytes_b))
>
> except that (probably) an equal length would have to be asserted.
>
> Georg
>
> --
> Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
> Four shall be the number of spaces thou shalt indent, and the number of thy
> indenting shall be four. Eight shalt thou not indent, nor either indent thou
> two, excepting that thou then proceed to four. Tabs are right out.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-ideas mailing list