Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

It is necessary to have purpose. -- Alice #1, "I, Mudd", stardate 4513.3


devel / comp.lang.python / Re: Configuring an object via a dictionary

SubjectAuthor
o Re: Configuring an object via a dictionaryPeter J. Holzer

1
Re: Configuring an object via a dictionary

<mailman.109.1710688315.3452.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=29674&group=comp.lang.python#29674

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: hjp-python@hjp.at (Peter J. Holzer)
Newsgroups: comp.lang.python
Subject: Re: Configuring an object via a dictionary
Date: Sun, 17 Mar 2024 16:11:53 +0100
Lines: 86
Message-ID: <mailman.109.1710688315.3452.python-list@python.org>
References: <b169e599-e81f-45ce-8e2a-7027b59a4627@tompassin.net>
<60E92E67-1412-4DE6-B330-495343107474@barrys-emacs.org>
<20240316230606.qjn5zepek645tsqq@hjp.at>
<98171cf7-c2ea-4496-8b68-fa9a8f247b3b@DancesWithMice.info>
<20240317151153.cgnsvd6hd7pb767r@hjp.at>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha512;
protocol="application/pgp-signature"; boundary="3two2jhfhbr2udgn"
X-Trace: news.uni-berlin.de DVRPsZtwxT6q5DiMcRIh0gDnTo3ufN4qsAq/ulGkfVnA==
Cancel-Lock: sha1:0qA6qnk7ikpUsw5+BRkm5HZZt4A= sha256:nlsHKKyLFJPnukMRvAh0inmJjb1FEtoEDZRPRKCPzlk=
Return-Path: <hjp-python@hjp.at>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; '(for': 0.05;
'content-type:multipart/signed': 0.05; 'mar': 0.07; 'tests': 0.07;
'content-type:application/pgp-signature': 0.09; 'fails': 0.09;
'filename:fname piece:asc': 0.09; 'filename:fname
piece:signature': 0.09; 'filename:fname:signature.asc': 0.09;
'meant': 0.09; 'values.': 0.09; 'syntax': 0.15; '"creative': 0.16;
'__/': 0.16; 'barry': 0.16; 'below).': 0.16; 'challenge!"': 0.16;
'from:addr:hjp-python': 0.16; 'from:addr:hjp.at': 0.16;
'from:name:peter j. holzer': 0.16; 'hand,': 0.16; 'hjp@hjp.at':
0.16; 'holzer': 0.16; 'idiom': 0.16; 'reality.': 0.16;
'self.name': 0.16; 'semantics': 0.16; 'stross,': 0.16; 'url-
ip:212.17.106/24': 0.16; 'url-ip:212.17/16': 0.16; 'url:hjp':
0.16; 'useful.': 0.16; '|_|_)': 0.16; 'wrote:': 0.16; 'problem':
0.16; 'python': 0.16; 'instead': 0.17; 'to:addr:python-list':
0.20; "i've": 0.22; 'lines': 0.23; "isn't": 0.27; 'else': 0.27;
'bit': 0.27; 'fact': 0.28; 'sense': 0.28; 'think': 0.32; 'gotten':
0.32; 'python-list': 0.32; 'but': 0.32; 'same': 0.34; 'header:In-
Reply-To:1': 0.34; 'meaning': 0.35; 'yes,': 0.35; 'fix': 0.36;
'those': 0.36; 'using': 0.37; 'two': 0.39; 'still': 0.40; 'from:':
0.62; 'received:212': 0.62; 'true': 0.63; 'similar': 0.65;
'received:userid': 0.66; 'url-ip:212/8': 0.69; 'production': 0.71;
'left': 0.83; 'exactly.': 0.84; 'received:at': 0.84
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <98171cf7-c2ea-4496-8b68-fa9a8f247b3b@DancesWithMice.info>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <20240317151153.cgnsvd6hd7pb767r@hjp.at>
X-Mailman-Original-References: <b169e599-e81f-45ce-8e2a-7027b59a4627@tompassin.net>
<60E92E67-1412-4DE6-B330-495343107474@barrys-emacs.org>
<20240316230606.qjn5zepek645tsqq@hjp.at>
<98171cf7-c2ea-4496-8b68-fa9a8f247b3b@DancesWithMice.info>
 by: Peter J. Holzer - Sun, 17 Mar 2024 15:11 UTC
Attachments: signature.asc (application/pgp-signature)

On 2024-03-17 17:15:32 +1300, dn via Python-list wrote:
> On 17/03/24 12:06, Peter J. Holzer via Python-list wrote:
> > 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.
>
>
> So, if starting from:
>
> def method( self, name=None, ):
>
> rather than:
>
> self.name = name if name else default_value
>
> ie
>
> self.name = name if name is True else default_value

These two lines don't have the same meaning (for the reason you outlined
below). The second line is also not very useful.

> the more precise:
>
> self.name = name if name is not None or default_value
>
> or:
>
> self.name = default_value if name is None or name

Those are syntax errors. I think you meant to write "else" instead of
"or".

Yes, exactly. That's the semantic of Perl's // operator.

JavaScript has a ?? operator with similar semantics (slightly
complicated by the fact that JavaScript has two "nullish" values).

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

Attachments: signature.asc (application/pgp-signature)
1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor