Re: default repr?

2012-07-23 Thread Oscar Benjamin
of getting the default repr output for that class anyway? If the class, call it C, is a subclass of some other class (or classes), then there is also the repr of the parent. You can get to that by calling parent.__repr__(instance), although there are some subtleties. In Python 2, there are old-style

default repr?

2012-07-22 Thread Dan Stromberg
If a class has defined its own __repr__ method, is there a way of getting the default repr output for that class anyway? I'm attempting to graph some objects by digging around in the garbage collector's idea of what objects exist, and when I go to format them for the graph node labels, the ones

Re: default repr?

2012-07-22 Thread Chris Angelico
On Mon, Jul 23, 2012 at 8:48 AM, Dan Stromberg drsali...@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? Methods are just functions, and you can call any method of any class with any object as its first

Re: default repr?

2012-07-22 Thread Oscar Benjamin
On 22 July 2012 23:48, Dan Stromberg drsali...@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

Re: default repr?

2012-07-22 Thread Steven D'Aprano
On Mon, 23 Jul 2012 08:54:00 +1000, Chris Angelico wrote: On Mon, Jul 23, 2012 at 8:48 AM, Dan Stromberg drsali...@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? If the class, call it C, is a subclass

Re: default repr?

2012-07-22 Thread Chris Angelico
On Mon, Jul 23, 2012 at 10:24 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Methods are just functions, and you can call any method of any class with any object as its first parameter. Not quite: they have to be an instance of that class. Though this mightn't work with

Re: default repr?

2012-07-22 Thread Devin Jeanpierre
On Sun, Jul 22, 2012 at 8:29 PM, Chris Angelico ros...@gmail.com wrote: On Mon, Jul 23, 2012 at 10:24 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Not quite: they have to be an instance of that class. 8 Hmm. I would have thought that methods were like all other

Re: default repr?

2012-07-22 Thread Steven D'Aprano
On Mon, 23 Jul 2012 10:29:33 +1000, Chris Angelico wrote: On Mon, Jul 23, 2012 at 10:24 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Methods are just functions, and you can call any method of any class with any object as its first parameter. Not quite: they have to be an