How can I learn more about Python’s internals? [closed]

I have been programming using Python for slightly more than half an year now and I am more interested in Python internals rather than using Python to develop applications. Currently I am working on porting a few libraries from Python2 to Python3. However, I have a rather abstract view on how to make port stuff over from Python2 to Python3 as most of the changes deal with design issues in Python2.x

I'd like to learn more about Python internals; should I go for a top-down or a bottom-up approach? Are there any references you could recommend?


It sounds like you want to know more about the rationale behind the design of the language, rather than internals. "internals" to me means things like how objects are laid out in memory, how reference counting works, and so on.

If you're looking for a deeper understanding of the design decisions, try reading the PEPs: they are the proposals for changes in the language, and often include detailed discussions of the reasons for the changes, rejected alternatives, and so on. Even the rejected PEPs are useful, because they show the thinking that has shaped the language.

For example:

  • 3105: Making print a function
  • 3110: Catching exceptions in Python 3.x
  • 3131: Supporting non-ASCII identifiers

and so on..

If you really want to learn about Python internals, then start by reading about the Python C API, which is used to build Python itself: my talk A Whirlwind Excursion through Python C Extensions is one place to start. Then you can dive into the Python source code itself for anything you need to learn about.


To someone who is stumbling upon this question from related links or search, there is a documentation written Yaniv Aknin on Python Internals. It starts from the scratch and is highly readable.


I find the series of Yaniv Aknin's Pythons Innards series fantastic, too

I discovered it thanks to Planet Python

.

You may be also interested by the answer of TryPyPy in this SO thread