[Python-3000] Fwd: UPDATED: PEP 3138- String representation in Python 3000 (original) (raw)
Atsuo Ishimoto ishimoto at gembook.org
Thu May 29 08:40:50 CEST 2008
- Previous message: [Python-3000] Fwd: UPDATED: PEP 3138- String representation in Python 3000
- Next message: [Python-3000] Fwd: UPDATED: PEP 3138- String representation in Python 3000
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, May 28, 2008 at 5:12 AM, Jim Jewett <jimjjewett at gmail.com> wrote:
>> - Add
'%a'
string format operator.'%a'
converts any python >> object to string usingrepr()
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().
- Previous message: [Python-3000] Fwd: UPDATED: PEP 3138- String representation in Python 3000
- Next message: [Python-3000] Fwd: UPDATED: PEP 3138- String representation in Python 3000
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]