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
"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
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
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
"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
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.
>
"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
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
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
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
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
11 matches
Mail list logo