Friday, November 16, 2012

Quick look into Python default modules

Have you ever seen code in Python default modules, let's take a look:

First, find out where are they with "locate" command:

hvn@lappy: / $ locate subprocess
/usr/lib/python2.7/subprocess.py
/usr/lib/python2.7/subprocess.pyc

we've locate subprocess module, which has a name specific enough. All python default module are in /usr/lib/python2.7/


you will see many .py and .pyc file there, but we only need .py file to dive into source code. Run bellow command to find  out how big they are:

hvn@lappy: /usr/lib/python2.7 $ for i in *.py; do wc -l $i; done | sort -n | cat -n | less

got this, so impressive, there are close to 30 file with COL < 100:

     1  1 __phello__.foo.py
     2  3 struct.py
     3  4 antigravity.py
     4  7 sitecustomize.py
     5  13 sre.py
     6  14 md5.py
     7  15 sha.py
     8  17 new.py
     9  18 dbhash.py
    10  18 statvfs.py
    11  28 this.py
    12  36 tty.py
    13  41 dircache.py
    14  48 user.py
    15  49 sunaudio.py
    16  55 mutex.py
    17  65 atexit.py
    18  66 nturl2path.py
    19  78 dummy_threading.py
    20  78 glob.py
    21  84 types.py
    22  85 anydbm.py
    23  88 UserList.py
    24  90 commands.py
    25  92 bisect.py
    26  93 keyword.py
    27  96 stat.py
    28  97 macurl2path.py
    29  98 io.py
    30  100 functools.py

dive in them, they are gem on your computer, no need to go anywhere!

No comments: