The PyListObject is the structure that is used to store the Python Lists.

typedef struct {
/* Vector of pointers to list elements. list[0] is ob_item[0], etc. */
PyObject **ob_item;

/* ob_item contains space for ‘allocated’ elements. The number
* currently in use is ob_size.
* Invariants:
* 0 <= ob_size <= allocated
* len(list) == ob_size
* ob_item == NULL implies ob_size == allocated == 0
* list.sort() temporarily sets allocated to -1 to detect mutations.
* Items must normally not be NULL, except during construction when
* the list is not yet visible outside the function that builds it.
Py_ssize_t allocated;
} PyListObject;

We see that the data is stored as an array of PyObjects. This is the main portion of the lists.

Open the debugger and set a debug point in the file Objects/listobject.c on line number 115.

In the debugger type the expression:

a = []

We see that the debugger is trapped. Debug step by step and understand how the list is created.

Set a debug point on line number 327 and type the expression:

a= range(0,10)

print a

In this function observe how the list is traversed and printed. Do check the other methods in listobject.c for further details on how lists work.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s