[Python-ideas] Changing str(someclass) to return only the class name
Ka-Ping Yee
python at zesty.ca
Sat Oct 29 00:00:57 CEST 2011
Hi there,
I get that repr() is supposed to be the precise representation
and str() is intended more to be friendly than precise. My
concern with the proposal is just that this:
>>> print x
foo
...doesn't actually feel that friendly to me. I want to know
that it's *probably* a function or *probably* a class, the same
way that today, when I see:
>>> print x
biscuit
>>> print y
[1, 2, 3]
I can guess that x is *probably* a string and y is *probably*
a list (e.g. because I know I'm not working with any custom
objects whose __str__ returns those things).
It would create a slightly higher mental burden (or slightly
higher probability of human error) if, when I see:
>>> print x
Splat
...I have to remember that x might be a string or a function or
a class.
I'd just like some kind of visual hint as to what it is. Like:
>>> print x
foo()
or:
>>> print x
function foo
or:
>>> print x
function foo(a, b)
or:
>>> print x
class Bar
In fact "function foo(a, b)" would actually be rather useful
in a lot of situations, and I would argue, friendlier than "foo".
--Ping
More information about the Python-ideas
mailing list