default repr?
Oscar Benjamin
oscar.j.benjamin at gmail.com
Sun Jul 22 18:54:13 EDT 2012
More information about the Python-list mailing list
Sun Jul 22 18:54:13 EDT 2012
- Previous message (by thread): default repr?
- Next message (by thread): default repr?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 22 July 2012 23:48, Dan Stromberg <drsalists at gmail.com> wrote: > > If a class has defined its own __repr__ method, is there a way of getting > the default repr output for that class anyway? > For new style classes you can just call object.__repr__ e.g.: In [1]: class A(object): ...: pass ...: In [2]: class B(object): ...: def __repr__(self): ...: return 'foo' ...: In [3]: a = A() In [4]: b = B() In [5]: repr(a) Out[5]: '<__main__.A object at 0x2136b10>' In [6]: repr(b) Out[6]: 'foo' In [7]: object.__repr__(b) Out[7]: '<__main__.B object at 0x2136c10>' Oscar. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20120722/bf171743/attachment.html>
- Previous message (by thread): default repr?
- Next message (by thread): default repr?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list