Configuring an object via a dictionary

Roel Schroeven roel at roelschroeven.net
Sat Mar 16 08:12:58 EDT 2024


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 at 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.

-- 
"This planet has - or rather had - a problem, which was this: most of the
people living on it were unhappy for pretty much of the time. Many solutions
were suggested for this problem, but most of these were largely concerned with
the movement of small green pieces of paper, which was odd because on the whole
it wasn't the small green pieces of paper that were unhappy."
         -- Douglas Adams


More information about the Python-list mailing list