Daniel Stutzbach wrote: > On 3/3/07, Bob Ippolito <[EMAIL PROTECTED]> wrote: >> When Erlang is printing the "repr" of a list or binary term to the >> shell it first checks to see if every item is printable ASCII integer. >> If so, then it prints as an ASCII string. Otherwise, it prints as a >> list of decimal integers. It doesn't work out well in these kinds of >> situations. If it was printed out as ASCII with hex escapes then it >> would make a lot more sense at a glance. > > Perhaps it would be best to make one format the default, but provide a > convenience method on the bytes type for the other format? > > repr(b) -> bytes("spam spam spam")' > b.hex() -> "7370616d 20737061 6d207370 616d"
The hex() method isn't implemented yet, but a really simple listcomp/gencomp already gives the 'list of integers' format: >>> data = b"what's in a name?" >>> repr(data) "b'what\\'s in a name?'" >>> [x for x in data] [119, 104, 97, 116, 39, 115, 32, 105, 110, 32, 97, 32, 110, 97, 109, 101, 63] Given the simplicity of retrieving the underlying integers, I think the string representation makes a good default repr implementation. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com