Name of type of object

Jive Dadson jdadson at yahoo.com
Wed Feb 9 16:57:15 EST 2005


I don't think I've quite got it.

The application I'm writing has some similarities to an interactive
shell.  Like an interactive shell, it executes arbitrary code that it
receives from an input stream.  When it gets an exception, it should
create an informative message, regardless of the type of exception.  The
traceback routine does that, somehow, some way, but I've tried to read
that code and figure out how and I don't get it.

The best I have so far is,

class Exec_thread(BG_thread):
	""" Execute a line of code in the global namespace. """
	def _process(s):
		""" Process one instruction """
		try:
			exec s.product in globals()
		except (Exception), e:
			handle_error( typename(e)+ ": " + str(e) )


But that works only if the exception happens to be derived from
Exception.  How do I handle the
general case?



More information about the Python-list mailing list