Google Groepen ondersteunt geen nieuwe Usenet-berichten of -abonnementen meer. Historische content blijft zichtbaar.

How to read source code of python?

3 weergaven
Naar het eerste ongelezen bericht

Leon

ongelezen,
9 jun 2010, 20:28:2809-06-2010
aan
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.

Steven D'Aprano

ongelezen,
9 jun 2010, 20:35:3109-06-2010
aan

How would you read any other source code?

--
Steven

geremy condra

ongelezen,
9 jun 2010, 20:59:0509-06-2010
aan Leon, pytho...@python.org

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

Bericht is verwijderd

Terry Reedy

ongelezen,
10 jun 2010, 01:00:0510-06-2010
aan pytho...@python.org

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.


Benjamin Kaplan

ongelezen,
10 jun 2010, 01:54:0110-06-2010
aan pytho...@python.org
On Wed, Jun 9, 2010 at 10:25 PM, Qijing Li <qjin...@gmail.com> 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?
>
>

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.

Ian Kelly

ongelezen,
10 jun 2010, 03:23:3910-06-2010
aan pytho...@python.org

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

Thomas Jollans

ongelezen,
10 jun 2010, 03:55:0210-06-2010
aan pytho...@python.org
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?

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:

News123

ongelezen,
10 jun 2010, 04:15:2510-06-2010
aan
Leon wrote:
> Hi, there,
> I'm trying to read the source code of python.dd

> I read around, and am kind of lost, so where to start?
>
> Any comments are welcomed, thanks in advance.


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.

pradeepbpin

ongelezen,
10 jun 2010, 07:18:5410-06-2010
aan


In my opinion, pydoc would be a good choice. I am a fan of it.

Floris Bruynooghe

ongelezen,
10 jun 2010, 10:53:0410-06-2010
aan
On Jun 10, 8:55 am, Thomas Jollans <tho...@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

Giampaolo Rodolà

ongelezen,
10 jun 2010, 13:26:2010-06-2010
aan Leon, pytho...@python.org
2010/6/10 Leon <qjin...@gmail.com>:
> --
> 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

Lee

ongelezen,
11 jun 2010, 03:55:5311-06-2010
aan
On Jun 10, 7:53 am, Floris Bruynooghe <floris.bruynoo...@gmail.com>
wrote:

It does help, thank you.
I think I know where to start, I found somethings I'm interested in in
listobject.c.

Lee

ongelezen,
11 jun 2010, 03:56:3411-06-2010
aan
On Jun 10, 10:26 am, Giampaolo Rodolà <g.rod...@gmail.com> wrote:
> 2010/6/10 Leon <qjing...@gmail.com>:

Great stuff, which works for me very well.

0 nieuwe berichten