[Tutor] A simple Question...

Noufal Ibrahim noufal at airtelbroadband.in
Tue Oct 2 20:43:45 CEST 2007


bhaaluu wrote:
> On 10/2/07, Kent Johnson <kent37 at tds.net> wrote:
>> traceback.print_stack() prints the stack trace to the current point of
>> execution. No forced error or drama needed :-)
>>
>> Kent
> 
> Exactly how is this used, please?
> 
> Traceback (most recent call last):
>   File "print_stack.py", line 160, in ?
>     print traceback.print_stack()
> NameError: name 'traceback' is not defined
> 
> It seems I should be able to insert a line, something like
>     print traceback.print_stack()
> in my code wherever I want to print the stack trace?

Make sure you import the traceback module before you do anything.

 >>>
 >>>
 >>> import traceback
 >>> def foo():
...   traceback.print_stack()
...
 >>>
 >>> foo()
   File "<stdin>", line 1, in <module>
   File "<stdin>", line 2, in foo
 >>>

-- 
~noufal
http://nibrahim.net.in/


More information about the Tutor mailing list