Re: Change the identation base value?

2023-02-15 Thread Cameron Simpson

On 16Feb2023 04:20, Chris Angelico  wrote:

On Thu, 16 Feb 2023 at 04:18, scruel tao  wrote:

Currently, we have following PEP:
PEP 8: E114 indentation is not a multiple of 4 (comment)

However, I wonder how many people are using 2 spaces as their code indentation 
in projects? Should it be nesserary for us to change this PEP from “multiple of 
4” to “multiple of 2”?


Read PEP 8 itself before making a decision.

1) It is NOT rules for all Python code, only the standard library.
2) 
https://peps.python.org/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds

It is not necessary to change the PEP; it is necessary to fix tools
that claim more authority than they actually have.


Speaking as a 2-space indenter myself (in my personal code):

The tool in question is likely `pycodestyle`, whose _default_ linting 
measures PEP8 criteria among other things.


I run a few different linters (via a script named "lint") and turn off 
quite a few of the `pycodestyle` checks, `E114` included.


`pycodestyle` doesn't clean any special "authority", and exlicitly 
offers ways to turn off whichever checks you find unsuitable to your 
code.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: LRU cache

2023-02-15 Thread Dino



Thank you Mats, Avi and Chris

btw, functools.lru_cache seems rather different from what I need, but 
maybe I am missing something. I'll look closer.


On 2/14/2023 7:36 PM, Mats Wichmann wrote:

On 2/14/23 15:07, Dino wrote:




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


Re: Python: How to use the 'trace' module programmatically?

2023-02-15 Thread Weatherby,Gerard
Have you tried the filter options?

“These options may be repeated multiple times.
--ignore-module=
Ignore each of the given module names and its submodules (if it is a package). 
The argument can be a list of names separated by a comma.
--ignore-dir=
Ignore all modules and packages in the named directory and subdirectories. The 
argument can be a list of directories separated by 
os.pathsep.”



From: Python-list  on 
behalf of Peter Slížik 
Date: Wednesday, February 15, 2023 at 12:22 PM
To: python-list@python.org 
Subject: Python: How to use the 'trace' module programmatically?
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

Hello,

I'm trying to analyze complex Python code. For some specific reasons, I
decided to use tracing instead of a debugger.

The first thing I tried was:

python -m trace -t /path/to/file.py

The output of this command turned out to be completely useless. The reason
is that there was a thread running in the background, doing some work
every *0.1
s* and this generated thousands of lines of tracing information. The useful
information (a reaction to my interaction with app GUI) scrolled away in a
blink.

For this reason, I decided to limit the scope of tracing. I did the
following.

The original code:

def caller():
print("I'm the caller.")
callee()
def callee():
print("Callee here.")

Code modified for tracing:

import trace

tracer = trace.Tracer(
count=0,
trace=1,
)
def outer():
print("I'm the caller.")
tracer.runfunc(inner)
def inner():
print("Callee here.")

Now I launched the program and the tracer did not generate any output. I
was hoping that this would provide complete tracing information, but only
for the limited scope of inner().

No success with tracer.run() either.

What I was able to do, when I set count=1, I was able to catch the coverage
data with tracer.results() and write them to a file. But the tracing
information was not generated even in this case.

Am I doing anything wrong?

Peter
--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!m_WsH0rFVMLw4RMkVvcu-ZoClOMWVTsdB8E99Qy5Sq7ZZF1iBw5_NpLvorEe3_hYvy2kdDwe2obDr1E2ZjFCM3Of$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Change the identation base value?

2023-02-15 Thread Chris Angelico
On Thu, 16 Feb 2023 at 04:18, scruel tao  wrote:
>
> Currently, we have following PEP:
> PEP 8: E114 indentation is not a multiple of 4 (comment)
>
> However, I wonder how many people are using 2 spaces as their code 
> indentation in projects? Should it be nesserary for us to change this PEP 
> from “multiple of 4” to “multiple of 2”?
>

Read PEP 8 itself before making a decision.

1) It is NOT rules for all Python code, only the standard library.
2) 
https://peps.python.org/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds

It is not necessary to change the PEP; it is necessary to fix tools
that claim more authority than they actually have.

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


Add angle brackets for required args in argparse

2023-02-15 Thread scruel tao
If we have the following code:
```
parser = argparse.ArgumentParser(description="test")
parser.add_argument('path')
```

Run it without args, will get error message:
```
usage: test.py [-h] path
test.py: error: the following arguments are required: path
```

However, I hope the message can be as the following:
```
usage: test.py [-h] 
test.py: error: the following arguments are required: path
```

