On Wed, May 28, 2008 at 5:12 AM, Jim Jewett <[EMAIL PROTECTED]> wrote:
>>  >>  - Add ``'%a'`` string format operator. ``'%a'`` converts any python
>>  >>   object to string using ``repr()`` and then hex-escape all non-ASCII
>>  >>   characters. ``'%a'`` operator generates same string as ``'%r'`` in
>>  >>   Python 2.
>
>>  > Then why not keep the old %r, and add a new one for the unicode repr?
>
>> repr() and "%r" should be consistent with object's __repr()__ function.
>
> Let me rephrase that:
>
> Why change repr and add a replacement that acts like old repr?

The "%r" and ascii() are not in my original proposal, but proposed in
this discussion. I added them to the PEP, but still I'm not sure they
are neccesary.

>
> Wouldn't it be easier to just add a new function (and format
> character) that act in the desirable new way?  That way there are no
> backwards compatibility problems, and people who use it will make an
> explicit choice that can be trusted.

Adding a new function is not enough, but we should define new protocol
to types such as __unicode_repr__() and implement them . For example,
the list type should implement a method which does almost same job as
__repr__().

class List:
   def __repr__(self):
       return "[%s]" % ",".join(repr(s) for s in self._items)

   def __unicode_repr__(self):
       return "[%s]" % ",".join(unicode_repr(s) for s in self._items)

I think keeping old repr() is not worth this effort.

> What I really want is that the
>
>    "No str?  Use repr instead"
>
> fallback change into
>
> "No str?  Use repr on *this* object instead, but keep using str on
> subobjects if those are printed"
>

Even If Python changed to call str() on subobjects as you want, I'll
still insist on PEP 3138. Printing result of str() is not always
relevant to debugging, and repr() is designed for debugging. str() can
not be a replacement for repr().
_______________________________________________
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

Reply via email to