Re: to pass self or not to pass self

2010-03-20 Thread Gregory Ewing
Patrick Maupin wrote: Actually, I think I overstated my case -- there is some special logic for len and built-in objects, I think. Yes, len() invokes the C-level sq_len slot of the type object, which for built-in types points directly to the C function implementing the len() operation for that

Re: to pass self or not to pass self

2010-03-17 Thread Joaquin Abian
On Mar 18, 12:11 am, Patrick Maupin wrote: > On Mar 17, 5:34 pm, Joaquin Abian wrote: > > > > > On Mar 17, 3:43 pm, Patrick Maupin wrote: > > > > On Mar 17, 4:12 am, Bruno Desthuilliers > > > 42.desthuilli...@websiteburo.invalid> wrote: > > > > Patrick Maupin a écrit : > > > > > > On Mar 16, 1:

Re: to pass self or not to pass self

2010-03-17 Thread Patrick Maupin
On Mar 17, 5:34 pm, Joaquin Abian wrote: > On Mar 17, 3:43 pm, Patrick Maupin wrote: > > > > > On Mar 17, 4:12 am, Bruno Desthuilliers > > 42.desthuilli...@websiteburo.invalid> wrote: > > > Patrick Maupin a écrit : > > > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > > > >> Why not create th

Re: to pass self or not to pass self

2010-03-17 Thread Joaquin Abian
On Mar 17, 3:43 pm, Patrick Maupin wrote: > On Mar 17, 4:12 am, Bruno Desthuilliers > 42.desthuilli...@websiteburo.invalid> wrote: > > Patrick Maupin a écrit : > > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > > >> Why not create the bound methods at instantiation time, rather than > > >> us

Re: to pass self or not to pass self

2010-03-17 Thread Patrick Maupin
On Mar 17, 2:55 pm, Terry Reedy wrote: > On 3/17/2010 1:35 AM, Patrick Maupin wrote: > > def a(s, count, lenfunc): > > ...     for i in xrange(count): > > ...        z = lenfunc(s) > > ... > >>>  a('abcdef', 1, len) > >>>  a('abcdef', 1, str.__len__) > > Running cPyt

Re: to pass self or not to pass self

2010-03-17 Thread Terry Reedy
On 3/17/2010 1:35 AM, Patrick Maupin wrote: def a(s, count, lenfunc): ... for i in xrange(count): ...z = lenfunc(s) ... >>> a('abcdef', 1, len) >>> a('abcdef', 1, str.__len__) Running cPython 2.6 on my machine, len() runs about 3 times faster than str.__len__().

Re: to pass self or not to pass self

2010-03-17 Thread Bruno Desthuilliers
Lie Ryan a écrit : On 03/17/2010 08:12 PM, Bruno Desthuilliers wrote: Patrick Maupin a écrit : On Mar 16, 1:59 pm, Jason Tackaberry wrote: Why not create the bound methods at instantiation time, rather than using the descriptor protocol which has the overhead of creating a new bound method ea

Re: to pass self or not to pass self

2010-03-17 Thread Patrick Maupin
On Mar 17, 4:12 am, Bruno Desthuilliers wrote: > Patrick Maupin a écrit : > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > >> Why not create the bound methods at instantiation time, rather than > >> using the descriptor protocol which has the overhead of creating a new > >> bound method each t

Re: to pass self or not to pass self

2010-03-17 Thread Lie Ryan
On 03/17/2010 08:12 PM, Bruno Desthuilliers wrote: > Patrick Maupin a écrit : >> On Mar 16, 1:59 pm, Jason Tackaberry wrote: >>> Why not create the bound methods at instantiation time, rather than >>> using the descriptor protocol which has the overhead of creating a new >>> bound method each time

Re: to pass self or not to pass self