Or might can consider to provide a way to let user have there own style, like:
```
usage: test.py [-h] path
```

Thanks.

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


Python: How to use the 'trace' module programmatically?

2023-02-15 Thread Peter Slížik
Hello,

I'm trying to analyze complex Python code. For some specific reasons, I
decided to use tracing instead of a debugger.

The first thing I tried was:

python -m trace -t /path/to/file.py

The output of this command turned out to be completely useless. The reason
is that there was a thread running in the background, doing some work
every *0.1
s* and this generated thousands of lines of tracing information. The useful
information (a reaction to my interaction with app GUI) scrolled away in a
blink.

For this reason, I decided to limit the scope of tracing. I did the
following.

The original code:

def caller():
print("I'm the caller.")
callee()
def callee():
print("Callee here.")

Code modified for tracing:

import trace

tracer = trace.Tracer(
count=0,
trace=1,
)
def outer():
print("I'm the caller.")
tracer.runfunc(inner)
def inner():
print("Callee here.")

Now I launched the program and the tracer did not generate any output. I
was hoping that this would provide complete tracing information, but only
for the limited scope of inner().

No success with tracer.run() either.

What I was able to do, when I set count=1, I was able to catch the coverage
data with tracer.results() and write them to a file. But the tracing
information was not generated even in this case.

Am I doing anything wrong?

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


Change the identation base value?

2023-02-15 Thread scruel tao
Currently, we have following PEP:
PEP 8: E114 indentation is not a multiple of 4 (comment)

However, I wonder how many people are using 2 spaces as their code indentation 
in projects? Should it be nesserary for us to change this PEP from “multiple of 
4” to “multiple of 2”?

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


Re: LRU cache

2023-02-15 Thread Mats Wichmann

On 2/14/23 15:07, Dino wrote:


Here's my problem today. I am using a dict() to implement a quick and 
dirty in-memory cache.


I am stopping adding elements when I am reaching 1000 elements (totally 
arbitrary number), but I would like to have something slightly more 
sophisticated to free up space for newer and potentially more relevant 
entries.


I am thinking of the Least Recently Used principle, but how to implement 
that is not immediate. Before I embark on reinventing the wheel, is 
there a tool, library or smart trick that will allow me to remove 
elements with LRU logic?


It depends here how fancy you want to get.  If you really need the 
behavior of a size-limited cache and you expect there to be a lot of 
churn, then you'll probably want a combination of data structures... 
e.g. a dict-like thing for quick hashed lookups (means your "keys" need 
to be hashable) and a doubly-linked list for ordering so you can quickly 
move a hit to the most-recent position - and maybe you want to keep 
cache stats as well.


