Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31689

Re: len() on mutables vs. immutables

References <50803B2C.6010900@gmail.com> <k5phqe$2ia$1@ger.gmane.org> <50804DA8.80708@gmail.com> <CACoLFeSNciVJEtkDz28emirogBp+KivP_y5-uFt5x6QEzipHwA@mail.gmail.com>
Date 2012-10-18 15:25 -0700
Subject Re: len() on mutables vs. immutables
From Demian Brecht <demianbrecht@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2478.1350599115.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Oct 18, 2012 at 12:43 PM, Daniel Urban <urban.dani@gmail.com> wrote:
> The source is usually in Objects/*object.c (e.g., the source for list
> is in Objects/listobject.c, dict is in dictobject.c and so on). The
> implementation of __len__ is usually in a method called
> whatever_length (e.g., dict.__len__ is called dict_length). To be
> sure, you can check the PyTypeObject declaration for the type.
> Probably the tp_as_sequence or tp_as_mapping field contains the
> pointer to __len__ (sq_length or mp_length respectively). (You can
> also search for "lenfunc", which is the type of such functions.)

Many thanks for the details.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: len() on mutables vs. immutables Demian Brecht <demianbrecht@gmail.com> - 2012-10-18 15:25 -0700

csiph-web