[Python-3000] Types and classes

Guido van Rossum guido at python.org
Wed Apr 9 02:17:39 CEST 2008


On Tue, Apr 8, 2008 at 4:49 PM, Facundo Batista
<facundobatista at gmail.com> wrote:
> 2008/4/8, Greg Ewing <greg.ewing at canterbury.ac.nz>:
>  > That's true, but it's sufficiently unlikely that a string
>  >  such as "<type 'foo'>" could have accidentally arisen some
>  >  other way that I don't lose any sleep over it. If weird
>  >  things seem to be happening in some particular case, I'll
>  >  put a repr() in to find out exactly what's going on. Most
>  >  of the time it's not needed, though.
>  >
>  >  There's another reason it bothers me. If a string like
>  >  "<type 'foo'>" turns up in otherwise normal output, it's
>  >  a fairly clear indication that I've somehow ended up
>  >  printing something that was never meant to be printed.
>  >  Whereas if it just comes out as "foo", it could easily
>  >  go unnoticed.
>
>  I'm with Greg here, but I'll put it in another way: I don't want
>  repr() to be nice, I want it to be as explicit as possible. I want to
>  be able to trust repr(), and never doubt of what it's showing to me.

Seems to be mass confusion all around. My proposal is:

repr(int) == <class 'int'>
str(int) == 'int'

For user-defined classes, a module name will always be present, e.g.
for class C defined in __main__:

repr(C) == <class '__main__.C'>
str(c) == '__main__.C'

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list