How / Where can I learn what's happening "under the hood" in Python

Viewed 1286

I am currently mainly developing things in Python, I code in Python a lot, and I am slowly starting to wonder: "what really happens on the lower-level of Python?", I know that Python's code gets converted to binary code which then gets processed, but where can I really find out whats happening when I, for example, create a variable with a value, how does one value get represented, where is it stored, how is it stored? How does the code get converted? How do booleans work, how can I modify bytes? etc. When telling a computer what to do it's like explaining your comments to the computer, but how does the computer process all of it?

Where/how can I find out how Python or in general my computer really works (looks under the hood)? I want to learn more about what's really happening in hopes of me becoming a better programmer.

2 Answers

If you want to look at a bytecode interpreter written in Python there is x-python. There is even a gdb (or pdb)-like debugger for this which allows you to step either Python statements or bytcode instructions.

It supports Bytecode back to around Python 2.4, but the interpreter is most complete around 3.5 opcodes and earlier.

This can be viewed as a feature for those who want to use this project to increase understanding of bytecode to the point of being able to fill in the gaps :-)

It is based on Ned Batchelder's byterun.

Note: neither project fully isolates the interpreter environment from the bytecode that is getting interpreted. But for tutorial purposes, this shouldn't be a problem.

Related