Re: sum() vs. loop

2021-10-11 Thread Dan Stromberg
On Mon, Oct 11, 2021 at 2:54 PM Steve Keller  wrote:

> I have found the sum() function to be much slower than to loop over the
> operands myself:
>
> def sum_products(seq1, seq2):
> return sum([a * b for a, b in zip(seq1, seq2)])
>
> def sum_products2(seq1, seq2):
> sum = 0
> for a, b in zip(seq1, seq2):
> sum += a * b
> return sum
>
> In a program I generate about 14 million pairs of sequences of ints each
> of length 15 which need to be summed.  The first version with sum() needs
> 44 seconds while the second version runs in 37 seconds.
>
> Can someone explain this difference?
>
I can't explain it.  It might help to try a line-by-line profiler.

If you need speed, maybe try Cython, numpy and/or numba.

It seems like the generator expression should be the fastest to me.  But
writing for speed instead of writing for clarity is usually not a great
idea.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: spyder does not work under root! [linux]

2021-10-11 Thread Michael Torrie
On 10/8/21 4:32 PM, Paulo da Silva wrote:
> Às 22:56 de 08/10/21, Paulo da Silva escreveu:
>> Hi!
>>
>> I need to debug a python3 script under root. I tried spyder but it does
>> not work.
>>
>> Running as root without --no-sandbox is not supported. See
>> https://crbug.com/638180.
>>
>> Thanks for any comments including alternative solutions to debug as root.
>>
> I also tried with eric and curiously it gave the same message!!
> 
> This seems crazy.

Not so crazy. It's incredibly dangerous to run a web browser as root.
There's no reason I can think of for running a python script driving a
web browser as root.  Python scripts can easily be run as an arbitrary
user, perhaps from a bash wrapper script using su, or being started from
systemd.

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


Re: Beginner problem, please help. Building a simple menu + lists , cannot print list

2021-10-11 Thread Chris Angelico
On Tue, Oct 12, 2021 at 9:13 AM Felix Kjellström
 wrote:
>
> Hello! Please see the link to the code I have uploaded to my account at 
> replit.com
>
> https://replit.com/join/lftxpszwrv-felixkjellstrom

Unfortunately, it's not public. Are you able to put the code on GitHub
as a repository or gist, or in some other public hosting?
Alternatively, can you make it short enough to simply include here in
your post?

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


Re: Assign a value to a var content in an object

2021-10-11 Thread Chris Angelico
On Tue, Oct 12, 2021 at 9:03 AM Paulo da Silva
 wrote:
>
> Hello!
>
> Is there a better way of doing this?
> Why didn't setattr (as commented) work?
>
> Thanks for an help/comments.
>
> class C:
> def f(self,v):
> #setattr(self,n,v)
> self.__dict__['n']=v
>
> c=C()
> c.f(3)
> print(c.n)
>

Because setattr needs a string, just like the assignment to the
dictionary does. Try:

setattr(self, "n", v)

Or, since it's a constant:

self.n = v

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


Re: sum() vs. loop

2021-10-11 Thread Chris Angelico
On Tue, Oct 12, 2021 at 9:02 AM Stefan Ram  wrote:
>
> Steve Keller  writes:
> >Now completely surprised.
>
>   I have observed that here the generator-based sum() call
>   is slower if both seq1 and seq2 have a length of 1000, but
>   faster if both seq1 and seq2 have 1000 entries each
>   (with float entries).
>
>   However, in any case, the direct for-loop still is fastest.
>   Maybe, calling "next()" (actually, "PyIter_Next" in C) on
>   an iterator has some overhead compared to just evaluating
>   an expression in a loop.
>

There's overhead whichever way you do it, and ultimately, it depends
on what you're doing. The genexp is effectively a callback into Python
code. The list comp requires preconstruction of the entire list. The
plain for loop involves summing by picking up and putting down in
Python code rather than doing that in C. The only way to know which is
fastest is to try them all :)

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


Beginner problem, please help. Building a simple menu + lists , cannot print list

2021-10-11 Thread Felix Kjellström
Hello! Please see the link to the code I have uploaded to my account at 
replit.com

https://replit.com/join/lftxpszwrv-felixkjellstrom

Problem:

When you select the menu option "Add buyer", you can enter three values. See 
code line 5, "def Add_buyer ():"

Then, you use the arrow keys to select the menu option "See list of buyers". 
When you do that the values you just entered should be printed. See code line 
23, "def See_list_of_buyers ():

The problem is that the list is DON'T gets printed.

Problem:

When you select the menu option "Add buyer", you can enter three values. See 
code line 5, "def Add_buyer ():"

