statement level resumable exception

Arnaud Delobelle arnodel at gmail.com
Thu Jan 20 14:58:17 EST 2011


ilejn <ilja.golshtein at gmail.com> writes:

> Hello!
>
> I have a sequence of a function calls. Basically it looks like
>
> f(arg1)
> f(arg2)
> ...
> f(argN)
>
> though real arguments are complex multilayer lists.
>
> The problem is some arguments are not known and I get NameError
> exceptions.
>
> The solutions I know
> 1. wrap every f call in try/except block
> 2. make (currently global) argument attributes of a class and use
> __getattr__ to convert unknown attributes to something recognizable by
> f.

for name in 'arg1', 'arg2', ... 'argN':
    try:
        arg = globals()[name]
    except NameError:
        continue
    f(arg)

But this is a strange problem...  Sounds like you should do it
differently.

-- 
Arnaud



More information about the Python-list mailing list