0

Is there a pypi module or an equivalent to log everything python does while executing a script, say if a django app is rendering a page I want to have an account of everything like from where a custom template tag is getting loaded, which module(and from where on the pythonpath) is called and things like that.I want to use it to understand pre existing codes and also debugging purposes. May be everyone else is aware of how to do it except me.

Kamal Reddy
  • 2,610
  • 5
  • 28
  • 36

1 Answers1

3

You can use the trace module to analyze execution. An example snippet:

$ python -m trace --trace euler32.py | head
 --- modulename: euler32, funcname: <module>
euler32.py(4): from itertools import permutations
euler32.py(6): digits = range(1,10)
euler32.py(7): positions = range(1,9)
euler32.py(9): for c in permutations(digits,9):
euler32.py(10):     for x in positions:
euler32.py(11):         for equal in positions[x:]:

pdb is the standard debugging tool.

Eduardo Ivanec
  • 11,668
  • 2
  • 39
  • 42
  • That may work, although it will take you a *long* time to get to the bit you're trying to debug. For Django I'd use `pdb` instead. Refer to this question: http://stackoverflow.com/questions/1118183/how-to-debug-in-django-the-good-way. – Eduardo Ivanec Mar 12 '12 at 19:06