For review: PEP 308 - If-then-else expression
Andrew Dalke
adalke at mindspring.com
Sat Feb 8 20:16:24 EST 2003
Samuele Pedroni:
> I sympathize but the question is really what you prefer your target group
to
> encounter:
>
> 1) sys.exit(errs and 1 or 0)
> style = bold and "bold" or "italic"
>
> or
>
> 2) sys.exit(1 if errs else 0)
> style = "bold" if bold else "italic"
>
> because (1) idioms are used in practice.
Huh? I would prefer neither. I would rather have
if errs:
sys.exit(1)
sys.exit(0)
or even
sys.exit(errs)
(which works just fine if 'errs' is a string, and it even prints
the message to stderr!)
and
style_names = {
BOLD: "bold",
ITALICS: "italics",
UNDER: "undescore",
}
print style_names[style]
or possibly even
print style.name
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list