Two question from a newbie
Joshua Macy
amused at webamused.com
Sat Feb 12 11:55:08 EST 2000
Jason Stokes wrote:
>
> Moshe Zadka wrote in message ...
>
> >
> >if x.mode in ("view", "modify"):
> > myMode = x.mode
>
> I don't see that this idiom has that much to recommend it. Mr Drake's
> version is clear in that we're comparing x.mode with two modes -- "view" and
> "modify". Your version attempts to *find* x.mode in the tuple ("view",
> "modify") and executes the sub-bock if successful. The intention of the
> first example is immediately apparent. The intention of the second is not
> so immediate, so it must lose out if you want to write maximally
> comprehendable code.
Consider what happens if you want to add another three modes
(particularly if this test occurs in other places in your code).
Something like:
modes = ("view", "modify", "debug", "modifyWithRollback")
if x.mode in modes:
myMode = x.mode
has it all over
if (x.mode == "view" or x.mode == "modify" or x.mode == "debug" or
x.mode == "modifyWithRollback"):
myMode = x.mode
IMO, of course.
Joshua
More information about the Python-list
mailing list