Re: list.__len__() or len(list)

2008-05-14 Thread Carl Banks
On May 14, 11:07 am, Nikhil <[EMAIL PROTECTED]> wrote: > Christian Heimes wrote: > > Ian Kelly schrieb: > >> The purpose of obj.__len__() is to implement len(obj), which simply > >> calls it. So obj.__len__() may be faster, but only marginally. The > >> reason to prefer len(obj) is that if you in

Re: list.__len__() or len(list)

2008-05-14 Thread Terry Reedy
"Nikhil" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Then why to have __len__() internal method at all when the built-in | len() is faster? Nearly all syntax constructions and builtin functions are implemented by calling one or another of the __special__ methods. This is what

Re: list.__len__() or len(list)

2008-05-14 Thread Duncan Booth
Nikhil <[EMAIL PROTECTED]> wrote: > Then why to have __len__() internal method at all when the built-in > len() is faster? Because the internal method is used internally. The idea is that you define __len__() on your objects when appropriate. You are not expected to ever call it. -- http://ma

Re: list.__len__() or len(list)

2008-05-14 Thread Nikhil
Christian Heimes wrote: Ian Kelly schrieb: The purpose of obj.__len__() is to implement len(obj), which simply calls it. So obj.__len__() may be faster, but only marginally. The reason to prefer len(obj) is that if you inadvertently pass an object that does not implement __len__, you get the m

Re: list.__len__() or len(list)

2008-05-14 Thread Hrvoje Niksic
"Ian Kelly" <[EMAIL PROTECTED]> writes: > On Wed, May 14, 2008 at 1:01 AM, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: >> Have you tried it? __len__ is in fact marginally slower because it >> involves a dict lookup, whereas the built-in len() knows how to cheat >> and invoke __len__ through a slo

Re: list.__len__() or len(list)

2008-05-14 Thread Ian Kelly
On Wed, May 14, 2008 at 1:01 AM, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Have you tried it? __len__ is in fact marginally slower because it > involves a dict lookup, whereas the built-in len() knows how to cheat > and invoke __len__ through a slot in the C type struct very > efficiently. >

Re: list.__len__() or len(list)

2008-05-14 Thread Hrvoje Niksic
"Ian Kelly" <[EMAIL PROTECTED]> writes: > On Tue, May 13, 2008 at 5:57 PM, Nikhil <[EMAIL PROTECTED]> wrote: >> __len__() is a built-in function of the list object and is updated along >> with the list object elements and will be useful incase the list is very >> huge. >> >> len() is an external

Re: list.__len__() or len(list)

2008-05-13 Thread Christian Heimes
Ian Kelly schrieb: > The purpose of obj.__len__() is to implement len(obj), which simply > calls it. So obj.__len__() may be faster, but only marginally. The > reason to prefer len(obj) is that if you inadvertently pass an object > that does not implement __len__, you get the more appropriate > T

Re: list.__len__() or len(list)

2008-05-13 Thread Ian Kelly
On Tue, May 13, 2008 at 5:57 PM, Nikhil <[EMAIL PROTECTED]> wrote: > __len__() is a built-in function of the list object and is updated along > with the list object elements and will be useful incase the list is very > huge. > > len() is an external method again, which may require the processing

Re: list.__len__() or len(list)

2008-05-13 Thread [EMAIL PROTECTED]
On May 13, 6:57 pm, Nikhil <[EMAIL PROTECTED]> wrote: > which one is better? and why? > > __len__() is a built-in function of the list object and is updated along > with the list object elements and will be useful incase the list is very > huge. > > len() is an external method again, which may requ

list.__len__() or len(list)

2008-05-13 Thread Nikhil
which one is better? and why? __len__() is a built-in function of the list object and is updated along with the list object elements and will be useful incase the list is very huge. len() is an external method again, which may require the processing cycles again. Is it right? -- http://mai