Trying to get started with Python functions and behavior through source code

I want to be able to explore and track through the Python source code to see how everything works under the hood, and resolve doubts about functions that are not explicitly documented in the reference document.

I would like some background information on how to do this because it is pretty overwhelming. I can read C, so for me this is happening for me. In addition, the task seems a little intimidating without even a small amount of guidance.

For example, let's say I wanted to document how an attribute reference is implemented in Python. How can I track what happens when an attribute reference expression is present in a Python program?

Perhaps a review of how the source code is organized and what each part will be useful, along with some examples of "walk = thru", for example, "case reference".

I was looking for information about this, but it seems not so much.

+6
source share
2 answers

Perhaps a good Python debugger will help? I would try using the PyDev plugin for Eclipse . This will at least help you determine which special python methods (e.g. __getattr__() or __setattr__() ) are called when a class attribute is referenced. If you need to go deeper, you can look at the Python C API or even the Python C Source Code .

+1
source

The python standard library has a trace module. It has several modes and can be used to print each line of python code, as it runs as follows:

 python -m trace -t myscript.py 

See http://docs.python.org/library/trace.html

+1
source

All Articles