Sujet : Re: Configuring an object via a dictionary
De : list1 (at) *nospam* tompassin.net (Thomas Passin)
Groupes : comp.lang.pythonDate : 16. Mar 2024, 14:02:56
Autres entêtes
Message-ID : <mailman.103.1710594187.3452.python-list@python.org>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
On 3/16/2024 8:12 AM, Roel Schroeven via Python-list wrote:
Barry via Python-list schreef op 16/03/2024 om 9:15:
>
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.
>
Me too. It's just too fragile. When writing code you're going to need an alternative for cases where "config.get('source_name') or default_value" doesn't work correctly; much better to use that alternative for all cases.
Trying to remember when I've used it, that was probably on personal code where I had a good idea what the values could be. Otherwise, I'm in agreement.