Re: exceptions, internals (introspection?)

2005-11-10 Thread Fernando Perez
ej wrote: > I have often wondered how to get at other internals, such as the name of > the current function, file, line number I am in? The arguments to the > current function, etc. I browsed through the table of contents of both the > Library Reference & Language Reference. I see section 18

Re: exceptions, internals (introspection?)

2005-11-10 Thread Paul Rubin
"ej" writes: > for key in dir(traceback_): > print "traceback_.%s =" % key, eval("traceback_.%s" % key) Don't use eval for this. Use getattr(traceback_, key). > traceback_.tb_frame = > traceback_.tb_lasti = 18 > traceback_.tb_lineno = 6 > traceback_.tb_next = None Yeah. As /F men

Re: exceptions, internals (introspection?)

2005-11-10 Thread ej
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > the second example on this page shows you how to do that: > > http://effbot.org/librarybook/traceback I am looking at it. Thanks for your prompt reply, Mr. Lundh! :) -ej -- http://mail.python.org/mailman/listinf

Re: exceptions, internals (introspection?)

2005-11-10 Thread ej
"Paul Rubin" wrote in message news:[EMAIL PROTECTED] > It's messy. Look at sys.exc_info() and go from there. Yeah, I think I am starting to see what you mean... #! /usr/local/bin/python import sys try: {}['foo'] except Exception, x: print "class of x =", x._

Re: exceptions, internals (introspection?)

2005-11-10 Thread Paul McNett
ej wrote: > I have often wondered how to get at other internals, such as the name of > the current function, file, line number I am in? The arguments to the > current function, etc. Others have given you information on how to get at the stack trace. But regarding getting at some of the othe

Re: exceptions, internals (introspection?)

2005-11-10 Thread Paul Rubin
"ej" writes: > I have often wondered how to get at other internals, such as the name of > the current function, file, line number I am in? The arguments to the > current function, etc. It's messy. Look at sys.exc_info() and go from there. -- http://mail.python.org/mailman/listinfo/python-

Re: exceptions, internals (introspection?)

2005-11-10 Thread Fredrik Lundh
"ej" <"ej atwellkeepercom"@bag.python.org> wrote > try: >{}['foo'] > except Exception, x: >print "class of x =", x.__class__ >print "type(x) =", type(x) >print "dir(x) =", dir(x) > >If you don't handle an exception, the interpreter will quit and print a > stack trace. What I'm

exceptions, internals (introspection?)

2005-11-10 Thread ej
I'm trying to figure out how to get at some of the internal interpreter state for exception handlers and debug statements in general. I just read through Section 8 of the Python Tutorial. I see how to catch an exception, and specify an optional argument to get ahold of the exception itself. For ex