Paul Rubin wrote:
Steven D'Aprano <st...@remove-this-cybersource.com.au> writes:
def assemble_page(header, body, footer):
if header or body or footer:
do_lots_of_expensive_processing()
else:
do_nothing_gracefully()
Why should the processing be expensive if all three fields are empty?
if header or body or footer:
is a huge improvement over:
if (header != '') or (body != '') or (footer != ''):
Doesn't really seem any better. There's always something like
if any(p != '' for p in [header, body, footer, otherthing1, ...])
if the number of components gets larger.
Or if any(p for p in [header, body, footer, whatever, ...])
Which is even nicer! :) Particularly if header, et al, are some more
complicated objects which don't easily generate strings, but do easily
know whether they are Something or Nothing.
I suppose some of these discussions are based more on one's personal
requirements (using several languages, just a couple, or just Python),
and whether one wants to achieve Mastery of Python, or just be
Proficient. Neither choice is wrong, and wanting Mastery, of course,
does not mean not wanting improvements, etc. It does, however, require
a deep understanding of not just the mechanics, but the philosophy of
the language.
Mind you, I am nowhere near Mastery just yet (okay, okay, I have a
_long_ way to go! ;), but I love the philosophy of Python, it's
simplicity, and the *entirety* of the Zen.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list