On 2024-03-20 at 09:49:54 +0100,
Roel Schroeven via Python-list wrote:
> You haven't only checked for None! You have rejected *every* falsish value,
> even though they may very well be acceptable values.
OTOH, only you can answer these questions about your situations.
Every application, every i
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
It's too complicated, there's no need for this
def __init__(self, config):
self.__dict__ = config
self.connection = None
"""
other code .
"""
Note that you need to keep the fields in the config dict named the same as
the fields you want to be assigne
Tobiah writes:
> I should mention that I wanted to answer your question,
> but I wouldn't actually do this. I'd rather opt for
> your self.config = config solution. The config options
> should have their own namespace.
>
> I don't mind at all referencing foo.config['option'],
> or you could mak
I should mention that I wanted to answer your question,
but I wouldn't actually do this. I'd rather opt for
your self.config = config solution. The config options
should have their own namespace.
I don't mind at all referencing foo.config['option'],
or you could make foo.config an object by its
On 3/15/24 02:30, Loris Bennett wrote:
Hi,
I am initialising an object via the following:
def __init__(self, config):
self.connection = None
self.source_name = config['source_name']
self.server_host = config['server_host']
However, with a view to asking forg
dn wrote:
>Loris Bennett wrote:
>> However, with a view to asking forgiveness rather than
>> permission, is there some simple way just to assign the dictionary
>> elements which do in fact exist to self-variables?
>
>Assuming config is a dict:
>
> self.__dict__.update( config )
Here's anothe
alpha, _, _ = dict_to_vars(**mydict)
The above is really just keeping alpha.
Of course if the possible keys are not known in advance, this does not work but
other languages that allow this may be better for your purpose.
-Original Message-
From: Python-list On
Behalf Of Peter J. Holzer via Py
On 18/03/24 04:11, Peter J. Holzer via Python-list wrote:
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 +, Barry via Python-list wrote:
On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
wrote
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 +, Barry via Python-list wrote:
> > > > On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
> > > > wrote:
> > > > I've always like writing using
On 17/03/24 12:06, Peter J. Holzer via Python-list wrote:
On 2024-03-16 08:15:19 +, Barry via Python-list wrote:
On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
wrote:
I've always like writing using the "or" form and have never gotten bit
I, on the other hand, had to fix a prod
On 2024-03-16 08:15:19 +, Barry via Python-list wrote:
> > On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
> > 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.
>
On 16/03/24 21:15, Barry via Python-list wrote:
On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
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 beca
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
wrote:
> > I've always like writing using the "or" form and have never gotten
bit
I, on the other hand, had to fix a p
Barry via Python-list schreef op 16/03/2024 om 9:15:
> On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
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
> On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
> 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.
Barry
--
htt
of control.
-Original Message-
From: Python-list On
Behalf Of Dan Sommers via Python-list
Sent: Friday, March 15, 2024 5:33 PM
To: python-list@python.org
Subject: Re: Configuring an object via a dictionary
On 2024-03-15 at 15:48:17 -0400,
Thomas Passin via Python-list wrote:
> [...] And I sup
On 3/15/2024 5:33 PM, Dan Sommers via Python-list wrote:
On 2024-03-15 at 15:48:17 -0400,
Thomas Passin via Python-list wrote:
[...] And I suppose there is always the possibility that sometime in
the future an "or" clause like that will be changed to return a
Boolean, which one would expect an
On 15/03/24 22:30, Loris Bennett via Python-list wrote:
Hi,
I am initialising an object via the following:
def __init__(self, config):
self.connection = None
self.source_name = config['source_name']
self.server_host = config['server_host']
self.server_
On 2024-03-15 at 15:48:17 -0400,
Thomas Passin via Python-list wrote:
> [...] And I suppose there is always the possibility that sometime in
> the future an "or" clause like that will be changed to return a
> Boolean, which one would expect anyway.
Not only is the current value is way more usefu
On 3/15/2024 3:09 PM, Grant Edwards via Python-list wrote:
On 2024-03-15, Thomas Passin via Python-list wrote:
On 3/15/2024 5:30 AM, Loris Bennett via Python-list wrote:
Hi,
I am initialising an object via the following:
def __init__(self, config):
self.connection = None
On 2024-03-15, Thomas Passin via Python-list wrote:
> On 3/15/2024 5:30 AM, Loris Bennett via Python-list wrote:
>> Hi,
>>
>> I am initialising an object via the following:
>>
>> def __init__(self, config):
>>
>> self.connection = None
>>
>> self.source_name = config['so
On 3/15/2024 5:30 AM, Loris Bennett via Python-list wrote:
Hi,
I am initialising an object via the following:
def __init__(self, config):
self.connection = None
self.source_name = config['source_name']
self.server_host = config['server_host']
self.serv
On 3/15/24 03:30, Loris Bennett via Python-list wrote:
Hi,
I am initialising an object via the following:
self.source_name = config['source_name']
config.get('source_name', default_if_not_defined) is a common technique...
--
https://mail.python.org/mailman/listinfo/python-list
24 matches
Mail list logo