[Python-3000] Thoughts on new I/O library and bytecode

Nick Coghlan ncoghlan at gmail.com
Sun Mar 4 03:24:22 CET 2007


Daniel Stutzbach wrote:
> On 3/3/07, Bob Ippolito <bob at redivi.com> 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   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list