Do look at functools if that well-tested standard library module fits 
your needs. If you need, or are motivated (as a learning experience?) to 
roll your own, my memory tells me the RealPython crew did a tutorial on 
implementing an LRU cache, might be worth a look (not sure if this is 
one of the all-free ones, or one of the 
must-be-a-paid-subscriber-to-get-the-advanced-stuff ones.



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


Re: Precision Tail-off?

2023-02-15 Thread Weatherby,Gerard
All languages that use IEEE floating point will indeed have the same 
limitations, but it is not true that Python3 only uses IEEE floating point. 
Using the Decimal class and cribbing a method from StackOverflow, 
https://stackoverflow.com/questions/47191533/how-to-efficiently-calculate-cube-roots-using-decimal-in-python


import decimal
from decimal import Decimal

decimal.getcontext().prec = 1_000_000


def cube_root(A: Decimal):
guess = (A - Decimal(1)) / Decimal(3)
x0 = (Decimal(2) * guess + A / Decimal(guess * guess)) / Decimal(3.0)
while 1:
xn = (Decimal(2) * x0 + A / Decimal(x0 * x0)) / Decimal(3.0)
if xn == x0:
break
x0 = xn
return xn


float_root = 5 ** (1.0 / 3)
float_r3 = float_root * float_root * float_root
print(5 - float_r3)
five = Decimal(5.0)
r = cube_root(five)
decimal_r3 = r * r * r
print(5 - decimal_r3)


8.881784197001252e-16
1E-99

From: Python-list  on 
behalf of Michael Torrie 
Date: Tuesday, February 14, 2023 at 5:52 PM
To: python-list@python.org 
Subject: Re: Precision Tail-off?
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

On 2/14/23 00:09, Stephen Tucker wrote:
> I have two questions:
> 1. Is there a straightforward explanation for this or is it a bug?
To you 1/3 may be an exact fraction, and the definition of raising a
number to that power means a cube root which also has an exact answer,
but to the computer, 1/3 is 0.333 repeating in decimal,
which is some other fraction in binary.  And even rational numbers like
0.2, which are precise and exact, are not in binary
(0.01010101010101010101).  0.2 is .0011011011011011011 on and on forever.

IEEE floating point has very well known limitations.  All languages that
use IEEE floating point will be subject to these limitations.  So it's
not a bug in the sense that all languages will exhibit this behavior.

> 2. Is the same behaviour exhibited in Python 3.x?
Yes. And Java, C++, and any other language that uses IEEE floating point.

--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!jjhLqksliV_IjxQAHxXvdnOLB00sJU_hfHNIfK2U1NK-yO2X2kOxJtk6nbqEzXZkyOPBOaMdIlz_sHGkpA$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Changing the original SQLite version to the latest

2023-02-15 Thread jose isaias cabrera
On Tue, Feb 14, 2023 at 8:55 PM Thomas Passin  wrote:
>
> On 2/14/2023 3:30 PM, jose isaias cabrera wrote:
> > Greetings.
> >
> > I have tried both Cygwin and SQLite support, and I have received very
> > little ideas from them, so I am trying this to see if anyone has dealt
> > with such a problem before.
> >
> > If I use Cygwin setup tool and install python39 and thus,
> >
> > $ python
> > Python 3.9.10 (main, Jan 20 2022, 21:37:52) [GCC 11.2.0] on cygwin
> > Type "help", "copyright", "credits" or "license" for more information.
>  import sqlite3
>  sqlite3.sqlite_version
> > '3.34.0'
> 
> >
> > As you can see, the SQlite3 version installed is v3.34.0. Right now,
> > the version available is 3.40.1. What I would like to do is to work
> > with the latest SQLite version. I have 4 Cygwin instances, 2 of them
> > are working ok, 2 are not. This is what I have done to get python to
> > use 3.41.0:
> > - downloaded the latest SQlite check-in from the site
> > - $ tar -xvf SQLite-44200596.tar.gz
> > - cd to SQLite-44200596
> > - $ ./configure --prefix=/usr
> > - $ make install
> >
> > These steps above have worked on two PCs, but I don't know what is the
> > difference that makes the other two work, and the other two not work.
> > I have started a few instances of Cygwin on the PC that is not
> > working, and I have been trying for a few days, and I am humbling
> > myself, and asking for help. So, the request is to get python3 to
> > change the SQLite3 library from 3.34.0 to 3.41.0. Any help would be
> > greatly appreciated. Since this is Windows 10, it's probably some
> > SQLite DLL somewhere that is being pulled instead of the one
> > installed. Perhaps some of you can provide a few suggestions to see
> > where I can  find a solution. I know the next step is to compile
> > python, but, I rather try to find how to fix this and get to the
> > bottom of it. Thanks, thanks and thanks.
>
> As a point of reference, the Python installation I've got on my Windows
> box (not a cygwin install) is
>
> Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec  6 2022, 20:01:21) [MSC v.1934
> 64 bit (AMD64)] on win32
>
> and the sqlite_version is 3.39.4



In case anyone needs the answer, These steps worked for me:

In case anyone needs the answer, what worked for me was:
-- Downloaded the Pre-release Snapshots
$ wget https://sqlite.org/snapshot/sqlite-snapshot-202302131932.tar.gz
-- untared the snapshot
$ tar xvf sqlite-snapshot-202302131932.tar.gz
-- cd to the untared directory
$ cd sqlite-snapshot-202302131932
$ ./configure --prefix=/usr
$ make install

And this process has set the python SQLite version to the
sqlite-snapshot version. After that, you can download the trunk and
follow the same procedure, and the version of the trunk will be
changed also.

$ ./SQLiteVersion.py
3.41.0
['/usr/lib/python3.9/sqlite3']
3.41.0
2023-02-13 19:32:40
ecdeef43b27412b0b0b09e09a62ad3a03836a3fc80f2070268090e7ca8f02712

I hope this helps.

This script may be useful...
$ cat SQLiteVersion.py
#!/usr/bin/python3
import sqlite3

def ConnectToSharedDB(sdb):
return sqlite3.connect(sdb)

print(sqlite3.sqlite_version)
print(sqlite3.__path__)
SharedDB = ":memory:"
con = ConnectToSharedDB(SharedDB)
cur = con.cursor()
cur.execute("SELECT sqlite_version(),sqlite_source_id();")
for row in cur:
print(row[0] + '\r\n' + row[1])

con.close()

-- 

What if eternity is real?  Where will you spend it?  H...
-- 
https://mail.python.org/mailman/listinfo/python-list