Éric Araujo <mer...@netwok.org> added the comment:

Suggestion by Guido on #868845:

> I sometimes wish that the str() of a class would return the class name
> rather than its repr(); that way "print(str)" would print "str"
> instead of <class 'str'>.  (Use case: printing an exception and its
> message: I wish I could print("%s: %s" % (err.__class__, err)) instead
> of having to use err.__class__.__name__.)

I wrote a simple patch for that.  I just copied the definition of type_repr to 
a new type_str function, edited the format strings and updated the member 
mapping (I checked in another file than casting to reprfunc is okay for a str 
func).  It compiles and runs just fine, but I’m still learning C, so there may 
be things I’ve missed: I don’t know if I have to declare the new function or 
something like that.  The test suite passes with very few edits.


Guido added this:
> One could even claim that the repr() of a class could be the same
I for one think of repr first as “string form for debugging”, so I like the 
angle brackets.  My patch leaves __repr__ alone.


If this get approved, I’ll update my patch with doc changes.  If there is no 
feedback I’ll go to python-ideas.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13224>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to