Then, you use the arrow keys to select the menu option "See list of buyers". 
When you do that the values you just entered should be printed. See code line 
23, "def See_list_of_buyers ():

The problem is that the list is DON'T gets printed.

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


Re: sum() vs. loop

2021-10-11 Thread Chris Angelico
On Tue, Oct 12, 2021 at 8:55 AM Steve Keller  wrote:
>
> I have found the sum() function to be much slower than to loop over the
> operands myself:
>
> def sum_products(seq1, seq2):
> return sum([a * b for a, b in zip(seq1, seq2)])
>
> def sum_products2(seq1, seq2):
> sum = 0
> for a, b in zip(seq1, seq2):
> sum += a * b
> return sum
>
> In a program I generate about 14 million pairs of sequences of ints each
> of length 15 which need to be summed.  The first version with sum() needs
> 44 seconds while the second version runs in 37 seconds.
>
> Can someone explain this difference?
>

When you use sum, you're constructing a list. Try removing the square brackets:

return sum(a * b for a, b in zip(seq1, seq2))

It's also possible that the genexp has more overhead than simply
iterating directly, but at very least, this will reduce the memory
consumption.

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


Re: Assign a value to a var content in an object

2021-10-11 Thread Paulo da Silva
Às 23:28 de 10/10/21, Stefan Ram escreveu:
> Paulo da Silva  writes:
>> class C:
>>def f(self,v):
>>#setattr(self,n,v)
>>self.__dict__['n']=v
> 
>> Why didn't setattr (as commented) work?
> 
>   Because the name n has not been initialized to a suitable
>   value in the function f. You could write
> 
> setattr( self, "n", v )
Ah, OK - I missed the "" around n! :-(
> 
>   , but if you want this,
> 
> self.n = v
> 
>   would be better.
Of course :-)
But that's not the purpose. This is just a toy example.

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


Re: spyder does not work under root! [linux]

2021-10-11 Thread Chris Angelico
On Tue, Oct 12, 2021 at 8:52 AM Paulo da Silva
 wrote:
>
> Hi!
>
> I need to debug a python3 script under root. I tried spyder but it does
> not work.
>
> Running as root without --no-sandbox is not supported. See
> https://crbug.com/638180.
>
> Thanks for any comments including alternative solutions to debug as root.
>

Did you try reading the linked bug report? Or running it with --no-sandbox?

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


Assign a value to a var content in an object

2021-10-11 Thread Paulo da Silva
Hello!

Is there a better way of doing this?
Why didn't setattr (as commented) work?

Thanks for an help/comments.

class C:
def f(self,v):
#setattr(self,n,v)
self.__dict__['n']=v

c=C()
c.f(3)
print(c.n)

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


Re: sum() vs. loop

2021-10-11 Thread Steve Keller
Christian Gollwitzer  writes:

> > def sum_products(seq1, seq2):
> >  return sum([a * b for a, b in zip(seq1, seq2)])
> > def sum_products2(seq1, seq2):
> >  sum = 0
> >  for a, b in zip(seq1, seq2):
> >  sum += a * b
> >  return sum
> > [...]
>
> The first version constructs a list, sums it up and throws the list
> away, while the second version only keeps the running sum in
> memory. How about a generator expression instead, i.e.
> 
> 
>  sum((a * b for a, b in zip(seq1, seq2)))

Ah, of course.  Much cleaner and I should have seen that myself.
Thanks.

BUT

> (untested) ?

I have tested it and with () instead of [] it's even slower:

   explicit loop:   37s   ± .5s
   sum([...])   44s   ± .5s
   sum((...))   47.5s ± .5s

Now completely surprised.

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


Re: sum() vs. loop

2021-10-11 Thread Christian Gollwitzer

Am 10.10.21 um 10:49 schrieb Steve Keller:

I have found the sum() function to be much slower than to loop over the
operands myself:

def sum_products(seq1, seq2):
 return sum([a * b for a, b in zip(seq1, seq2)])

def sum_products2(seq1, seq2):
 sum = 0
 for a, b in zip(seq1, seq2):
 sum += a * b
 return sum

In a program I generate about 14 million pairs of sequences of ints each
of length 15 which need to be summed.  The first version with sum() needs
44 seconds while the second version runs in 37 seconds.


The first version constructs a list, sums it up and throws the list 
away, while the second version only keeps the running sum in memory. How 
about a generator expression instead, i.e.



sum((a * b for a, b in zip(seq1, seq2)))

(untested) ?

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


Re: spyder does not work under root! [linux]

