Re: How to enter multiple, similar, dictionaries?

2023-12-11 Thread Piergiorgio Sartor via Python-list

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

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to enter multiple, similar, dictionaries?

2023-12-11 Thread Chris Green via Python-list
Jon Ribbens  wrote:
> On 2023-12-11, Chris Green  wrote:
> > 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.
> >> 
> > Or, more sensibly, make the above into a list (or maybe dictionary)
> > of dictionaries:-
> >
> > adccfg = [
> > {'abbr':'lv', 'dev':'bbb', 'input':'1', 'name':'Leisure volts'},
> > {'abbr':'sv', 'dev':'bbb', 'input':'0', 'name':'Starter volts'},
> > {'abbr':'la', 'dev':'bbb', 'input':'2', 'name':'Leisure Amps'},
> > {'abbr':'sa', 'dev':'bbb', 'input':'3', 'name':'Starter Amps'},
> > {'abbr':'bv', 'dev':'adc2', 'input':0, 'name':'BowProp Volts'}
> > ]
> >
> > This pickles nicely, I just want an easy way to enter the data!
> 
> adccfg = [
> dict(zip(('abbr', 'dev', 'input', 'name'), row))
> for row in (
> ('lv', 'bbb', '1', 'Leisure volts'),
> ('sv', 'bbb', '0', 'Starter volts'),
> ('la', 'bbb', '2', 'Leisure Amps'),
> ('sa', 'bbb', '3', 'Starter Amps'),
> ('bv', 'adc2', 0, 'BowProp Volts'),
> )
> ]

Neat, I like that, thank you.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to enter multiple, similar, dictionaries?

2023-12-11 Thread Jon Ribbens via Python-list
On 2023-12-11, Chris Green  wrote:
> 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.
>> 
> Or, more sensibly, make the above into a list (or maybe dictionary)
> of dictionaries:-
>
> adccfg = [
> {'abbr':'lv', 'dev':'bbb', 'input':'1', 'name':'Leisure volts'},
> {'abbr':'sv', 'dev':'bbb', 'input':'0', 'name':'Starter volts'},
> {'abbr':'la', 'dev':'bbb', 'input':'2', 'name':'Leisure Amps'},
> {'abbr':'sa', 'dev':'bbb', 'input':'3', 'name':'Starter Amps'},
> {'abbr':'bv', 'dev':'adc2', 'input':0, 'name':'BowProp Volts'}
> ]
>
> This pickles nicely, I just want an easy way to enter the data!

adccfg = [
dict(zip(('abbr', 'dev', 'input', 'name'), row))
for row in (
('lv', 'bbb', '1', 'Leisure volts'),
('sv', 'bbb', '0', 'Starter volts'),
('la', 'bbb', '2', 'Leisure Amps'),
('sa', 'bbb', '3', 'Starter Amps'),
('bv', 'adc2', 0, 'BowProp Volts'),
)
]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to enter multiple, similar, dictionaries?

2023-12-11 Thread MRAB via Python-list

On 2023-12-11 15:57, Chris Green via Python-list wrote:

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.


Or, more sensibly, make the above into a list (or maybe dictionary)
of dictionaries:-

adccfg = [
 {'abbr':'lv', 'dev':'bbb', 'input':'1', 'name':'Leisure volts'},
 {'abbr':'sv', 'dev':'bbb', 'input':'0', 'name':'Starter volts'},
 {'abbr':'la', 'dev':'bbb', 'input':'2', 'name':'Leisure Amps'},
 {'abbr':'sa', 'dev':'bbb', 'input':'3', 'name':'Starter Amps'},
 {'abbr':'bv', 'dev':'adc2', 'input':0, 'name':'BowProp Volts'}
]

This pickles nicely, I just want an easy way to enter the data!


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.


How about:

keys = ['abbr', 'dev', 'input', 'name']
adccfg = [
('lv', 'bbb', '1', 'Leisure volts'),
('sv', 'bbb', '0', 'Starter volts'),
('la', 'bbb', '2', 'Leisure Amps'),
('sa', 'bbb', '3', 'Starter Amps'),
('bv', 'adc2', '0', 'BowProp Volts'),
]
adccfg = [dict(zip(keys, row)) for row in adccfg]

