[Tutor] Why difference between printing string & typing its object reference at the prompt?
Dave Angel
d at davea.name
Thu Oct 4 13:02:26 CEST 2012
On 10/03/2012 11:11 PM, boB Stepp wrote:
> Thanks to all who responded.
> <SNIP>.
> What happens if str() or repr() is not supported by a particular
> object? Is an exception thrown, an empty string returned or something
> else I am not imagining?
Let's try it and see:
>>> class A:pass
...
>>> a = A()
>>> a
<__main__.A object at 0x16ae790>
This is generic information about an object with no methods at all, and
in particular without a __repr__ method. It identifies the module where
the class was defined, the name of the class, and the address the
particular instance happens to be located at. (In CPython, that happens
to be identical to id(a). I'd be happier if it would just identify the
number as the id, since ordinarily, the address is of no use. BTW, as
far as I know, there's no promise as to how this is formatted, so I
wouldn't try to parse it with a program.
>> <SNIP>
>> What larger phrase does "repr" stand for? My text mentions
>> "representational form" later in the book, which sounds similar in
>> concept to what you are discussing.
That would be my guess. I don't recall seeing anything about it.
--
DaveA
More information about the Tutor
mailing list