[Python-Dev] bin codec + EOF (original) (raw)

tomer filiba tomerfiliba at gmail.com
Fri Apr 21 10:34:44 CEST 2006


yeah, i came to realize nothing helpful will ever come out from this list, so i might as well stop trying. but i have one last thing to try.

i'm really missing a binary codec, just like the hex codec, for doing things like

"abc".encode("bin") "011000010110001001100011" "011000010110001001100011".decode("bin") "abc"

decode should also support padding, either None, "left", or "right", i.e.,

"1".decode("bin") # error "1".decode("bin", "left) # 00000001 '\x01' '1'.decode("bin", "right") # 10000000 '\x80'

i've written a codec by myself for that, it's not that complicated, but the problem is, because it's not in the standard encodings package, i can't distribute code that uses it easily:

so i resorted to an encode_bin and decode_bin functions that are included with my code. of course this codec should be written in c to make it faster, as it's quite a bottleneck in my code currently.

it's a trivial and useful codec that should be included in the stdlib. saying "you can write it for yourself" is true, but the same came be said about "hex", which can even be written as a one-liner: "".join("%02x" % (ord(ch),) for ch in "abc")

so now that it's said, feel free to (-1) it by the millions. don't worry, i will not waste my or your time anymore.

-tomer -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-dev/attachments/20060421/5772205f/attachment.htm



More information about the Python-Dev mailing list