Sujet : Re: Configuring an object via a dictionary
De : hjp-python (at) *nospam* hjp.at (Peter J. Holzer)
Groupes : comp.lang.pythonDate : 17. Mar 2024, 00:06:06
Autres entêtes
Message-ID : <mailman.105.1710630375.3452.python-list@python.org>
References : 1 2 3
Pièces jointes : signature.asc (application/pgp-signature) On 2024-03-16 08:15:19 +0000, Barry via Python-list wrote:
On 15 Mar 2024, at 19:51, Thomas Passin via Python-list <python-list@python.org> wrote:
I've always like writing using the "or" form and have never gotten bit
I, on the other hand, had to fix a production problem that using “or” introducted.
I avoid this idiom because it fails on falsy values.
Perl has a // operator (pronounced "err"), which works like || (or),
except that it tests whether the left side is defined (not None in
Python terms) instead of truthy. This still isn't bulletproof but I've
found it very handy.
hp
-- _ | Peter J. Holzer | Story must make more sense than reality.|_|_) | || | | hjp@hjp.at | -- Charles Stross, "Creative writing__/ | http://www.hjp.at/ | challenge!"