Any comments are welcomed, thanks in advance.
How would you read any other source code?
--
Steven
Are you trying to find out more about python-the-language,
or the interpreter, or the stdlib, or trying to make some
specific change, or...?
Geremy Condra
I would begin at the beginning, whatever that might be. But the Python
source tree is rather opaque in some respects compared to other stuff I
have read. The individual files I have read are much better organized.
Still O(n). Python doesn't know that your list is sorted, so nothing
changes. And the check to make sure it is sorted would be O(n) anyway.
However, if the programmer knows that the list is sorted, then the
following would be O(log n):
from bisect import bisect_left
index = bisect_left(the_list, item)
item_in_list = index < len(the_list) and the_list[index] == item
But in general, if you want the "in" operator to be efficient, then
you probably want to use a set or a dict, not a list.
Cheers,
Ian
There is excellent documentation of the language and standard library at
http://docs.python.org/ .
Otherwise, just download the Python source code! You know it's free. I
think it's pretty well organised, though I haven't worked with it a lot
yet myself. Just poke around!
Have fun,
Thomas
>
>
>
> On Wed, Jun 9, 2010 at 5:59 PM, geremy condra <deba...@gmail.com
> <mailto:deba...@gmail.com>> wrote:
I use my favourite text editor with syntax highlighting.
Next to it I use a web browser with pydoc and google.
If uou're looking for an IDE that will help you a little more navigating
in python code, then you could look at
Eclipse
or
Netbeans
both support python
both are rather heavy weapons though.
In my opinion, pydoc would be a good choice. I am a fan of it.
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
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
It does help, thank you.
I think I know where to start, I found somethings I'm interested in in
listobject.c.
Great stuff, which works for me very well.