From: Floris Bruynooghe on
On Jun 10, 8:55 am, Thomas Jollans <tho...(a)jollans.com> wrote:
> On 06/10/2010 07:25 AM, Qijing Li wrote:
>
> > Thanks for your reply.
> > I'm trying to understand python language deeply and  use it efficiently.
> > For example: How the operator "in" works on list? the running time is
> > be O(n)?  if my list is sorted, what the running time would be?

Taking this example, you know you want the "in" operator. Which you
somehow need to know is implemented by the "__contains__" protocol
(you can find this in the "expressions" section of the "Language
Reference").

Now you can either know how objects look like in C (follow the
"Extending and Embedding" tutorial, specifically the "Defining New
Types" section) and therefore know you need to look at the sq_contains
slot of the PySequenceMethods sturcture. Or you could just locate the
list object in Objects/listobjects.c (which you can easily find by
looking at the source tree) and search for "contains". Both ways
will lead you pretty quickly to the list_contains() function in
Objects/listobject.c. And now you just need to know the C-API (again
in the docs) to be able to read it (even if you don't that's a pretty
straightforward function to read).

Hope that helps
Floris
From: Giampaolo Rodolà on
2010/6/10 Leon <qjing.li(a)gmail.com>:
> Hi, there,
> I'm trying to read the source code of python.
> I read around, and am kind of lost, so where to start?
>
> Any comments are welcomed, thanks in advance.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

If you're interested in understanding Python internals you might want
to take a look at this:
http://tech.blog.aknin.name/category/my-projects/pythons-innards/


--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil
From: Lee on
On Jun 10, 7:53 am, Floris Bruynooghe <floris.bruynoo...(a)gmail.com>
wrote:
> On Jun 10, 8:55 am, Thomas Jollans <tho...(a)jollans.com> wrote:
>
> > On 06/10/2010 07:25 AM, Qijing Li wrote:
>
> > > Thanks for your reply.
> > > I'm trying to understand python language deeply and  use it efficiently.
> > > For example: How the operator "in" works on list? the running time is
> > > be O(n)?  if my list is sorted, what the running time would be?
>
> Taking this example, you know you want the "in" operator.  Which you
> somehow need to know is implemented by the "__contains__" protocol
> (you can find this in the "expressions" section of the "Language
> Reference").
>
> Now you can either know how objects look like in C (follow the
> "Extending and Embedding" tutorial, specifically the "Defining New
> Types" section) and therefore know you need to look at the sq_contains
> slot of the PySequenceMethods sturcture.  Or you could just locate the
> list object in Objects/listobjects.c (which you can easily find by
> looking at the source tree) and search for "contains".  Both ways
> will lead you pretty quickly to the list_contains() function in
> Objects/listobject.c.  And now you just need to know the C-API (again
> in the docs) to be able to read it (even if you don't that's a pretty
> straightforward function to read).
>
> Hope that helps
> Floris

It does help, thank you.
I think I know where to start, I found somethings I'm interested in in
listobject.c.
From: Lee on
On Jun 10, 10:26 am, Giampaolo Rodolà <g.rod...(a)gmail.com> wrote:
> 2010/6/10 Leon <qjing...(a)gmail.com>:
>
> > Hi, there,
> > I'm trying to read the source code of python.
> > I read around, and am kind of lost, so where to start?
>
> > Any comments are welcomed, thanks in advance.
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> If you're interested in understanding Python internals you might want
> to take a look at this:http://tech.blog.aknin.name/category/my-projects/pythons-innards/
>
> --- Giampaolohttp://code.google.com/p/pyftpdlibhttp://code.google.com/p/psutil

Great stuff, which works for me very well.