default repr?

Chris Angelico rosuav at gmail.com
Sun Jul 22 20:29:33 EDT 2012


On Mon, Jul 23, 2012 at 10:24 AM, Steven D'Aprano
<steve+comp.lang.python at 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 everything. I wasn't able to paint a list
>> as a tuple - "tuple.__repr__([1,2,3])" threw a TypeError. Oh well.
>> There's a limit to the ways Python lets you shoot yourself in the foot.
>
> Of course -- [1,2,3] is not a tuple, so how would tuple know what to do
> with it?

Hmm. I would have thought that methods were like all other functions:
they take their arguments and do code with them. Duck typing and all.
I stand corrected, then.

In any case, it works fine for methods of object, at least with Python
3 and with new-style classes in Py2.

(Other than backward compatibility with old code, is there any reason
to use an old-style class?)

ChrisA



More information about the Python-list mailing list