[Python-ideas] Changing str(someclass) to return only the class name
Ben Finney
ben+python at benfinney.id.au
Sun Oct 23 08:58:16 CEST 2011
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”.
--
\ “I wish there was a knob on the TV to turn up the intelligence. |
`\ There's a knob called ‘brightness’ but it doesn't work.” |
_o__) —Eugene P. Gallagher |
Ben Finney
More information about the Python-ideas
mailing list