new bitwise module [was Re: Discussion: new operators ...]

Huaiyu Zhu hzhu at localhost.localdomain
Mon Jul 31 13:34:42 EDT 2000


On Mon, 31 Jul 2000 11:43:14 +0200, Alex Martelli <alex at magenta.com> wrote:
[snip]
>
>And I like your solution of finessing this via names bitor, bitand, etc.
>This
>also makes it sensible to 'from bitwise import *' in a module that does
>heavy bitwise processing.

That's what I had in mind.  Thanks for reminding me of shifts and reserved
words. 

>> >The 'bitwise' module could supply easily explicit bitfield-extraction
>> >in place of the mask-and-shift idioms, too.
>
>E.g., with your current prototype, bitget, bitset, and bitflip, for
>single-bit
>operations, and bitfieldget, bitfieldset, maybe bitfieldoperate for
>multi-bit
>fields operations.  You could see the purpose of this as 'marketing' -- an
>attempt to make the new module more popular, by having it provide a
>little useful extra prepackaged-functionality, that is often welcome in
>program segments that do work with bitfields.

Excellent.  So let's put them in.  I don't know what they do as I don't use
bitwise operations, but I suppose they are simple to write on top of current
bitwise operators.  Would you do it?

[snip]
>
>Maybe it could get into the Standard Distribution, and it would be trivial
>to supply a C implementation of course (cBitfield perhaps?).  No way to
>take away | & << >> ~ until Python 3000, of course, but, yes, surely when
>3000's time comes life will be easier if bitwise is the popular way to do
>things and the linenoise alternative an old/legacy/deprecated one:-).

That's the idea.  So let's have it.   That would make adding new math
operators a little easier to swallow as well. :-)

Huaiyu



More information about the Python-list mailing list