binascii.a2b_binary
Serge Orlov
Serge.Orlov at gmail.com
Mon Apr 3 12:49:10 EDT 2006
Ed Swarthout wrote:
> Why is there no binascii.a2b_binary(bitstr) which returns the binary data
> represented by the bit string? Like:
>
> >>> binascii.a2b_binary('0011001100110101')
> '35'
>
> perl has pack("B*", "0011001100110101");
>
> What is the python way to do this?
to post a question on comp.lang.python and have the code written by
somebody else :)
def a2b_binary(s):
return ''.join(chr(int(s[pos:pos+8],2)) for pos in
range(0,len(s),8))
More information about the Python-list
mailing list