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

Guido van Rossum guido at python.org
Sun Oct 23 18:07:05 CEST 2011


On Sat, Oct 22, 2011 at 11:58 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> Guido van Rossum <guido at python.org> writes:
>
>> On Sat, Oct 22, 2011 at 2:44 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
>> > Guido van Rossum <guido at python.org> writes:
>> >> 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.
>> >
>> > -1. That makes the string representation of an exception much less
>> > useful.
>> >
>> > Exceptions don't have names; each exception *type* has a name, but that
>> > doesn't distinguish instances of the type from one another. When there
>> > is an 'IOError' it's far more useful that the string representation
>> > contains the exception *message*, since the name of the exception type
>> > doesn't tell the user much about what went wrong.
>>
>> You misunderstood me. I'm not proposing to change the str() of an
>> exception *instance*.
>
> That's what I take to be the meaning of “print an exception”. Like
> “print an int” or “print a list”, it seems to me that refers not to a
> type, but to an instance of the type.
>
> Thanks for clarifying that you meant “print an exception class”.

Sorry, reading back what I wrote with less context it's clear how you
could misread it. Since the proposal clearly started out limited to
classes, functions and modules, the ambiguity never occurred to me.

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list