How to enter multiple, similar, dictionaries?
Piergiorgio Sartor
piergiorgio.sartor.this.should.not.be.used at nexgo.REMOVETHIS.de
Mon Dec 11 14:05:16 EST 2023
On 11/12/2023 16.16, Chris Green wrote:
> Is there a way to abbreviate the following code somehow?
>
> lv = {'dev':'bbb', 'input':'1', 'name':'Leisure volts'}
> sv = {'dev':'bbb', 'input':'0', 'name':'Starter volts'}
> la = {'dev':'bbb', 'input':'2', 'name':'Leisure Amps'}
> sa = {'dev':'bbb', 'input':'3', 'name':'Starter Amps'}
> bv = {'dev':'adc2', 'input':0, 'name':'BowProp Volts'}
>
> It's effectively a 'table' with columns named 'dev', 'input' and
> 'name' and I want to access the values of the table using the variable
> name.
>
> I could, obviously, store the data in a database (sqlite), I have some
> similar data in a database already but the above sort of format in
> Python source is more human readable and accessible. I'm just looking
> for a less laborious way of entering it really.
>
Maybe a dict of dicts:
tx = {lv: {'dev':'bbb', 'input':'1', 'name':'Leisure volts'},
sv: {'dev':'bbb', 'input':'0', 'name':'Starter volts'},
...}
Might have one or two advantages.
bye,
--
piergiorgio
More information about the Python-list
mailing list