Re: Lost in descriptor land

2016-07-03 Thread Steven D'Aprano
On Mon, 4 Jul 2016 09:59 am, eryk sun wrote: > On Sun, Jul 3, 2016 at 3:32 PM, Steven D'Aprano > 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

Re: Lost in descriptor land

2016-07-03 Thread eryk sun
On Sun, Jul 3, 2016 at 3:32 PM, Steven D'Aprano 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

Re: Lost in descriptor land

2016-07-03 Thread Steven D'Aprano
On Sun, 3 Jul 2016 09:06 am, Ian Kelly wrote: > you can't define a method > on an instance (though you can certainly store a function there and > call it). Yes -- the difference is that Python doesn't apply the descriptor protocol to attributes attached to the instance. So the function remains a

Re: Lost in descriptor land

2016-07-03 Thread Ankush Thakur
On Sunday, July 3, 2016 at 6:32:56 AM UTC+5:30, Lawrence D’Oliveiro wrote: > Haste makes waste, as they say. At least read the relevant part of the > article. I really feel like I've been pushed into studying its genetics while I only wanted to pluck the fruit. Why do descriptors have to be so o

Re: Lost in descriptor land

2016-07-03 Thread Ankush Thakur
On Sunday, July 3, 2016 at 4:37:49 AM UTC+5:30, Ian wrote: > Classes define object behavior; > instances contain object state. For example, you can't define a method > on an instance (though you can certainly store a function there and > call it). Nice! Thanks for clearing that up. :) -- https:/

Re: Lost in descriptor land

2016-07-02 Thread Lawrence D’Oliveiro
On Saturday, July 2, 2016 at 11:31:02 PM UTC+12, Ankush Thakur wrote: > On Friday, July 1, 2016 at 9:03:44 AM UTC+5:30, Lawrence D’Oliveiro wrote: >> Every time I feel unsure, I go back to the horse’s mouth: here >>

Re: Lost in descriptor land

2016-07-02 Thread Ian Kelly
On Sat, Jul 2, 2016 at 5:32 AM, Ankush Thakur wrote: > On Friday, July 1, 2016 at 9:13:19 AM UTC+5:30, Lawrence D’Oliveiro wrote: >> >> > Shouldn't we be instead using self.celcius in, say, __init__() and then >> > everything will work fine? >> >> I guess it might. But this way, using descriptors,

Re: Lost in descriptor land

2016-07-02 Thread Ankush Thakur
On Friday, July 1, 2016 at 9:13:19 AM UTC+5:30, Lawrence D’Oliveiro wrote: > > > Shouldn't we be instead using self.celcius in, say, __init__() and then > > everything will work fine? > > I guess it might. But this way, using descriptors, all the setup is done once > at class definition, rather

Re: Lost in descriptor land

2016-07-02 Thread Ankush Thakur
On Friday, July 1, 2016 at 9:03:44 AM UTC+5:30, Lawrence D’Oliveiro wrote: > Every time I feel unsure, I go back to the horse’s mouth: here > > is GvR himself with all the details on “new-style” classes, including

Re: Lost in descriptor land

2016-07-02 Thread Ankush Thakur
On Friday, July 1, 2016 at 7:07:09 AM UTC+5:30, Ian wrote: > First of all, do you understand what descriptors are? This is a fairly > advanced Python concept. For a general tutorial, I would point you to > https://docs.python.org/3/howto/descriptor.html I understand what descriptors try to accomp

Re: Lost in descriptor land

2016-06-30 Thread Lawrence D’Oliveiro
On Friday, July 1, 2016 at 1:06:12 PM UTC+12, Ankush Thakur wrote: > 1) I don't get the idea behind the 'instance' and 'owner' parameters at > all. Is there some simple tutorial that can explain these? Read the GvR blog post I referenced separately. Then after that, the relevant section of the la

Re: Lost in descriptor land

2016-06-30 Thread Lawrence D’Oliveiro
On Friday, July 1, 2016 at 1:06:12 PM UTC+12, Ankush Thakur wrote: > There's something I don't understand about descriptors. There’s a lot to not understand about them. :) Every time I feel unsure, I go back to the horse’s mouth: here

Re: Lost in descriptor land

2016-06-30 Thread Ian Kelly
On Thu, Jun 30, 2016 at 7:06 PM, Ankush Thakur wrote: > Hello, > > There's something I don't understand about descriptors. On a StackOverflow > discussion > (http://stackoverflow.com/questions/12846116/python-descriptor-vs-property) > one of the answers provides the following descriptors exampl

Lost in descriptor land

2016-06-30 Thread Ankush Thakur
Hello, There's something I don't understand about descriptors. On a StackOverflow discussion (http://stackoverflow.com/questions/12846116/python-descriptor-vs-property) one of the answers provides the following descriptors example: class Celsius( object ): def __init__( self, value=0.0 ):