or even:

keys = ['abbr', 'dev', 'input', 'name']
adccfg = '''\
lv,bbb,1,Leisure volts
sv,bbb,0,Starter volts
la,bbb,2,Leisure Amps
sa,bbb,3,Starter Amps
bv,adc2,0,BowProp Volts
'''
adccfg = [dict(zip(keys, line.split(','))) for line in adccfg.splitlines()]

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to enter multiple, similar, dictionaries?

2023-12-11 Thread Grant Edwards via Python-list
On 2023-12-11, Chris Green via Python-list  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.

Named tuples stored in a dictionary or list?

> 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.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to enter multiple, similar, dictionaries?

2023-12-11 Thread Chris Green via Python-list
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.
> 
Or, more sensibly, make the above into a list (or maybe dictionary)
of dictionaries:-

adccfg = [
{'abbr':'lv', 'dev':'bbb', 'input':'1', 'name':'Leisure volts'},
{'abbr':'sv', 'dev':'bbb', 'input':'0', 'name':'Starter volts'},
{'abbr':'la', 'dev':'bbb', 'input':'2', 'name':'Leisure Amps'},
{'abbr':'sa', 'dev':'bbb', 'input':'3', 'name':'Starter Amps'},
{'abbr':'bv', 'dev':'adc2', 'input':0, 'name':'BowProp Volts'}
]

This pickles nicely, I just want an easy way to enter the data!

> 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.
> 
-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


How to enter multiple, similar, dictionaries?

2023-12-11 Thread Chris Green via Python-list
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.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


[Python-announce] ANN: numexpr 2.8.8 released

2023-12-11 Thread Francesc Alted

Announcing NumExpr 2.8.8


Hi everyone,

NumExpr 2.8.8 is a release to deal mainly with issues appearing with
upcoming `NumPy` 2.0.  Also, some small fixes (support for simple complex
expressions like `ne.evaluate('1.5j')`) and improvements are included.

Project documentation is available at:

http://numexpr.readthedocs.io/

Changes from 2.8.7 to 2.8.8
---

* Fix re_evaluate not taking global_dict as argument. Thanks to Teng Liu
  (@27rabbitlt).

* Fix parsing of simple complex numbers.  Now, `ne.evaluate('1.5j')` works.
  Thanks to Teng Liu (@27rabbitlt).

* Fixes for upcoming NumPy 2.0:

  * Replace npy_cdouble with C++ complex. Thanks to Teng Liu (@27rabbitlt).
  * Add NE_MAXARGS for future numpy change NPY_MAXARGS. Now it is set to 64
to match NumPy 2.0 value. Thanks to Teng Liu (@27rabbitlt).

What's Numexpr?
---

Numexpr is a fast numerical expression evaluator for NumPy.  With it,
expressions that operate on arrays (like "3*a+4*b") are accelerated
and use less memory than doing the same calculation in Python.

It has multi-threaded capabilities, as well as support for Intel's
MKL (Math Kernel Library), which allows an extremely fast evaluation
of transcendental functions (sin, cos, tan, exp, log...) while
squeezing the last drop of performance out of your multi-core
processors.  Look here for a some benchmarks of numexpr using MKL:

https://github.com/pydata/numexpr/wiki/NumexprMKL

Its only dependency is NumPy (MKL is optional), so it works well as an
easy-to-deploy, easy-to-use, computational engine for projects that
don't want to adopt other solutions requiring more heavy dependencies.

Where I can find Numexpr?
-

The project is hosted at GitHub in:

https://github.com/pydata/numexpr

You can get the packages from PyPI as well (but not for RC releases):

http://pypi.python.org/pypi/numexpr

Documentation is hosted at:

http://numexpr.readthedocs.io/en/latest/

Share your experience
-

Let us know of any bugs, suggestions, gripes, kudos, etc. you may
have.

Enjoy data!

-- 
Francesc Alted
___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com