Re: Configuring an object via a dictionary

Liste des GroupesRevenir à cl python 
Sujet : Re: Configuring an object via a dictionary
De : roel (at) *nospam* roelschroeven.net (Roel Schroeven)
Groupes : comp.lang.python
Date : 20. Mar 2024, 10:49:54
Autres entêtes
Message-ID : <mailman.121.1710924599.3452.python-list@python.org>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla Thunderbird
Op 19/03/2024 om 0:44 schreef Gilmeh Serda via Python-list:
On Mon, 18 Mar 2024 10:09:27 +1300, dn wrote:
>
YMMV!
NB your corporate Style Guide may prefer 'the happy path'...
>
If you only want to check for None, this works too:
>
name = None
dafault_value = "default"
name or default_value
'default'
name = 'Fred Flintstone'
name or default_value
'Fred Flintstone'
 >>> name = ''
 >>> name or default_value
'default'
 >>> name = False
 >>> name or default_value
'default'
 >>> name = []
 >>> name or default_value
'default'
 >>> name = 0
 >>> name or default_value
'default'
You haven't only checked for None! You have rejected *every* falsish value, even though they may very well be acceptable values.
--
"Most of us, when all is said and done, like what we like and make up
reasons for it afterwards."
         -- Soren F. Petersen

Date Sujet#  Auteur
17 Mar 24 * Re: Configuring an object via a dictionary3dn
20 Mar 24 +- Re: Configuring an object via a dictionary1Roel Schroeven
20 Mar 24 `- Re: Configuring an object via a dictionary12QdxY4RzWzUUiLuE

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal