Re: python3 binascii.hexlify ...
Cameron Simpson wrote: This seems to return a bytes object in Python 3.3.0. I was expecting a string. The documentation here: http://docs.python.org/3/library/binascii.html#binascii.hexlify also keeps me expecting a string. Am I missing something? Return the hexadecimal representation of the binary data. Every byte of data is converted into the corresponding 2-digit hex representation. makes it pretty clear that the function is operating on bytes, not str. The following sentence The resulting string... is likely a leftover from Python 2 and should be fixed. If you need str instead of bytes it's easy enough to do the encoding/decoding yourself: import binascii as ba ba.hexlify(äöü.encode()) b'c3a4c3b6c3bc' ba.unhexlify(_).decode() 'äöü' -- http://mail.python.org/mailman/listinfo/python-list
Re: python3 binascii.hexlify ...
On Sat, Feb 9, 2013 at 10:10 PM, Peter Otten __pete...@web.de wrote: Return the hexadecimal representation of the binary data. Every byte of data is converted into the corresponding 2-digit hex representation. makes it pretty clear that the function is operating on bytes, not str. That doesn't necessarily mean it has to return bytes, though. It's taking binary data and producing something that's plausibly either bytes or str. It's human-readable and would definitely make sense to be str (for instance, hex() returns a str), so imo this should be made very clear in the docs. Maybe: Return the hexadecimal representation of the binary data. Every byte of data is converted into two bytes with the corresponding hex representation in ASCII. or somesuch? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: python3 binascii.hexlify ...
On 09Feb2013 22:26, Chris Angelico ros...@gmail.com wrote: | On Sat, Feb 9, 2013 at 10:10 PM, Peter Otten __pete...@web.de wrote: | Return the hexadecimal representation of the binary data. Every byte of | data is converted into the corresponding 2-digit hex representation. | | | makes it pretty clear that the function is operating on bytes, not str. Well of course. I want a hexadecimal string representation of a chunk of bytes. It should be producing a string. | That doesn't necessarily mean it has to return bytes, though. It's | taking binary data and producing something that's plausibly either | bytes or str. It's human-readable and would definitely make sense to | be str (for instance, hex() returns a str), so imo this should be made | very clear in the docs. Maybe: | | Return the hexadecimal representation of the binary data. Every byte of | data is converted into two bytes with the corresponding hex | representation in ASCII. | | | or somesuch? Only if returning a string would break something relying on hexlify returning bytes. The natural way to write this function is to have it return a string. _If_ there's some dependency in the stdlib, maybe a doc fix would do. But otherwise IMO the function should be returning a string. What is the use case for returning bytes that just _look_ like a string? It is returning a textual representation; without a good reason, that should be a string. -- Cameron Simpson c...@zip.com.au Because of its special customs, crossposting between alt.peeves and normal newsgroups is discouraged. - Cameron Spitzer -- http://mail.python.org/mailman/listinfo/python-list