GNU Info

Info Node: (python2.1-lib.info)Traceback Example

(python2.1-lib.info)Traceback Example


Prev: traceback Up: traceback
Enter node , (file) or (file)node

Traceback Example
-----------------

This simple example implements a basic read-eval-print loop, similar to
(but less useful than) the standard Python interactive interpreter
loop.  For a more complete implementation of the interpreter loop,
refer to the `code' module.

     import sys, traceback
     
     def run_user_code(envdir):
         source = raw_input(">>> ")
         try:
             exec source in envdir
         except:
             print "Exception in user code:"
             print '-'*60
             traceback.print_exc(file=sys.stdout)
             print '-'*60
     
     envdir = {}
     while 1:
         run_user_code(envdir)


automatically generated by info2www version 1.2.2.9