How to iterate through maildir messages in python 3?

2021-06-24 Thread Chris Green
In python 2 one can do:- for msg in maildir: print msg # or whatever you want to do with the message However in python 3 this produces "TypeError: string argument expected, got 'bytes'". How should one iterate over a maildir in python3? (I've been here before but this probl

round decimal values

2021-06-24 Thread jo
Hi, this code generate 4 values with gaussian distribution (mu=5, sigma=1): import numpy as np x = np.random.normal(5, 1, 4) print(x) Output: [5.87879753 3.29162433 3.83024698 4.92997148] I would like to round the output like this: [6, 3, 4, 5] What should I add to the code? Thank you j.

Re: round decimal values

2021-06-24 Thread jo
Il Thu, 24 Jun 2021 18:07:07 +0200, Julio Di Egidio ha scritto: > On 24/06/2021 16:23, jo wrote: >> Hi, >> >> this code generate 4 values with gaussian distribution (mu=5, sigma=1): >> >> import numpy as np x = np.random.normal(5, 1, 4) >> print(x) >> >> Output: >> [5.87879753 3.29162433 3.8302

Re: How to iterate through maildir messages in python 3?

2021-06-24 Thread Greg Ewing
On 25/06/21 7:06 am, Chris Green wrote: In python 2 one can do:- for msg in maildir: print msg # or whatever you want to do with the message However in python 3 this produces "TypeError: string argument expected, got 'bytes'". How should one iterate over a maildir in pytho

Re: creating raw AWS log event

2021-06-24 Thread Grant Edwards
On 2021-06-24, Larry Martell wrote: > On Wed, Jun 23, 2021 at 7:05 PM Dennis Lee Bieber > wrote: >> >> On Wed, 23 Jun 2021 10:42:42 -0700, Larry Martell >> declaimed the following: >> >> >def _decode(data): >> >compressed_payload = b64decode(data) >> >json_payload = zlib.decompress(comp

RE: Optimizing Small Python Code

2021-06-24 Thread Avi Gross via Python-list
Barry, I am not going to continue replying in this thread. I made my point and it was focused after a while on the size of the CODE. Of course, the code can be made ever smaller using gimmicks and yet run longer or use more memory or CPU. If you have control of a package with a short name l

Re: creating raw AWS log event

2021-06-24 Thread Larry Martell
On Thu, Jun 24, 2021 at 10:38 AM Larry Martell wrote: > > On Thu, Jun 24, 2021 at 12:20 AM Peter Otten <__pete...@web.de> wrote: > > > > On 23/06/2021 19:42, Larry Martell wrote: > > > When an AWS cloudwatch event is passed to a consumer it looks like this: > > > > > > { > > > "awslogs": { >

Re: Optimizing Small Python Code

2021-06-24 Thread Barry Scott
> On 24 Jun 2021, at 16:58, Avi Gross via Python-list > wrote: > > Now a has a length of 53! > > It now looks like this: > > b'x\x9c3\xe4R\x00\x03\x03.#8\x0bB\x1br\x19c\x88(\x18q\x99p!q\xc1\x00\xa6\xd1\x98\xcb\x14S\x03\x9a\n\x13.3\x82j > \xb4\t\x94\x86\x99\t\x00\xdc\x87\x14\xb7' > > So th

Re: Optimizing Small Python Code

2021-06-24 Thread jan via Python-list
You're right, I was making an academic point. I think this whole compression question relates to Kolmogorov complexity "In algorithmic information theory (a subfield of computer science and mathematics), the Kolmogorov complexity of an object,

Re: creating raw AWS log event

2021-06-24 Thread Larry Martell
On Thu, Jun 24, 2021 at 12:20 AM Peter Otten <__pete...@web.de> wrote: > > On 23/06/2021 19:42, Larry Martell wrote: > > When an AWS cloudwatch event is passed to a consumer it looks like this: > > > > { > > "awslogs": { > > "data": "ewogICAgIm1l..." > > } > > } > > > > To get

RE: Optimizing Small Python Code

2021-06-24 Thread Avi Gross via Python-list
Jan, As an academic discussion, yes, many enhancements only pay off when things are larger. And for most purposes, I/O is so much slower that it makes little difference. But on a multi-processing machine, extra CPU may impact how much else the machine can do at the same time. Here is an exam

Re: creating raw AWS log event

2021-06-24 Thread Peter Otten
On 23/06/2021 19:42, Larry Martell wrote: When an AWS cloudwatch event is passed to a consumer it looks like this: { "awslogs": { "data": "ewogICAgIm1l..." } } To get the actual message I do this: def _decode(data): compressed_payload = b64decode(data) json_paylo

Re: Optimizing Small Python Code

2021-06-24 Thread jan via Python-list
If I'm not mistaken, the original output is O(n^2) in quantity of chars, and as output time is proportional to the length of the output, that makes the output time also O(n^2) here too. So I guess this only looks like it's reduced to linear because the output here is very small. For large n it wou