Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

Can I learn Python without knowing anything?

Yes, you can learn Python without any programming experience. In fact, Python is so popular in part because of its easy-to-use, intuitive nature. For people without any coding experience at all, Python is actually considered the perfect programming language.

How many days is enough to learn Python?

In general, it takes around two to six months to learn the fundamentals of Python. But you can learn enough to write your first short program in a matter of minutes. Developing mastery of Python's vast array of libraries can take months or years.


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


I would first read the What's New document for Python 3. It gives a good high-level overview and touches on the detailed changes.

You might also do a search for 'porting to python 3' or similar. There are lots of good resources and tools.

One tool that's new and hard to find is six, by Benjamin Peterson. It enables writing of code that is compatible across the Python 2*3 gap.

The part I found most difficult about maintaining Python 2 and Python 3 -compatible code was deployment. I could write code that would run just fine, but when I went do package and deploy, it was unclear when the conversion should happen. I ultimately found a distutils command build_py_2_to_3 that would do the trick. By using that command in my setup.py, I could release a source distribution that would deploy on either Python 2 or Python 3. An example can be found in jaraco.util.

You also asked about the internals. If you really want to get at the internals, you can view the source for Python 2.x and Python 3.x, though honestly, I would stick with reading the tutorials and maybe some of the .py files in the Python libs.