Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25833

Re: default repr?

References <CAGGBd_oD9tT6Ej0NdsPF7-VRda1k_GQmUQAuutg-eO+XbdYD3Q@mail.gmail.com> <mailman.2444.1342997643.4697.python-list@python.org> <500c99d5$0$29978$c3e8da3$5496439d@news.astraweb.com>
Date 2012-07-23 10:29 +1000
Subject Re: default repr?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2447.1343003376.4697.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Jul 23, 2012 at 10:24 AM, Steven D'Aprano
<steve+comp.lang.python@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: default repr? Chris Angelico <rosuav@gmail.com> - 2012-07-23 08:54 +1000
  Re: default repr? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-23 00:24 +0000
    Re: default repr? Chris Angelico <rosuav@gmail.com> - 2012-07-23 10:29 +1000
      Re: default repr? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-23 01:40 +0000
    Re: default repr? Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-07-22 20:44 -0400

csiph-web