"Kalle Svensson" <[EMAIL PROTECTED]> wrote
>> but only if the data is in scope. If it is local data within the
>> raising function then bit will be gone by the time you catch
>> the exception.
>
> Well, not entirely. If you look at the sys.exc_info() function there
> is a way to get the backtrace of the currently handled exception.
I knew you could get the backtrace but...
>>>> def a(x):
> ... l = 0
> ... print x/l
> ...
>>>> def b(y):
> ... c = 75
> ... a(y)
> ...
>>>> try:
> ... b(3)
> ... except:
> ... t,v,bt = sys.exc_info()
> ...
>>>> bt.tb_next.tb_frame.f_locals
> {'y': 3, 'c': 75}
...I didn't realize it included local variables(eg c) , I thought it
only had
the functions and the arguments passed. Interesting, and very useful.
Thanks for that,
Alan G
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor