[Python-ideas] Changing str(someclass) to return only the class name

Georg Brandl g.brandl at gmx.net
Sat Oct 22 23:27:39 CEST 2011

On 10/22/11 22:32, Guido van Rossum wrote:

> Thinking of str(x) as an API to get a certain value would lead there,
> yes. But thinking of str(x) as what gets printed by print(x),
> formatted by "{}.format(x)", and "%s" % s, changes things. When I am
> printing an object and I have no idea what type it is, I'll use repr()
> or "%r"; but when I know I am printing, say, an exception, I think it
> would be very nice if print(x) would just print its name. Just like
> print(None) prints 'None', it would make all the sense in the world if
> print(ZeroDivisionError) printed 'ZeroDivisionError', and
> print(type(42)) printed 'int'.



More information about the Python-ideas mailing list