statement level resumable exception
Jon Clements
joncle at googlemail.com
Fri Jan 21 07:20:26 EST 2011
On Jan 21, 8:41 am, ilejn <ilja.golsht... at gmail.com> wrote:
> Arnaud,
>
> it looks like a solution.
> Perhaps it is better than plain try/accept and than proxy class with
> __getattr__.
> It is not for free, e.g. because syntax check such as parentheses
> matching is lazy too, though looks
> very interesting.
>
> Thanks a lot!
>
> On Jan 21, 10:41 am, Arnaud Delobelle <arno... at gmail.com> wrote:
>
>
>
> > ilejn <ilja.golsht... at gmail.com> writes:
> > > Arnaud,
>
> > > these lists are not generated.
>
> > > Actually these lists are a sort of interpreted programs and contain
> > > some application logic.
>
> > > Here is an example
> > > [
> > > [PUSH, [get_modified_interface, req]],
> > > [TIMEOUT, 3],
> > > [PULL, [out_interface, '']],
> > > [PULL, [err_interface, '']],
> > > [PULL, [out_mined_interface, req]],
> > > ]
>
> > > If any interface name is unknown the list must not be invoked (in
> > > other words, f function
> > > call with this list must be somehow bypassed).
>
> > > Thanks.
>
> > You could still use the same idea and delay evaluation of the lists. E.g.
>
> > prg1 = """[
> > [PUSH, [get_modified_interface, req]],
> > [TIMEOUT, 3],
> > ...
> > """
>
> > prg2 = """[
> > [OPCODE, [arguments, blah]],
> > ...
> > """
>
> > ...
>
> > prgN = """..."""
>
> > for prg in prg1, prg2, ..., prgN:
> > try:
> > prg = eval(prg)
> > except NameError:
> > continue
> > f(prg)
>
> > --
> > Arnaud
>
> Best regards,
> Ilja Golshtein
Not sure if a good idea or not, but:
I would probably use pyparsing and create a small grammar to parse
your list data. If parsing an entry with an unknown interface, then
skip to the next list entry. If the entire list parses, then you can
execute your function calls.
hth
Jon.
More information about the Python-list
mailing list