<br><div class="gmail_quote">On 23 July 2012 01:24, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve+comp.lang.python@pearwood.info" target="_blank">steve+comp.lang.python@pearwood.info</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Mon, 23 Jul 2012 08:54:00 +1000, Chris Angelico wrote:<br>
<br>
> On Mon, Jul 23, 2012 at 8:48 AM, Dan Stromberg <<a href="mailto:drsalists@gmail.com">drsalists@gmail.com</a>><br>
> wrote:<br>
</div><div class="im">>> If a class has defined its own __repr__ method, is there a way of<br>
>> getting the default repr output for that class anyway?<br>
<br>
</div>If the class, call it C, is a subclass of some other class (or classes),<br>
then there is also the repr of the parent. You can get to that by calling<br>
parent.__repr__(instance), although there are some subtleties.<br>
<br>
In Python 2, there are old-style or classic classes that don't inherit<br>
from anything else. I don't believe there is any way to get the repr of a<br>
classic class with no __repr__ method *except* from an instance with no<br>
__repr__ method. So the answer for C below will be No:<br>
<br>
# Python 2.x<br>
class C:<br>
    def __repr__(self):<br>
        return "C()"<br></blockquote><div><br></div><div>You coudl always implement repr yourself:</div><div><br></div><div><div><div>def repr_oldstyle(obj):</div><div>    mod = obj.__class__.__module__</div><div>
    cls = obj.__class__.__name__</div><div>    mem = '0x' + hex(id(obj))[2:].zfill(8).upper()</div><div>    return '<{0}.{1} instance at {2}>'.format(mod, cls, mem)</div></div></div></div>