On 2008-11-07 11:48, [EMAIL PROTECTED] wrote: > On Nov 7, 11:20 am, Steven D'Aprano <[EMAIL PROTECTED] > cybersource.com.au> wrote: > >>> What I am trying to do is to execute it "step-by-step", so that I can >>> capture the exception if one line (or multi-line statement) fails, print >>> a warning about the failure, and continue the execution fo the following >>> lines/statements. Of course, an error on one line can trigger errors in >>> the following lines, but it does not matter in the application I have in >>> mind, >> I'm curious what sort of application you have where it doesn't matter >> that programmatic statements are invalid. > > Well, it is not that it does not matter, it is that I'd like to get as > much as possible of the input file "executed". > The application is roughly to save a graph, and retrieve it later. > The graph is made of a set of python classes, derived from a GraphNode > instance but each having particular sets of new attributes. > The storage format should be human readable and editable (this is why > a simple pickle or equivalent is not OK), store only part of the > database, and automatically reflect the changes of the classes (new > attributes in old classes, new classes, ...). The format I used was > "simply" instructions that re-create the graph... > > It works, but could be robust accross changes (basically, an old > database read with new version of the application should > recreate as much nodes as possible, with new attributes intialized at > default value). The node classes allows that, but during the parsing > when attributes names or classes names have changed, some errors can > happen, which will not only affect those nodes but stop execution. In > many cases, even with those error, executing the rest of the commands > will re-create an usefull graph, of course lacking some informations > but much more usefull that the partial graph obtained when stopping at > the first error... > >> So basically you want to create a Python interpreter you can stop and >> start which runs inside Python. Is that right? > > Yep, and the InteractiveConsole works very nicely for doing that :-)
Instead of creating a Python interpreter in Python (using e.g. PyPy ... http://www.pypy.org/), you might want to look at using a trace function using sys.settrace(): http://www.python.org/doc/2.5.2/lib/module-sys.html These functions are called for every line the Python interpreter executes and have full access to the stack, variables, etc. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 07 2008) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ :::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 -- http://mail.python.org/mailman/listinfo/python-list