2010-03-17 Thread Lie Ryan
On 03/17/2010 04:32 PM, Steven D'Aprano wrote: > On Wed, 17 Mar 2010 15:57:17 +1100, Lie Ryan wrote: > >> Most people probably would never need to use >> descriptor protocol directly, since the immediate benefit of descriptor >> protocol are property(), classmethod(), and instancemethod() decorato

Re: to pass self or not to pass self

2010-03-17 Thread Bruno Desthuilliers
Patrick Maupin a écrit : On Mar 16, 1:59 pm, Jason Tackaberry wrote: Why not create the bound methods at instantiation time, rather than using the descriptor protocol which has the overhead of creating a new bound method each time the method attribute is accessed? Well, for one thing, Python

Re: to pass self or not to pass self

2010-03-16 Thread Patrick Maupin
On Mar 16, 1:59 pm, Jason Tackaberry wrote: > Why not create the bound methods at instantiation time, rather than > using the descriptor protocol which has the overhead of creating a new > bound method each time the method attribute is accessed? Well, for one thing, Python classes are open. They

Re: to pass self or not to pass self

2010-03-16 Thread Steven D'Aprano
On Wed, 17 Mar 2010 15:57:17 +1100, Lie Ryan wrote: > Most people probably would never need to use > descriptor protocol directly, since the immediate benefit of descriptor > protocol are property(), classmethod(), and instancemethod() decorators > which, without descriptor protocol, would never b

Re: to pass self or not to pass self

2010-03-16 Thread Lie Ryan
On 03/17/2010 05:59 AM, Jason Tackaberry wrote: > On Tue, 2010-03-16 at 10:04 +0100, Bruno Desthuilliers wrote: >> Answer here: >> >> http://wiki.python.org/moin/FromFunctionToMethod > > I have a sense I used to know this once upon a time, but the question > came to my mind (possibly again) and I

Re: to pass self or not to pass self

2010-03-16 Thread Jonathan Gardner
On Tue, Mar 16, 2010 at 2:04 AM, Bruno Desthuilliers wrote: > lallous a écrit : >> >> What is the difference between the reference in 'F' and 'func_tbl' ? > > Answer here: > > http://wiki.python.org/moin/FromFunctionToMethod > Among all the things in the Python language proper, this is probably t

Re: to pass self or not to pass self

2010-03-16 Thread Jason Tackaberry
On Tue, 2010-03-16 at 10:04 +0100, Bruno Desthuilliers wrote: > Answer here: > > http://wiki.python.org/moin/FromFunctionToMethod I have a sense I used to know this once upon a time, but the question came to my mind (possibly again) and I couldn't think of an answer: Why not create the bound met

Re: to pass self or not to pass self

2010-03-16 Thread Bruno Desthuilliers
lallous a écrit : Hello, Learning Python from the help file and online resources can leave one with many gaps. Can someone comment on the following: (snip code) Why in test1() when it uses the class variable func_tbl we still need to pass self, but in test2() we don't ? What is the differen

Re: to pass self or not to pass self

2010-03-15 Thread Rami Chowdhury
On Monday 15 March 2010 10:42:41 TomF wrote: > On 2010-03-15 09:39:50 -0700, lallous said: > > > > Why in test1() when it uses the class variable func_tbl we still need > > to pass self, but in test2() we don't ? > > > > What is the difference between the reference in 'F' and 'func_tbl' ? >

Re: to pass self or not to pass self

2010-03-15 Thread TomF
On 2010-03-15 09:39:50 -0700, lallous said: Hello, Learning Python from the help file and online resources can leave one with many gaps. Can someone comment on the following: # - class X: T = 1 def f1(self, arg): print "f1, arg=%d" % arg def f2(self, arg):

to pass self or not to pass self

2010-03-15 Thread lallous
Hello, Learning Python from the help file and online resources can leave one with many gaps. Can someone comment on the following: # - class X: T = 1 def f1(self, arg): print "f1, arg=%d" % arg def f2(self, arg): print "f2, arg=%d" % arg def f3(self, arg):