Loading select queries into objects

Alex Martelli aleaxit at yahoo.com
Wed Jun 20 09:11:29 EDT 2001


"Graham Ashton" <graham at coms.com> wrote in message
news:xKYX6.1456$h45.9220 at news.uk.colt.net...
> 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)

there should be a linebreak after ',name' and before 'else:' -- sorry if the
error was in my post, can't understand how it got there...

> 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).

I agree, and the best connection of such pointers about the standard
Python library is IMHO Fredrik Lundh's "Python Standard Library", just
published by O'Reilly.  It doesn't _substitute_ for Python's excellent
online docs (what would be the point?) but it _supplements_ them with
270 pages of brief, colloquial-tone discussion and, mostly, short, effective
examples of "how to *USE*" each module in the library.


Alex






More information about the Python-list mailing list