2021-10-11 Thread Paulo da Silva
Às 22:56 de 08/10/21, Paulo da Silva escreveu:
> Hi!
> 
> I need to debug a python3 script under root. I tried spyder but it does
> not work.
> 
> Running as root without --no-sandbox is not supported. See
> https://crbug.com/638180.
> 
> Thanks for any comments including alternative solutions to debug as root.
> 
I also tried with eric and curiously it gave the same message!!

This seems crazy.
-- 
https://mail.python.org/mailman/listinfo/python-list


sum() vs. loop

2021-10-11 Thread Steve Keller
I have found the sum() function to be much slower than to loop over the
operands myself:

def sum_products(seq1, seq2):
return sum([a * b for a, b in zip(seq1, seq2)])

def sum_products2(seq1, seq2):
sum = 0
for a, b in zip(seq1, seq2):
sum += a * b
return sum

In a program I generate about 14 million pairs of sequences of ints each
of length 15 which need to be summed.  The first version with sum() needs
44 seconds while the second version runs in 37 seconds.

Can someone explain this difference?

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


spyder does not work under root! [linux]

2021-10-11 Thread Paulo da Silva
Hi!

I need to debug a python3 script under root. I tried spyder but it does
not work.

Running as root without --no-sandbox is not supported. See
https://crbug.com/638180.

Thanks for any comments including alternative solutions to debug as root.

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


installazione numpy

2021-10-11 Thread stefano felli
l'installazione di numpy con
pip install numpy
fornisce errore
Building wheel for numpy (PEP 517)

 ERROR: Failed building wheel for numpy
Failed to build numpy
ERROR: Could not build wheels for numpy which use PEP 517 and cannot be
installed directly


A cosa è dovuto e come devo fare per installare anche scipy che non riesce?
Grazie
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: HELP - uninstall pyton error

2021-10-11 Thread Michel

give more details

OS, Python Version, Method of installation.. etc..


On 10/7/21 17:18, Almadar Plus wrote:

Could you please help me uninstall python?
see attached screenshots files
Regards

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


nrfutil icorrect installation

2021-10-11 Thread Gerhard van Rensburg
Dear python,

 

I installed Python 3.10.0

I then install

pip install nrfutil

 

When I try to run nrfutil, I get

ModuleNotFoundError: No module named 'constants'

 

C:\Users\ x\nrfutil keys --help

Traceback (most recent call last):

  File "C:\Users\Gerhard van
Rensburg\AppData\Local\Programs\Python\Python310\Scripts\nrfutil-script.py",
line 33, in 

sys.exit(load_entry_point('nrfutil==5.2.0', 'console_scripts',
'nrfutil')())

  File "C:\Users\Gerhard van
Rensburg\AppData\Local\Programs\Python\Python310\Scripts\nrfutil-script.py",
line 25, in importlib_load_entry_point

return next(matches).load()

  File "C:\Users\Gerhard van
Rensburg\AppData\Local\Programs\Python\Python310\lib\importlib\metadata\__in
it__.py", line 162, in load

module = import_module(match.group('module'))

  File "C:\Users\Gerhard van
Rensburg\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py",
line 126, in import_module

return _bootstrap._gcd_import(name[level:], package, level)

  File "", line 1050, in _gcd_import

  File "", line 1027, in _find_and_load

  File "", line 1006, in
_find_and_load_unlocked

  File "", line 688, in _load_unlocked

  File "", line 883, in exec_module

  File "", line 241, in
_call_with_frames_removed

  File "C:\Users\Gerhard van
Rensburg\AppData\Local\Programs\Python\Python310\lib\site-packages\nordicsem
i\__main__.py", line 53, in 

from nordicsemi.dfu.dfu_transport_serial import DfuTransportSerial

  File "C:\Users\Gerhard van
Rensburg\AppData\Local\Programs\Python\Python310\lib\site-packages\nordicsem
i\dfu\dfu_transport_serial.py", line 52, in 

from nordicsemi.lister.device_lister import DeviceLister

  File "C:\Users\Gerhard van
Rensburg\AppData\Local\Programs\Python\Python310\lib\site-packages\nordicsem
i\lister\device_lister.py", line 39, in 

from nordicsemi.lister.windows.lister_win32 import Win32Lister

  File "C:\Users\Gerhard van
Rensburg\AppData\Local\Programs\Python\Python310\lib\site-packages\nordicsem
i\lister\windows\lister_win32.py", line 43, in 

from constants import DIGCF_PRESENT, DEVPKEY, DIGCF_DEVICEINTERFACE

ModuleNotFoundError: No module named 'constants'

 

Any help appreciated

 

Gerhard van Rensburg

___
RENIX

Electronics, Inc.

*713-503-0855 * Fax: 281-517-0773

*    www.Renix-Electronics.com
Email:   i...@renix-electronics.com


_

**All communications should be considered RENIX Confidential**

 

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