Giles, you keep mentioning syntax errors as the (/a) cause of the problem. I suggest you avoid such problems, so that the import sethook approach, et al. will actually work. The easiest thing to do is to run PyChecker on your script prior to executing it. PyChecker will catch your syntax errors (and a whole host of other things, some of which are actual problems, some not) and let you know where they are. With that simple bit of testing, the other approaches that rely on a syntactically-correct script will work, because you will have corrected the syntax errors.
You *will* have corrected the syntax errors, right? :) -- http://mail.python.org/mailman/listinfo/python-list