elif alternative

gert gert.cuykens at gmail.com
Fri Sep 18 02:03:23 CEST 2009


On Sep 18, 12:18 am, gert <gert.cuyk... at gmail.com> wrote:
> On Sep 18, 12:12 am, gert <gert.cuyk... at gmail.com> wrote:
>
>
>
> > On Sep 18, 12:09 am, gert <gert.cuyk... at gmail.com> wrote:
>
> > > On Sep 17, 9:48 pm, Chris Rebert <c... at rebertia.com> wrote:
>
> > > > On Thu, Sep 17, 2009 at 12:38 PM, gert <gert.cuyk... at gmail.com> wrote:
> > > > > Can anybody show me a better looking alternative for this elif
> > > > > structure ?
>
> > > > Use a dictionary with functions as values. For example:
>
> > > > #untested obviously
> > > > def admin_remove(db, v, gid):
> > > >     db.execute("DELETE FROM appointments WHERE aid=?",(v['aid'],))
>
> > > > def guest_remove(db, v, gid):
> > > >     db.execute("DELETE FROM appointments WHERE aid=? AND
> > > > uid=?",(v['aid'],s.UID))
>
> > > > cmd_gid2func = {('remove', 'admin') : admin_remove, ('remove',
> > > > 'guest') : guest_remove}
>
> > > > func = cmd_gid2func[(v['cmd'], s.GID)]
> > > > func(db, v, s.GID)
>
> > > What about s.UID ?
>
> > Never mind :)
> > func(db, v, s.GID, s.UID)
>
> [(v['cmd'], s.GID)]
> Can s.GID be None ?

So far i have this
http://code.google.com/p/appwsgi/source/browse/appwsgi/wsgi/appointment.wsgi

I have 3 problems left Any_GID, Everybody_no_GID, and when no key
found do return




More information about the Python-list mailing list