Saturday, October 11, 2008

Python code reading

I made a presentation at a meeting called "Python code reading" held by a Python community in Japan. It's a meeting to read one standard Python module each time (a volunteer makes a presentation) to steal knowledge and techniques by reading scripts written by Python gurus. We read inspect module this time.

Here are several topics I mentioned during the code reading.

- basic usage of inspect module
- method generation mechanism by descriptor and decorator
- custom import (PEP302, which is used by importing zipped modules)
- code object and its meaning
- various special attributes (co_filelineno etc.)
- .pyo file
- file open mode 'U'
- imp module
- negative lookbehind assertion
- method resolution order
- how to clear the cache of the source code which is used by inspect.getsource(), etc.
(if the cache is kept uncleared, getsource() etc. still returns an old source after you modify the script and reload the module)

And what I studied during its preparation (but not talked during the presentation) are

- Python VM and byte code
- disassembling using dis module
- Python dev bug tracking

I didn't mention VM related stuff so that the meeting wouldn't be only for experts (and there was no time to explain them anyway).

2 comments:

Xupeng said...

Hi, do you have video or presentation for the meeting?

hohehohe2 [at] gmail.com said...

Xupeng,

Written document is on
http://groups.google.com/group/python-code-reading/files
but it's not a video and written in Japanese