Re: Configuring an object via a dictionary (Posting On Python-List Prohibited)

Liste des GroupesRevenir à cl python 
Sujet : Re: Configuring an object via a dictionary (Posting On Python-List Prohibited)
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.python
Date : 15. Mar 2024, 22:09:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <ut2de5$2fd1e$5@dont-email.me>
References : 1
User-Agent : Pan/0.155 (Kherson; fc5a80b8)
On Fri, 15 Mar 2024 10:30:03 +0100, Loris Bennett wrote:

        self.source_name = config['source_name']
        self.server_host = config['server_host']
        self.server_port = config['server_port']
        self.user_base = config['user_base']
        self.user_identifier = config['user_identifier']
        self.group_base = config['group_base']
        self.group_identifier = config['group_identifier']
        self.owner_base = config['owner_base']
>
However, some entries in the configuration might be missing.

Since all the attribute names and dictionary keys are the same, the
solution is simple:

    for k in \
        (
            'source_name',
            'server_host',
            'server_port',
            'user_base',
            'user_identifier',
            'group_base',
            'group_identifier',
            'owner_base',
        ) \
    :
        if k in config :
            setattr(self, k, config[k])
        #end if
    #end for

Date Sujet#  Auteur
15 Mar 24 * Configuring an object via a dictionary15Loris Bennett
15 Mar 24 +- Re: Configuring an object via a dictionary1Mats Wichmann
15 Mar 24 +- Re: Configuring an object via a dictionary1Thomas Passin
15 Mar 24 +* Re: Configuring an object via a dictionary4Tobiah
15 Mar 24 i`* Re: Configuring an object via a dictionary3Tobiah
18 Mar 24 i `* Re: Configuring an object via a dictionary2Loris Bennett
19 Mar 24 i  `- Re: Configuring an object via a dictionary1Pokemon Chw
15 Mar 24 +- Re: Configuring an object via a dictionary1Grant Edwards
15 Mar 24 +- Re: Configuring an object via a dictionary1Thomas Passin
15 Mar 24 +- Re: Configuring an object via a dictionary (Posting On Python-List Prohibited)1Lawrence D'Oliveiro
15 Mar 24 +- Re: Configuring an object via a dictionary12QdxY4RzWzUUiLuE
16 Mar 24 +- Re: Configuring an object via a dictionary1dn
16 Mar 24 +- Re: Configuring an object via a dictionary1Thomas Passin
16 Mar 24 +- Re: Configuring an object via a dictionary1<avi.e.gross
18 Mar 24 `- Re: Configuring an object via a dictionary1Anders Munch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal