import traceback for line in traceback.format_stack(): print line.strip()
Source on StackOverflow.com