Is there a way of better tracback reporting??

ed_tsang at ed_tsang at
Thu May 3 23:17:20 CEST 2001

hi I currentyl have the foloowing situation:

I am trying to execute a python function in file, from 
I also want this function execution can be turned on or off at, without commenting any code or changing any code other than 
the ENABLE_ME flag.

So I include a file that has a varable ENABLE_ME, which can be 
enabled or diabled, from file 

Since the attached code is the simplified version, the opeation is 
not continuous and can't show the user to enable or diable some 
function execution at run time. 

My problem is I want to print the traceback information just in case 
something like: the function to be executed cannot be found in Although I am able to print some info, it does not specify me 
the error is in instead it say from during exec(cmd). 

This may mislead user that the is the one in question. How can 
I point out the error is actually from 

Here is the attached code:


def a():
    print "A is executed\n"
def b():
    print "B is executed\n"


from inc import *



   import traceback, sys
   exec('import pix')
   if hasattr(pix,'ENABLE_ME') > 0:
      if pix.ENABLE_ME == 1:
         cmd = '%s.%s'%('pix','a()')
         print "hihiht"
         cmd = '%s.%s'%('pix','b()')
         cmd = '%s.%s'%('pix','c()')
except SyntaxError:
   exc = sys.exc_info()

A is executed

B is executed

Traceback (innermost last):
  File "", line 15, in ?
  File "<string>", line 1, in ?
AttributeError: c

See the error is saying in exec(cmd) in but the real problem 
is there is no c function in ....  :(  
I want to generalise this to include any type of error hapeend when 
executing functions in

More information about the Python-list mailing list