Dan Sommers <[EMAIL PROTECTED]> wrote:
   ...
> Put the results into a dictionary (untested code follows!):
> 
>     l = [ (re1, 'bar'),
>           (re2, 'foo'),
>           (re3, 'baz'),
>         ]
>     results = {}
>     for (regexp, key) in l:
>         m = re.search(regexp, data)
>         if m:
>             results[key] = m.group(1)
> 
> Now you can access the results as results['foo'], etc.  Or look up the
> Borg pattern in the ASPN cookbook and you can access the results as
> results.foo, etc.

I think you mean the Bunch idiom, rather than the Borg one (which has to
do with having instances of the same class share state).

Personally, I would rather pass myvar as well as the attribute names,
and set them with setattr, as I see some others already suggested.


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to