<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">@Ian,<br><br>The function name in arraymodule.c file is array_len but you have to call something like: , why?<br><br>>>>arr=array('i',[5,8,7])<br>>>>lg=arr.__len__()<br>>>>print(lg)<br><br>Why __len__() where the original name if array_length? Why is method names like __NAME__ ?<br><br>--- On <b>Sun, 6/24/12, gmspro <i><gmspro@yahoo.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: gmspro <gmspro@yahoo.com><br>Subject: Re: How can i call array_length to get the length of array object?<br>To: "Ian Kelly" <ian.g.kelly@gmail.com><br>Cc: "python-list" <python-list@python.org><br>Date: Sunday, June 24, 2012, 3:01 AM<br><br><div id="yiv307492126"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font:inherit;"
valign="top">Why are some methods/functions named in this way in python? __len__<br><br>underscoreunderscoreNAMEunderscoreunderscore<br><br>Is there any speciality of naming such methods?<br><br>--- On <b>Sun, 6/24/12, Ian Kelly <i><ian.g.kelly@gmail.com></i></b> wrote:<br><blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px;"><br>From: Ian Kelly <ian.g.kelly@gmail.com><br>Subject: Re: How can i call array_length to get the length of array object?<br>To: "gmspro" <gmspro@yahoo.com><br>Cc: "python-list" <python-list@python.org><br>Date: Sunday, June 24, 2012, 12:34 AM<br><br><div class="yiv307492126plainMail">On Sat, Jun 23, 2012 at 8:23 PM, gmspro <<a rel="nofollow">gmspro@yahoo.com</a>> wrote:<br>> I'm trying to call this function, <a rel="nofollow" target="_blank"
href="http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657">http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657</a><br>><br>> Is that possible to call that function?<br>><br>> I know it's possible to do:<br>> >>>len(arr)<br><br>You call it just like that. array_length is the C implementation of<br>__len__ for arrays.<br><br>> Doesn't it call this :<br>> <a rel="nofollow" target="_blank" href="http://hg.python.org/cpython/file/c0eab397f098/Python/bltinmodule.c#l1283">http://hg.python.org/cpython/file/c0eab397f098/Python/bltinmodule.c#l1283</a><br>> instead of this:<br>> <a rel="nofollow" target="_blank" href="http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657">http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657</a><br><br>Yes, and builtin_len calls PyObject_Size, which in turn calls the<br>object's sq_length method, which is
defined to be
array_length for<br>arrays.<br></div></blockquote></td></tr></tbody></table></div></blockquote></td></tr></table>