Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #111023
| From | eryk sun <eryksun@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Lost in descriptor land |
| Date | 2016-07-03 23:59 +0000 |
| Message-ID | <mailman.51.1467590399.2295.python-list@python.org> (permalink) |
| References | (2 earlier) <7b72a3a0-f0c0-429a-b383-5c3dbfdedba5@googlegroups.com> <CALwzidk9AJa0m0086_xKcYearCv34NK8xQ2Q=1SMZv7WbM2yRA@mail.gmail.com> <mailman.30.1467500855.2295.python-list@python.org> <5779301d$0$1600$c3e8da3$5496439d@news.astraweb.com> <CACL+1au7XBG7r_JgfL-bDwxfW8j9aoSDfUjFpJME9=s9Y4dHVA@mail.gmail.com> |
On Sun, Jul 3, 2016 at 3:32 PM, Steven D'Aprano <steve@pearwood.info> wrote:
>
> But if you prepare the method ahead of time, it works:
>
> from types import MethodType
> instance.method = MethodType(method, instance)
That's a fine way to bind a method, but in the context of this
"descriptor land" topic, I think it's more insightful to call the
function's __get__ method:
>>> type(method)
<class 'function'>
>>> instance.method = method.__get__(instance)
>>> type(instance.method)
<class 'method'>
>>> instance.method.__self__ is instance
True
>>> instance.method.__func__ is method
True
>>> instance.method()
method called from self <__main__.Test object at 0x7faf51d1a198>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Lost in descriptor land Ankush Thakur <ankush.thakur53@gmail.com> - 2016-06-30 18:06 -0700
Re: Lost in descriptor land Ian Kelly <ian.g.kelly@gmail.com> - 2016-06-30 19:36 -0600
Re: Lost in descriptor land Ankush Thakur <ankush.thakur53@gmail.com> - 2016-07-02 04:27 -0700
Re: Lost in descriptor land Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-30 20:33 -0700
Re: Lost in descriptor land Ankush Thakur <ankush.thakur53@gmail.com> - 2016-07-02 04:30 -0700
Re: Lost in descriptor land Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-02 18:02 -0700
Re: Lost in descriptor land Ankush Thakur <ankush.thakur53@gmail.com> - 2016-07-03 06:29 -0700
Re: Lost in descriptor land Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-30 20:43 -0700
Re: Lost in descriptor land Ankush Thakur <ankush.thakur53@gmail.com> - 2016-07-02 04:32 -0700
Re: Lost in descriptor land Ian Kelly <ian.g.kelly@gmail.com> - 2016-07-02 17:06 -0600
Re: Lost in descriptor land Ankush Thakur <ankush.thakur53@gmail.com> - 2016-07-03 06:27 -0700
Re: Lost in descriptor land Steven D'Aprano <steve@pearwood.info> - 2016-07-04 01:32 +1000
Re: Lost in descriptor land eryk sun <eryksun@gmail.com> - 2016-07-03 23:59 +0000
Re: Lost in descriptor land Steven D'Aprano <steve@pearwood.info> - 2016-07-04 11:56 +1000
csiph-web