Re: Calling methods without objects?

2017-09-26 Thread Stephan Houben
Op 2017-09-25, Stefan Ram schreef : > So, is there some mechanism in Python that can bind a method > to an object so that the caller does not have to specify the > object in the call? > > If so, how is this mechanism called? > Others have already explained the

Re: Calling methods without objects?

2017-09-26 Thread Gregory Ewing
Thomas Jollans wrote: When an object is constructed from a class, all functions in the class are turned into method objects that refer back to the original object. That's not quite true. Nothing is done to the methods at the time an instance is created; rather, a bound method object is created

Re: Calling methods without objects?

2017-09-25 Thread Thomas Jollans
On 26/09/17 01:04, Thomas Jollans wrote: > > In [1]: class C: > >...: def m(self): > >...: return True I'll have to give my MUA a stern talking to about the importance of whitespace. Anyway, you know what I mean. > >...: -- https://mail.python.org/mailman/listinfo/python-list

Re: Calling methods without objects?

2017-09-25 Thread Chris Angelico
On Tue, Sep 26, 2017 at 8:49 AM, Stefan Ram wrote: > |>>> from random import randint > | > |>>> randint > |> > | > |>>> randint.__self__ > | > | > |>>> randint( 2, 3 ) > |2 > > It seems I am calling the method »randint« of the object at > »0x389798«, but I do not have