deque.popleft() and list.pop(0). Is there performance difference?

deque.popleft() is faster than list.pop(0), because the deque has been optimized to do popleft() approximately in O(1), while list.pop(0) takes O(n) (see deque objects). Comments and code in _collectionsmodule.c for deque and listobject.c for list provide implementation insights to explain the performance differences. Namely that a deque object “is composed of a doubly-linked list”, which … Read more

Using NumPy and Cpython with Jython

It’s ironic, considering that Jython and Numeric (NumPy’s ancestor) were initiated by the same developer (Jim Hugunin, who then moved on to also initiate IronPython and now holds some kind of senior architect position at Microsoft, working on all kind of dynamic languages support for .NET and Silverlight), that there’s no really good way to … Read more

CPython is bytecode interpreter?

CPython is the implementation of Python in C. It’s the first implementation, and still the main one that people mean when they talk about Python. It compiles .py files to .pyc files. .pyc files contain bytecodes. The CPython implementation also interprets those bytecodes. CPython is not written in C++, it is C. The compilation from … Read more

CPython memory allocation

Much of this is answered in the Memory Management chapter of the C API documentation. Some of the documentation is vaguer than you’re asking for. For further details, you’d have to turn to the source code. And nobody’s going to be willing to do that unless you pick a specific version. (At least 2.7.5, pre-2.7.6, … Read more

Why does str.split not take keyword arguments?

See this bug and its superseder. str.split() is a native function in CPython, and as such exhibits the behavior described here: CPython implementation detail: An implementation may provide built-in functions whose positional parameters do not have names, even if they are ‘named’ for the purpose of documentation, and which therefore cannot be supplied by keyword. … Read more

What is python-dev package used for

python-dev python-dev contains the header files you need to build Python extensions. lxml lxml is a Python C-API extension that is compiled when you do pip install lxml. The lxml sources have at least something like #include <Python.h> in the code. The compiler looks for the header file Python.h during compilation, hence those header files … Read more

How exactly is Python Bytecode Run in CPython?

Yes, your understanding is correct. There is basically (very basically) a giant switch statement inside the CPython interpreter that says “if the current opcode is so and so, do this and that”. http://hg.python.org/cpython/file/3.3/Python/ceval.c#l790 Other implementations, like Pypy, have JIT compilation, i.e. they translate Python to machine codes on the fly.