Loading select queries into objects

Graham Ashton graham at coms.com
Wed Jun 20 04:00:29 EDT 2001


In article <9gpgde02rc6 at enews1.newsguy.com>, "Alex Martelli"
<aleaxit at yahoo.com> wrote:

> Assuming you mean "on the current instance", there is absolutely no need
> for eval & friends -- the following will do just fine:
> 
>     def applydict(self, adict):
>         for name, value in adict.items():
>             try: method = getattr(self, name)
>             except AttributeError: print "Warning: no method",name else:
>             method(value)

That's much cleaner, thanks. I'm struggling my way around the standard
library at the moment trying to find out how things should be done;
pointers like that are incredibly useful, especially for people who are
used to doing it a different way in a different language (like me).

Graham



More information about the Python-list mailing list