pythonのソースコードを読むコツのようなもの 続き

pythonのソースコードを読むコツのようなもので書いた.pythonrc.pyにさらに追加して以下のような感じに。

import rlcompleter, readline
readline.parse_and_bind('tab: complete')

import inspect
import string
igd = inspect.getdoc
igs = inspect.getsource
igf = inspect.getfile
igsl = inspect.getsourcelines

def getsourcewithline(object):
  lines, lnum = igsl(object)
  lineswithlnum = []
  for l in lines:
    linewithlnum = str(lnum) + ' ' + l
    lineswithlnum.append(linewithlnum)
    lnum += 1
  return string.join(lineswithlnum, '')
igswl = getsourcewithline

で、実行すると以下のように出来るようになった。あとはソースコードハイライト出来たらいいんだけど...ま、いいか。

>>> print igswl(igs)
550 def getsource(object):
551     """Return the text of the source code for an object.
552
553     The argument may be a module, class, method, function, traceback, frame,
554     or code object.  The source code is returned as a single string.  An
555     IOError is raised if the source code cannot be retrieved."""
556     lines, lnum = getsourcelines(object)
557     return string.join(lines, '')

ところで今更気づいたけど、djangoでmanage.py shellしたとき~/.pythonrc.pyが読み込まれてないような...orz