Re: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API

2024-10-02 Thread Chris Angelico via Python-list
On Wed, 2 Oct 2024 at 23:53, Left Right via Python-list
 wrote:
> In the same email you replied to, I gave examples of languages for
> which parsers can be streaming (in general): SCSI or IP.

You can't validate an IP packet without having all of it. Your notion
of "streaming" is nonsensical.

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


Re: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API

2024-09-30 Thread Chris Angelico via Python-list
On Tue, 1 Oct 2024 at 08:56, Grant Edwards via Python-list
 wrote:
>
> On 2024-09-30, Dan Sommers via Python-list  wrote:
>
> > In Common Lisp, integers can be written in any integer base from two
> > to thirty six, inclusive.  So knowing the last digit doesn't tell
> > you whether an integer is even or odd until you know the base
> > anyway.
>
> I had to think about that for an embarassingly long time before it
> clicked.

The only part I'm not clear on is what identifies the base. If you're
going to write numbers little-endian, it's not that hard to also write
them with a base indicator before the digits. But, whatever. This is a
typical tangent and people are argumentative for no reason. I was just
trying to add some explanatory notes to why little-endian does make
more sense than big-endian.

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


Re: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API

2024-09-30 Thread Chris Angelico via Python-list
On Tue, 1 Oct 2024 at 04:30, Dan Sommers via Python-list
 wrote:
>
> But why do I need to start with the least
> significant digit?

If you start from the most significant, you don't know anything about
the number until you finish parsing it. There's almost nothing you can
say about a number given that it starts with a particular sequence
(since you don't know how MANY digits there are). However, if you know
the LAST digits, you can make certain statements about it (trivial
examples being whether it's odd or even).

It's not very, well, significant. But there's something to it. And it
extends nicely to p-adic numbers, which can have an infinite number of
nonzero digits to the left of the decimal:

https://en.wikipedia.org/wiki/P-adic_number

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


Re: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API

2024-09-30 Thread Chris Angelico via Python-list
On Tue, 1 Oct 2024 at 02:20, Thomas Passin via Python-list
 wrote:
>
> On 9/30/2024 11:30 AM, Barry via Python-list wrote:
> >
> >
> >> On 30 Sep 2024, at 06:52, Abdur-Rahmaan Janhangeer via Python-list 
> >>  wrote:
> >>
> >>
> >> import polars as pl
> >> pl.read_json("file.json")
> >>
> >>
> >
> > This is not going to work unless the computer has a lot more the 60GiB of 
> > RAM.
> >
> > As later suggested a streaming parser is required.
>
> Streaming won't work because the file is gzipped.  You have to receive
> the whole thing before you can unzip it. Once unzipped it will be even
> larger, and all in memory.

Streaming gzip is perfectly possible. You may be thinking of PKZip
which has its EOCD at the end of the file (although it may still be
possible to stream-decompress if you work at it).

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


Re: python3 package import difference?

2024-08-07 Thread Chris Angelico via Python-list
On Thu, 8 Aug 2024 at 03:40, Tobiah via Python-list
 wrote:
> The one under rcs.dbi contains:
>
>  from dbi import *
>  from regos import *
>

You probably want these to be package-relative now:

from .dbi import *
from .regos import *

Or, since you're using namespaced imports anyway ("rcs.dbi.feature"),
you may prefer this form:

from . import dbi, regos

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


Re: python C-api and thread

2024-08-05 Thread Chris Angelico via Python-list
On Tue, 6 Aug 2024 at 08:48, aotto1968 via Python-list
 wrote:
>
> hi,
>
> Is it possible to run two completely independent Python interpreters in one 
> process, each using a thread?
>
> By independent, I mean that no data is shared between the interpreters and 
> thus the C API can be used without any other
> "lock/GIL" etc.
>

You're probably thinking of subinterpreters:

https://peps.python.org/pep-0734/

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


Re: Best (simplest) way to share data

2024-07-11 Thread Chris Green via Python-list
Stefan Ram  wrote:
> Chris Green  wrote or quoted:
> >That's exactly the sort of solution I was wondering about.  Is there a
> >ready made module/library for handling this sort of thing?  Basically
> >it will just be a string of a few tens of characters that would be
> >kept up to date by one process and asked for by all the others.
> 
>   I'm not an expert here, and just quickly tried to make it
>   run, so the code will still contain errors and not contain
>   something necessary, but might give you a starting point.
> 
>   A process doing something (here: printing an incrementing value
>   named "info") and also serving requests from other processes
>   for this "info" value:
> 
[snip]

Thanks, that should get me started!  :-)

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


Re: Best (simplest) way to share data (Posting On Python-List Prohibited)

2024-07-08 Thread Chris Green via Python-list
Lawrence D'Oliveiro  wrote:
> On Sat, 6 Jul 2024 08:28:41 +0100, Chris Green wrote:
> 
> > One fairly obvious way is to have single process/script which reads the
> > A2D values continuously and writes them to a file.  All other scripts
> > then read from the file as needed, a simple file lock can then be used
> > to prevent simultaneous access (well, simultaneous access when the
> > writing process is writing).
> 
> The thing with a file is, it persists even when the collector process is 
> not running. Do you want data that persists when the collector process is 
> not running?
> 
> Is this a history of values, or just a snapshot of current values? A 
> history of values could be written to a database. Databases provide their 
> own transactions and interlocking to prevent readers from reading partial 
> updates.
> 
There's a separate (crontab driven) process that writes the history to
a sqlite3 database,


> If it’s a snapshot of current values, that does not persist when the 
> collector process is not running, then why not just keep the data in the 
> memory of the collector process, and have it concurrently listen on a 
> socket for connections from readers requesting a copy of the current data?

That's exactly the sort of solution I was wondering about.  Is there a
ready made module/library for handling this sort of thing?  Basically
it will just be a string of a few tens of characters that would be
kept up to date by one process and asked for by all the others.

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


Re: Best (simplest) way to share data between processes

2024-07-08 Thread Chris Green via Python-list
Piergiorgio Sartor 
 wrote:
> On 06/07/2024 09.28, Chris Green wrote:
> > I have a Raspberry Pi in my boat that uses I2C to read a number of
> > voltages and currents (using ADS1115 A2D) so I can monitor the battery
> > condition etc.
> > 
> > At present various different scripts (i.e. processes) just read the
> > values using the I2C bus whenever they need to but I'm pretty sure
> > this (quite rarely) results in false readings because two processes
> > try to read at the same time.
> > 
> > Thus I'm looking for ways to prevent simultaneous access.
> 
> Why using "different scripts"?
> Is it there any particular reason?
> 
> Maybe it would be better, if possible, to have
> a single script, which, sequentially, reads
> whatever needs to be read (or written).
> In a loop.
> 
> This is even simpler than using a file.
> 
Yes, but it's conceptually (and programming wise) much simpler to have
separate scripts.  Some of them are simple 'on demand' scripts that I
run from the command line when I want to know something.  Others are
scripts that drive displays on control panels.

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


Best (simplest) way to share data between processes

2024-07-07 Thread Chris Green via Python-list
I have a Raspberry Pi in my boat that uses I2C to read a number of
voltages and currents (using ADS1115 A2D) so I can monitor the battery
condition etc.

At present various different scripts (i.e. processes) just read the
values using the I2C bus whenever they need to but I'm pretty sure
this (quite rarely) results in false readings because two processes
try to read at the same time.

Thus I'm looking for ways to prevent simultaneous access.

One fairly obvious way is to have single process/script which reads
the A2D values continuously and writes them to a file.  All other
scripts then read from the file as needed, a simple file lock can then
be used to prevent simultaneous access (well, simultaneous access when
the writing process is writing).

Is this the simplest approach?  Are there better ways using
multiprocess?  (They look more complicated though).

The I2C bus itself has a mutex but I don't think this guarantees that
(for example) an A2D reading is atomic because one reading takes more
than one I2C bus access.

Would a mutex of some sort around each I2C transaction (i.e. complete
A2D reading) be a better way to go?

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


Re: Anonymous email users

2024-06-25 Thread Chris Angelico via Python-list
On Wed, 26 Jun 2024 at 03:40, Anton Shepelev via Python-list
 wrote:
>
> Chris Angelico to dn:
>
> > > Python mailing-lists are covered by the Code of Conduct
> > > and monitored by ListAdmins. Thus, there are controls
> > > which limit the impact which advertisers and others with
> > > non-pythonic aims might otherwise exert!
> >
> > So long as there's a newsgroup gateway, those controls are
> > toothless.
>
> The gateway operator can have the usual anti-spam software
> installed

Anti-spam is not the same as CoC and admins, though. Without putting
an actual moderation barrier in there, it's still toothless.

(Yes, there are a scant few posters who've been blocked from the
gateway, but it's rare.)

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


Re: Anonymous email users

2024-06-24 Thread Chris Angelico via Python-list
On Tue, 25 Jun 2024 at 11:41, Grant Edwards via Python-list
 wrote:
> I've been using the same e-mail address for about 20 years. I've use
> that e-mail address with probably close to 100 retailers, charities,
> open-source projects, media sites, and various other organizations.

Mostly the same, although in my case, I've had multiple email
addresses for different purposes (and still kept all of them for
decades).

> I get at most a few spam emails per week [I just checked my spam
> folder: 8 in the past 30 days]. And Gmail is very, very close to 100%
> accurate at filtering them out.  I can't remember the last time I
> actually got a spam message in my inbox.
>
> > A few years ago the spam count was greater than a 1,000 a month.
>
> I'm baffled.  Is Gmail silently rejecting that much junk before it
> even gets to the filter that puts stuff into my "spam" folder?
>

It really depends on how you count. On my mail server (can't get stats
for Gmail), I have a number of anti-spam and anti-abuse rules that
apply prior to the Bayesian filtering (for example, protocol
violations), and any spam that gets blocked by those rules isn't shown
in my stats. And then I have a further set of rules that nuke some of
the most blatant spam, and finally the regular trainable filter. I
should probably keep better stats on the stuff I don't keep, but at
the moment, all I actually track is the ones that the filter sees -
which is roughly 25-50 a day.

So yeah, Gmail is probably rejecting that much junk, but most of
it for protocol violations.

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


Re: Anonymous email users

2024-06-24 Thread Chris Angelico via Python-list
On Tue, 25 Jun 2024 at 08:31, dn via Python-list  wrote:
> Python mailing-lists are covered by the Code of Conduct and monitored by
> ListAdmins. Thus, there are controls which limit the impact which
> advertisers and others with non-pythonic aims might otherwise exert!
>

So long as there's a newsgroup gateway, those controls are toothless.

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


Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread Chris Angelico via Python-list
On Mon, 24 Jun 2024 at 10:18, MRAB via Python-list
 wrote:
> Tkinter in recent versions of Python can handle astral characters, at
> least back to Python 3.8, the oldest I have on my Windows PC.

Good to know, thanks! I was hoping that would be the case, but I don't
have a Windows system to check on, so I didn't want to speak without
facts.

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


Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread Chris Angelico via Python-list
On Mon, 24 Jun 2024 at 08:20, Rayner Lucas via Python-list
 wrote:
>
> In article ,
> ros...@gmail.com says...
> >
> > If you switch to a Linux system, it should work correctly, and you'll
> > be able to migrate the rest of the way onto Python 3. Once you achieve
> > that, you'll be able to operate on Windows or Linux equivalently,
> > since Python 3 solved this problem. At least, I *think* it will; my
> > current system has a Python 2 installed, but doesn't have tkinter
> > (because I never bothered to install it), and it's no longer available
> > from the upstream Debian repos, so I only tested it in the console.
> > But the decoding certainly worked.
>
> Thank you for the idea of trying it on a Linux system. I did so, and my
> example code generated the error:
>
> _tkinter.TclError: character U+1f40d is above the range (U+-U+)
> allowed by Tcl
>
> So it looks like the problem is ultimately due to a limitation of
> Tcl/Tk.
Yep, that seems to be the case. Not sure if that's still true on a
more recent Python, but it does look like you won't get astral
characters in tkinter on the one you're using.

> I'm still not sure why it doesn't give an error on Windows and

Because of the aforementioned weirdness of old (that is: pre-3.3)
Python versions on Windows. They were built to use a messy, buggy
hybrid of UCS-2 and UTF-16. Sometimes this got you around problems, or
at least masked them; but it wouldn't be reliable. That's why, in
Python 3.3, all that was fixed :)

> instead either works (when UTF-8 encoding is specified) or converts the
> out-of-range characters to ones it can display (when the encoding isn't
> specified). But now I know what the root of the problem is, I can deal
> with it appropriately (and my curiosity is at least partly satisfied).

Converting out-of-range characters is fairly straightforward, at least
as long as your Python interpreter is correctly built (so, Python 3,
or a Linux build of Python 2).

"".join(c if ord(c) < 65536 else "?" for c in text)

> This has given me a much better understanding of what I need to do in
> order to migrate to Python 3 and add proper support for non-ASCII
> characters, so I'm very grateful for your help!
>

Excellent. Hopefully all this mess is just a transitional state and
you'll get to something that REALLY works, soon!

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


Re: Decoding bytes to text strings in Python 2

2024-06-21 Thread Chris Angelico via Python-list
On Sat, 22 Jun 2024 at 03:28, Rayner Lucas via Python-list
 wrote:
> I'm curious about something I've encountered while updating a very old
> Tk app (originally written in Python 1, but I've ported it to Python 2
> as a first step towards getting it running on modern systems).
>
> I am using Python 2.7.18 on a Windows 10 system. If there's any other
> relevant information I should provide please let me know.

Unfortunately, you're running into one of the most annoying problems
from Python 2 and Windows: "narrow builds". You don't actually have
proper Unicode support. You have a broken implementation that works
for UCS-2 but doesn't actually support astral characters.

If you switch to a Linux system, it should work correctly, and you'll
be able to migrate the rest of the way onto Python 3. Once you achieve
that, you'll be able to operate on Windows or Linux equivalently,
since Python 3 solved this problem. At least, I *think* it will; my
current system has a Python 2 installed, but doesn't have tkinter
(because I never bothered to install it), and it's no longer available
from the upstream Debian repos, so I only tested it in the console.
But the decoding certainly worked.

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


Re: Anonymous email users

2024-06-14 Thread Chris Angelico via Python-list
On Sat, 15 Jun 2024 at 08:32, dn via Python-list  wrote:
> These mailing-lists all run under the Python Code of Conduct.
>

The newsgroup, however, is not. Which means that anyone who posts on
the newsgroup is subject to no such restrictions - and that might
explain the, shall we say, quite different signal-to-noise ratio of
newsgroup posters compared to mailing list posters.

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


Re: Couldn't install numpy on Python 2.7

2024-06-13 Thread Chris Green via Python-list
Chris Angelico  wrote:
> On Thu, 13 Jun 2024 at 10:58,  wrote:
> >
> > Chris,
> >
> > You seem to have perceived an insult that I remain unaware of.
> 
> If you're not aware that you're saying this, then don't say it.
> 
Er, um, that really makes no sense! :-)

How can one not say something that one isn't aware of saying?

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 10:58,  wrote:
>
> Chris,
>
> You seem to have perceived an insult that I remain unaware of.

If you're not aware that you're saying this, then don't say it.

> I looked up FUD and sharply disagree with suggestions I am trying to somehow
> cause Fear, Uncertainty or Doubt. I simply asked if another such update ...
> as a hypothetical. Had I asked what impact Quantum Computers might have on
> existing languages, would that also be FUD, or just a speculation in a
> discussion.

What DID you intend by your comments? Were you trying to imply that
work spent upgrading to Python 3 would have to be redone any day now
when this hypothetical massively-incompatible Python 4 is released? Or
what? What WERE you trying to say?

If you don't understand how damaging it can be to say that sort of
thing, **don't say it**. Otherwise, expect responses like this.

I *detest* the attitude that you can make vague disparaging comments
and then hide behind claims that you had no idea how damaging you were
being.

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 09:20,  wrote:
> My point was that version 4 COULD HAPPEN one day and I meant INCOMPATIBLE
> version not 4. Obviously we can make a version 4 that is not incompatible
> too.

This is still FUD. Back your words with something, or stop trying to
imply that there's another incompatible change just around the corner.

Do you realise how insulting you are being to the developers of Python
by these implications?

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 08:46, Oscar Benjamin via Python-list
 wrote:
> I don't know much about SSL and related networking things especially
> on Windows. I would be surprised if pip on old Python can't install
> from current PyPI though. I imagine that something strange has
> happened like a new version of pip running on an old version of Python
> or old Python on new OS (or old PyCharm...).
>
> There is no problem using Python 2.7 with pip and PyPI on this Linux
> machine but I guess it has a newer SSL library provided by the OS:

Sadly, I would NOT be surprised if this is indeed a problem on
Windows. You're exactly right - on Linux, it can use a newer SSL
library from the OS. Of course, this does assume that you've updated
your OS, which is far from a guarantee, but since this has security
implications there's a good chance you can update it while retaining a
legacy system.

On Thu, 13 Jun 2024 at 08:51, Greg Ewing via Python-list
 wrote:
> On 13/06/24 10:09 am, Chris Angelico wrote:
>  > So if anyone
>  > actually does need to use pip with Python 2.7, they probably need to
>  > set up a local server
>
> You should also be able to download a .tar.gz from PyPI and use pip
> to install that. Although you'll have to track down the dependencies
> yourself in that case.

Also a possibility; in my opinion, losing dependency management is too
big a cost, so I would be inclined to set up a local server. But then,
I would be using a newer SSL library and not have the problem in the
first place.

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 07:57, Oscar Benjamin via Python-list
 wrote:
> They are seeing a warning that explicitly says "You can upgrade to a
> newer version of Python to solve this". I don't know whether that SSL
> warning is directly connected to pip not finding any versions of numpy
> but with the available information so far that seems like the first
> thing to consider.

I think it is; AIUI, with an ancient SSL library, pip is unable to
download packages safely from the current pypi server. So if anyone
actually does need to use pip with Python 2.7, they probably need to
set up a local server, using older encryption protocols (which should
therefore NOT be made accessible to the internet). Since pip can't
contact the upstream pypi, there's no available numpy for it to
install.

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 07:36,  wrote:
> But if the goal was to deprecate python 2 and in some sense phase it out, it
> is perhaps not working well for some. Frankly, issuing so many updates like
> 2.7 and including backporting of new features has helped make it possible to
> delay any upgrade.

The goal was to improve Python. I don't think anyone's ever tried to
"kill off" Python 2 - not in the sense of stopping people from using
it - but there haven't been any changes, not even security fixes, in
over four years.

> And, yes, I was KIDDING about python 4. I am simply suggesting that there
> may well be a time that another shift happens that may require another
> effort to get people on board a new and perhaps incompatible setup.

Kidding, eh? It sure sounded like you were trying to imply that there
would inevitably be another major breaking change. It definitely
smelled like FUD.

Maybe your jokes just aren't funny.

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 06:55, Thomas Passin via Python-list
 wrote:
> The project cannot move to a Python-3 compatible version because Jython
> 3.xx doesn't exist and may never exist.  The saving grace is that my
> project doesn't have to use packages like numpy, scipy, and so forth.

Exactly. If you don't need to ALSO use something newer, there's
nothing stopping you from continuing with the old version. And that's
fine! As long as you're okay with not getting updates, you're welcome
to do whatever you like - including running Windows 98 on an ancient
PC and editing your documents on that. (Yes, I know someone who did
that, long after Win 98 was dead to most of us.)

> Thunderbird and everything else worked perfectly for me during that
> week.  True, there were a few Windows-only programs I missed, but I used
> other similar programs even if I didn't like them as much.

It's true. And there ARE solutions to that, although it's a bit rough
trying to run them on low hardware (Wine works nicely for some
programs, less so for others; VirtualBox is really not gonna be happy
with a small fraction of your limited RAM). But if your needs are
simple, even a crazily low-end system is sufficient.

> It's amazing
> how little resources Linux installs need, even with a GUI.  Of course,
> 4GB RAM is limiting whether you are on Linux or Windows - you can't
> avoid shuffling all those GUI bits around - but with a little care it
> worked great.  And with the external SSD the laptop was a lot snappier
> than it ever was when it was new.

One of the big differences with Linux is that you have a choice of
desktop environments, from "none" (just boot straight into a terminal)
on up. Some of them are a bit of a compromise in terms of how well you
can get your work done, but let's say you had an even MORE ancient
system with maybe one gig of memory... I'd rather have a super-light
desktop environment even if it doesn't have everything I'm normally
accustomed to!

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 03:41, AVI GROSS via Python-list
 wrote:
>
> Change is hard even when it may be necessary.
>
> The argument often is about whether some things are necessary or not.
>
> Python made a decision but clearly not a unanimous one.

What decision? To not release any new versions of Python 2? That isn't
actually the OP's problem here - the Python interpreter runs just
fine. But there's no numpy build for the OP's hardware and Python 2.7.

So if you want to complain about Python 2.7 being dead, all you have
to do is go through all of the popular packages and build binaries for
all modern computers. If that sounds easy, go ahead and do it; if it
sounds hard, realise that open source is not a democracy, and you
can't demand that other people do more and more and more unpaid work
just because you can't be bothered upgrading your code.

> My current PC was not upgradable because of the new hardware requirement
> Microsoft decided was needed for Windows 11.

Yes, and that's a good reason to switch to Linux for the older computer.

> I mention this in the context of examples of why even people who are fairly
> knowledgeable do not feel much need to fix what does not feel broken.

It doesn't feel broken, right up until it does. The OP has discovered
that it *IS* broken. Whining that it doesn't "feel broken" is nonsense
when it is, in fact, not working.

> When is Python 4 coming?

Is this just another content-free whine, or are you actually curious
about the planned future of Python? If the latter, there is **PLENTY**
of information out there and I don't need to repeat it here.

Please don't FUD.

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Wed, 12 Jun 2024 at 21:32, marc nicole via Python-list
 wrote:
>
> I am trying to install numpy library on Python 2.7.15 in PyCharm but the
> error message I get is:
>
> You can upgrade to a newer version of Python to solve this.

The answer is right there in the error message.

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


Re: From JoyceUlysses.txt -- words occurring exactly once

2024-06-04 Thread Chris Angelico via Python-list
On Wed, 5 Jun 2024 at 02:49, Edward Teach via Python-list
 wrote:
>
> On Mon, 03 Jun 2024 14:58:26 -0400 (EDT)
> Grant Edwards  wrote:
>
> > On 2024-06-03, Edward Teach via Python-list 
> > wrote:
> >
> > > The Gutenburg Project publishes "plain text".  That's another
> > > problem, because "plain text" means UTF-8and that means
> > > unicode...and that means running some sort of unicode-to-ascii
> > > conversion in order to get something like "words".  A couple of
> > > hoursa couple of hundred lines of Cproblem solved!
> >
> > I'm curious.  Why does it need to be converted frum Unicode to ASCII?
> >
> > When you read it into Python, it gets converted right back to
> > Unicode...
> >
>
> Well.when using the file linux.words as a useful master list of
> "words".linux.words is strict ASCII
>

Whatever gave you that idea? I have a large number of dictionaries in
/usr/share/dict, all of them encoded UTF-8 except one (and I don't
know why that is). Even the English ones aren't entirely ASCII.

There is no need to "convert from Unicode to ASCII", which makes no sense.

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


Re: Formatted Output and Argument Parsing (was: Re: Flubbed it in the second interation through the string: range error... HOW?)

2024-05-29 Thread Chris Angelico via Python-list
On Wed, 29 May 2024 at 23:06, Dan Sommers via Python-list
 wrote:
> (For the history-impaired, getopt existed long before Python and will
> likely exist long after it, but getopt's "replacement" optparse lasted
> only from 2003 until 2011.)

Depends on your definition of "lasted". It's not getting developed
further, but it's still there. If you started using it, you're welcome
to keep going.

https://docs.python.org/3/library/optparse.html

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


Re: Flubbed it in the second interation through the string: range error... HOW?

2024-05-29 Thread Chris Angelico via Python-list
On Wed, 29 May 2024 at 16:03, Cameron Simpson via Python-list
 wrote:
> By which Thomas means stuff like this:
>
>  print(f'if block {name[index]} and index {index}')
>
> Notice the leading "f'". Personally I wouldn't even go that far, just:
>
>  print('if block', name[index], 'and index', index)
>
> But there are plenty of places where f-strings are very useful.

I wouldn't replace str.format() everywhere, nor would I replace
percent encoding everywhere - but in this case, I think Thomas is
correct. Not because it's 2024 (f-strings were brought in back in
2015, so they're hardly chronologically special), but because most of
this looks like debugging output that can take advantage of this
feature:

print(f"if block {name[index]=} {index=}")

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


Re: PyCon

2024-05-18 Thread Chris Angelico via Python-list
On Sun, 19 May 2024 at 04:10, Abdur-Rahmaan Janhangeer via Python-list
 wrote:
>
> Yes, this year's pretty exciting, great keynotes, great lightnings, great
> location, great even sponsor talks (thought they would be pumping a lot of
> marketing, but the ones i went were pretty awesome technically)
>
> Organization side pretty smooth as well 👍

I missed out on the first day's lightning talks session due to
conflict with work, and it didn't seem to have been recorded. What did
I miss?

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


Re: PyCon

2024-05-18 Thread Chris Angelico via Python-list
On Sat, 18 May 2024 at 21:44, Skip Montanaro via Python-list
 wrote:
>
> >
> > > I’m at PyCon in Pittsburgh and I’m haven’t an amazing time!
> >
> > s/haven’t/having/
> >
>
> No need to explain/correct. We understand you are excited. Many of us have
> been in the same state before. ;-)
>

We're fluent in autocorrupt :)

If you're connecting to the online parts of PyCon, I'll see you there
- I'm about to hang out in the lightning talks! Geography's a bit of a
barrier for me, but thanks to livestreams, I can participate too!

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


Re: Python Dialogs

2024-05-06 Thread Chris Angelico via Python-list
On Tue, 7 May 2024 at 03:42, jak via Python-list  wrote:
>
> Loris Bennett ha scritto:
> > r...@zedat.fu-berlin.de (Stefan Ram) writes:
> >
> >>Me (indented by 2) and the chatbot (flush left). Lines lengths > 72!
> >
> > Is there a name for this kind of indentation, i.e. the stuff you are
> > writing not being flush left?  It is sort of contrary to
> > what I think of as "normal" indentation.  You seem to use it in all your
> > postings, too, which hurts my brain, but I guess that's my problem :-)
> >
> > [snip (40 lines)]
> >
>
> It's not just your problem. When the texts are particularly long and
> complex, I happen to use Google-Translator. It makes bad translations if
> the lines are interrupted by the newline, so I wrote a tool dedicated to
> Stefan and to all those who indent like him. This tool takes the text
> from the clipboard, removes all the superfluous spaces, combines all the
> lines in one and puts the result back into the clipboard. :-D
>

Fun fact: His posts are completely irrelevant to people who follow the
mailing list. Due to a dispute over permissions, his posts are blocked
at the gateway. So all of us folks who use the mailing list never need
to see the wonky indentation.

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


Re: how to discover what values produced an exception?

2024-05-06 Thread Chris Angelico via Python-list
On Tue, 7 May 2024 at 03:38, Alan Bawden via Python-list
 wrote:
> A good error message shouldn't withhold any information that can
> _easily_ be included.  Debugging is more art than science, so there is
> no real way to predict what information might prove useful in solving
> the crime.  I emphasized "easily" because of course you have to draw the
> line somewhere.

Emphasis on "easily" is correct here. How easy is it to report the
value of something that could be arbitrarily large?

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


Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Chris Angelico via Python-list
On Fri, 22 Mar 2024 at 18:35, Lars Liedtke via Python-list
 wrote:
>
> Hey,
>
> As far as I know (might be old news) flask does not support asyncio.
>
> You would have to use a different framework, like e.g. FastAPI or similar. 
> Maybe someone has already written "flask with asyncio" but I don't know about 
> that.
>

Did you try searching their documentation?

https://flask.palletsprojects.com/en/3.0.x/async-await/

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


Re: GIL-Removal Project Takes Another Step (Posting On Python-List Prohibited)

2024-03-20 Thread Chris Angelico via Python-list
On Wed, 20 Mar 2024 at 18:31, Greg Ewing via Python-list
 wrote:
>
> On 20/03/24 4:14 pm, Lawrence D'Oliveiro wrote:
> > not to
> > mention the latency when there isn’t quite enough memory for an allocation
> > and you have to wait until the next GC run to proceed. Run the GC a
> > thousand times a second, and the latency is still 1 millisecond.
>
> That's not the way it usually works. If you run out of memory, you
> run a GC there and then. You don't have to wait for GCs to occur on
> a time schedule.
>
> Also, as a previous poster pointed out, GCs are typically scheduled
> by number of allocations, not by time.
>

FYI you're violating someone's request by responding to them in a way
that results in it getting onto python-list, so it's probably safest
to just ignore cranks and trolls and let them stew in their own
juices.

But normally the GC doesn't need to be scheduled at all. In CPython,
the only reason to "run garbage collection" is to detect cycles, so
you would have to be generating inordinate amounts of cyclic garbage
for this to matter at all.

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


Re: A Single Instance of an Object?

2024-03-11 Thread Chris Angelico via Python-list
On Tue, 12 Mar 2024 at 08:04, Ivan "Rambius" Ivanov
 wrote:
> > A Singleton is just a global variable. Why do this? Did someone tell
> > you "global variables are bad, don't use them"?
>
> I have bad experience with global variables because it is hard to
> track what and when modifies them. I don't consider them bad, but if I
> can I avoid them.
>
If you have a singleton, how will you track "what and when modifies"
it? How is it any different from a global?

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


Re: A Single Instance of an Object?

2024-03-11 Thread Chris Angelico via Python-list
On Tue, 12 Mar 2024 at 07:54, Ivan "Rambius" Ivanov via Python-list
 wrote:
> I am refactoring some code and I would like to get rid of a global
> variable. Here is the outline:
>
> ...
>
> I have never done that in Python because I deliberately avoided such
> complicated situations up to now. I know about the Singleton pattern,
> but I have never implemented it in Python and I don't know if it is
> Pythonish.
>

A Singleton is just a global variable. Why do this? Did someone tell
you "global variables are bad, don't use them"?

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


Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Chris Angelico via Python-list
On Sat, 9 Mar 2024 at 03:42, Grant Edwards via Python-list
 wrote:
>
> On 2024-03-08, Chris Angelico via Python-list  wrote:
> > On Sat, 9 Mar 2024 at 00:51, Grant Edwards via Python-list
> > wrote:
> >
> >> One might argue that "global" isn't a good choice for what to call the
> >> scope in question, since it's not global. It's limited to that source
> >> file. It doesn't make sense to me to call a binding "global", when
> >> there can be multile different "global" bindings of the same name.
> >
> > Most "globals" aren't global either, since you can have different
> > globals in different running applications.
>
> To me, "global" has always been limited to within a single
> process/address space, but that's probably just bias left over from
> C/Pascal/FORTRAN/assembly/etc. It never occurred to me that a global
> called "X" in one program on one computer would be the same as a
> global called "X" in a different program on a different computer
> somewhere else on the "globe".
>

Yeah. My point is, though, the name "global" is a bit of a hack
anyway, so it's not THAT big a deal if it has other caveats too. For
example, let's say you always "import globals" at the top of every
script, and then assign "globals.x = 123" etc. Now you have a concept
of globals that spans the entire application, right? Well, no, not if
you use multiprocessing.

So, go ahead and call them globals, but people will always have to
learn about exactly what that means.

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


Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Chris Angelico via Python-list
On Sat, 9 Mar 2024 at 00:51, Grant Edwards via Python-list
 wrote:
> One might argue that "global" isn't a good choice for what to call the
> scope in question, since it's not global. It's limited to that source
> file. It doesn't make sense to me to call a binding "global", when
> there can be multile different "global" bindings of the same name.
>

Most "globals" aren't global either, since you can have different
globals in different running applications.

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


Re: Can one output something other than 'nan' for not a number values?

2024-02-19 Thread Chris Green via Python-list
Grant Edwards  wrote:
> On 2024-02-16, Chris Green via Python-list  wrote:
> 
> > I'm looking for a simple way to make NaN values output as something
> > like '-' or even just a space instead of the string 'nan'.
> 
> It would probably help if you told us how you're "outputting" them now
> (the Python feaatures/functions used, not the actual output format).
> 
> Are you using f-strings, the % operator, str.format(), or ??
> 
> I would be tempted to try monkey-patching the float class to override
> the __format__ method. I have no idea what side effects that might
> have, or if it's even used by the various formatting mechanisms, so
> you might end up scraping bits off the walls...
> 
It's using f'{...}' at the moment.

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


Re: Can one output something other than 'nan' for not a number values?

2024-02-19 Thread Chris Green via Python-list
dn  wrote:
> On 18/02/24 09:53, Grant Edwards via Python-list wrote:
> > On 2024-02-17, Cameron Simpson via Python-list  
> > wrote:
> >> On 16Feb2024 22:12, Chris Green  wrote:
> >>> I'm looking for a simple way to make NaN values output as something
> >>> like '-' or even just a space instead of the string 'nan'.
> >>> [...]
> >>>
> >>> Battery Voltages and Currents
> >>> Leisure Battery - 12.42 volts  -0.52 Amps
> >>> Starter Battery -   nan voltsnan Amps
> >>>
> >>> What I would like is for those 'nan' strings to be just a '-' or
> >>> something similar.
> > 
> >> The simplest thing is probably just a function writing it how you want
> >> it:
> >>
> >>   def float_s(f):
> >>   if isnan(f):
> >>   return "-"
> >>   return str(f)
> >>
> >> and then use eg:
> >>
> >>   print(f'value is {float_s(value)}')
> >>
> >> or whatever fits your code.
> > 
> > Except he's obviously using some sort of formatting to control the
> > number of columns and decimal places, so 'str(f)' is not going to cut
> > it. Is the basic floating point number formatting functionality seen
> > when using f-strings or '%' operator part of the float type or is it
> > part of the f-string and % operator?
> 
> It's part of the PSL's string library: "Format Specification 
> Mini-Language" 
> https://docs.python.org/3/library/string.html#format-specification-mini-language
> 
> Has the OP stated if we're talking 'Python' or numpy, pandas, ...?
> 
Just python, on a Raspberry Pi, so currently Python 3.9.2.

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


Re: Can one output something other than 'nan' for not a number values?

2024-02-18 Thread Chris Angelico via Python-list
On Mon, 19 Feb 2024 at 06:47, Grant Edwards via Python-list
 wrote:
> I would be tempted to try monkey-patching the float class to override
> the __format__ method. I have no idea what side effects that might
> have, or if it's even used by the various formatting mechanisms, so
> you might end up scraping bits off the walls...
>

You can try, but you'd have to do it in C - the float type is
immutable in Python.

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


Can one output something other than 'nan' for not a number values?

2024-02-16 Thread Chris Green via Python-list
I'm looking for a simple way to make NaN values output as something
like '-' or even just a space instead of the string 'nan'.  This would
then make it much easier to handle outputting values from sensors when
not all sensors are present. 

So, for example, my battery monitoring program outputs:-

Battery Voltages and Currents
Leisure Battery - 12.42 volts  -0.52 Amps
Starter Battery - 12.34 volts  -0.01 Amps

If the starter battery sensor has failed, or is disconnected, I see:- 

Battery Voltages and Currents
Leisure Battery - 12.42 volts  -0.52 Amps
Starter Battery -   nan voltsnan Amps


What I would like is for those 'nan' strings to be just a '-' or
something similar.

Obviously I can write conditional code to check for float('nan')
values but is there a neater way with any sort of formatting string or
other sort of cleverness?


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


Re: Is there a way to implement the ** operator on a custom object

2024-02-08 Thread Chris Angelico via Python-list
On Fri, 9 Feb 2024 at 17:03, Cameron Simpson via Python-list
 wrote:
>
> On 08Feb2024 12:21, tony.fl...@btinternet.com  
> wrote:
> >I know that mappings by default support the ** operator, to unpack the
> >mapping into key word arguments.
> >
> >Has it been considered implementing a dunder method for the **
> >operator so you could unpack an object into a key word argument, and
> >the developer could choose which keywords would be generated (or could
> >even generate 'virtual' attributes).
>
> Can you show us why you think that would look like in code?
>
> Note that Python already has `a ** b` to raise `a` to the power of `b`,
> and it has a bunder method `__pow__` which you can define.

I presume this is more like:

obj = SomeObject()
func(**obj)

ie making the object behave in a dict-like way. I can't remember how
this is implemented, but you can create the necessary methods to have
your object produce whatever it likes.

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


Re: Await expressions (Posting On Python-List Prohibited)

2024-01-26 Thread Chris Angelico via Python-list
On Sat, 27 Jan 2024 at 11:01, Greg Ewing via Python-list
 wrote:
>
> If it helps at all, you can think of an async function as being
> very similar to a generator, and "await" as being very similar to
> "yield from". In the current implementation they're almost exactly
> the same thing underneath.
>

Don't bother responding to people who say that they don't want
responses on a public list.

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


Re: Question about garbage collection

2024-01-16 Thread Chris Angelico via Python-list
On Wed, 17 Jan 2024 at 01:45, Frank Millman via Python-list
 wrote:
>
> On 2024-01-16 2:15 PM, Chris Angelico via Python-list wrote:
> >
> > Where do you tend to "leave a reference dangling somewhere"? How is
> > this occurring? Is it a result of an incomplete transaction (like an
> > HTTP request that never finishes), or a regular part of the operation
> > of the server?
> >
>
> I have a class that represents a database table, and another class that
> represents a database column. There is a one-to-many relationship and
> they maintain references to each other.
>
> In another part of the app, there is a class that represents a form, and
> another class that represents the gui elements on the form. Again there
> is a one-to-many relationship.

I don't know when you'd be "done" with the table, so I won't try to
give an example, but I'll try this one and maybe it'll give some ideas
that could apply to both.

When you open the form, you initialize it, display it, etc, etc. This
presumably includes something broadly like this:

class Form:
def __init__(self):
self.elements = []

class Element:
def __init__(self, form):
self.form = form
form.elements.append(self)

frm = Form(...)
Element(frm, ...) # as many as needed
frm.show() # present it to the user

This is a pretty classic refloop. I don't know exactly what your setup
is, but most likely it's going to look something like this. Feel free
to correct me if it doesn't.

The solution here would be to trap the "form is no longer being
displayed" moment. That'll be some sort of GUI event like a "close" or
"delete" signal. When that comes through (and maybe after doing other
processing), you no longer need the form, and can dispose of it. The
simplest solution here is: Empty out frm.elements. That immediately
leaves the form itself as a leaf (no references to anything relevant),
and the elements still refer back to it, but once nothing ELSE refers
to the form, everything can be disposed of.

> A gui element that represents a piece of data has to maintain a link to
> its database column object. There can be a many-to-one relationship, as
> there could be more than one gui element referring to the same column.

Okay, so the Element also refers to the corresponding Column. If the
Form and Element aren't in a refloop, this shouldn't be a problem.
However, if this is the same Table and Column that you referred to
above, that might be the answer to my question. Are you "done" with
the Table at the same time that the form is no longer visible? If so,
you would probably have something similar where the Form refers to the
Table, and the Table and Columns refer to each other... so the same
solution hopefully should work: wipe out the Table's list of columns.

> There are added complications which I won't go into here. The bottom
> line is that on some occasions a form which has been closed does not get
> gc'd.
>
> I have been trying to reproduce the problem in my toy app, but I cannot
> get it to fail. There is a clue there! I think I have just
> over-complicated things.

Definitely possible.

> I will start with a fresh approach tomorrow. If you don't hear from me
> again, you will know that I have solved it!
>
> Thanks for the input, it definitely helped.

Cool cool, happy to help.

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


Re: Question about garbage collection

2024-01-16 Thread Chris Angelico via Python-list
On Tue, 16 Jan 2024 at 23:08, Frank Millman via Python-list
 wrote:
>
> On 2024-01-15 3:51 PM, Frank Millman via Python-list wrote:
> > Hi all
> >
> > I have read that one should not have to worry about garbage collection
> > in modern versions of Python - it 'just works'.
> >
> > I don't want to rely on that. My app is a long-running server, with
> > multiple clients logging on, doing stuff, and logging off. They can
> > create many objects, some of them long-lasting. I want to be sure that
> > all objects created are gc'd when the session ends.
> >
>
> I did not explain myself very well. Sorry about that.
>
> My problem is that my app is quite complex, and it is easy to leave a
> reference dangling somewhere which prevents an object from being gc'd.
>
> This can create (at least) two problems. The obvious one is a memory
> leak. The second is that I sometimes need to keep a reference from a
> transient object to a more permanent structure in my app. To save myself
> the extra step of removing all these references when the transient
> object is deleted, I make them weak references. This works, unless the
> transient object is kept alive by mistake and the weak ref is never removed.
>
> I feel it is important to find these dangling references and fix them,
> rather than wait for problems to appear in production. The only method I
> can come up with is to use the 'delwatcher' class that I used in my toy
> program in my original post.
>
> I am surprised that this issue does not crop up more often. Does nobody
> else have these problems?
>

It really depends on how big those dangling objects are. My personal
habit is to not worry about a few loose objects, by virtue of ensuring
that everything either has its reference loops deliberately broken at
some point in time, or by keeping things small.

An example of deliberately breaking a refloop would be when I track
websockets. Usually I'll tag the socket object itself with some kind
of back-reference to my own state, but I also need to be able to
iterate over all of my own state objects (let's say they're
dictionaries for simplicity) and send a message to each socket. So
there'll be a reference loop between the socket and the state. But at
some point, I will be notified that the socket has been disconnected,
and that's when I go to its state object and wipe out its
back-reference. It can then be disposed of promptly, since there's no
loop.

It takes a bit of care, but in general, large state objects won't have
these kinds of loops, and dangling references haven't caused me any
sort of major issues in production.

Where do you tend to "leave a reference dangling somewhere"? How is
this occurring? Is it a result of an incomplete transaction (like an
HTTP request that never finishes), or a regular part of the operation
of the server?

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


Re: Question about garbage collection

2024-01-15 Thread Chris Angelico via Python-list
On Tue, 16 Jan 2024 at 13:49, Akkana Peck via Python-list
 wrote:
>
> I wrote:
> > > Also be warned that some modules (particularly if they're based on 
> > > libraries not written in Python) might not garbage collect, so you may 
> > > need to use other methods of cleaning up after those objects.
>
> Chris Angelico writes:
> > Got any examples of that?
>
> The big one for me was gdk-pixbuf, part of GTK. When you do something like 
> gtk.gdk.pixbuf_new_from_file(), there's a Python object that gets created, 
> but there's also the underlying C code that allocates memory for the pixbuf. 
> When the object went out of scope, the Python object was automatically 
> garbage collected, but the pixbuf data leaked. Calling gc.collect() caused 
> the pixbuf data to be garbage collected too.
>
> There used to be a post explaining this on the pygtk mailing list: the link 
> was
> http://www.daa.com.au/pipermail/pygtk/2003-December/006499.html
> but that page is gone now and I can't seem to find any other archives of that 
> list (it's not on archive.org either). And this was from GTK2; I never 
> checked whether the extra gc.collect() is still necessary in GTK3, but I 
> figure leaving it in doesn't hurt anything. I use pixbufs in a tiled map 
> application, so there are a lot of small pixbufs being repeatedly read and 
> then deallocated.
>

Okay, so to clarify: the Python object will always be garbage
collected correctly, but a buggy third-party module might have
*external* resources (in that case, the pixbuf) that aren't properly
released. Either that, or there is a reference loop, which doesn't
necessarily mean you NEED to call gc.collect(), but it can help if you
want to get rid of them more promptly. (Python will detect such loops
at some point, but not always immediately.) But these are bugs in the
module, particularly the first case, and should be considered as such.
2003 is fully two decades ago now, and I would not expect that a
serious bug like that has been copied into PyGObject (the newer way of
using GTK from Python).

So, Python's garbage collection CAN be assumed to "just work", unless
you find evidence to the contrary.

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


Re: Question about garbage collection

2024-01-15 Thread Chris Angelico via Python-list
On Tue, 16 Jan 2024 at 06:32, Akkana Peck via Python-list
 wrote:
>
> > Frank Millman wrote at 2024-1-15 15:51 +0200:
> > >I have read that one should not have to worry about garbage collection
> > >in modern versions of Python - it 'just works'.
>
> Dieter Maurer via Python-list writes:
> > There are still some isolated cases when not all objects
> > in an unreachable cycle are destroyed
> > (see e.g. step 2 of
> > "https://devguide.python.org/internals/garbage-collector/index.html#destroying-unreachable-objects";).
>
> Also be warned that some modules (particularly if they're based on libraries 
> not written in Python) might not garbage collect, so you may need to use 
> other methods of cleaning up after those objects.
>

Got any examples of that?

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


Re: Extract lines from file, add to new files

2024-01-15 Thread Chris Angelico via Python-list
On Mon, 15 Jan 2024 at 19:26, Greg Ewing via Python-list
 wrote:
>
> On 15/01/24 9:07 pm, Chris Angelico wrote:
> > The grammar *can't* specify everything. If it did, it would have to
> > have rules for combining individual letters into a NAME and individual
> > characters into a string literal.
>
> The lexical level of a grammar can be, and often is, described
> formally using regular expressions.
>
> Although some might consider that this doesn't contradict
> your statement about readability. :-)
>

Not even slightly :)

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


Re: Extract lines from file, add to new files

2024-01-15 Thread Chris Angelico via Python-list
On Mon, 15 Jan 2024 at 18:56, Greg Ewing via Python-list
 wrote:
>
> On 15/01/24 1:28 am, Left Right wrote:
> > Python isn't a context-free language, so the grammar that is used to
> > describe it doesn't actually describe the language
>
> Very few languages have a formal grammar that *fully* describes
> the set of strings that constitute valid programs, including all
> the rules about things having to be declared, types matching up,
> etc. The only one I know of which attempted that is Algol 68,
> and it seems to be regarded as a technical success but a practical
> failure.
>
> > ... so, it's a "pretend grammar" that ignores indentation.
>
> Indentation isn't ignored, it appears in the grammar by means of
> INDENT and DEDENT lexical tokens.
>
> It's true that the meaning of these tokens is described informally
> elsewhere, but that's true of all the lexical features.
>

I've recently been doing a bit of work with grammar parsers, and to be
quite honest, the grammar is only about one third of the overall
parser.  There are three sections with roughly equal importance:

1. Tokenizer
2. Grammar
3. What to DO with that grammar (actions)

INDENT and DEDENT are being handled at the tokenizer stage, and so are
a lot of other rules like backslashes in quoted strings. On the flip
side, string prefixes (like b"...") seem to be handled in the third
phase, and the grammar actually doesn't concern itself with those
either.

The grammar *can't* specify everything. If it did, it would have to
have rules for combining individual letters into a NAME and individual
characters into a string literal. The grammar would be completely
unreadable. (I tried, and even just building up a decimal literal in
that style was quite a pain.)

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


Re: Extract lines from file, add to new files

2024-01-14 Thread Chris Angelico via Python-list
On Mon, 15 Jan 2024 at 12:42, dn via Python-list  wrote:
>
> On 15/01/24 14:33, Chris Angelico via Python-list wrote:
> > On Mon, 15 Jan 2024 at 12:12, dn via Python-list  
> > wrote:
> >> Here's another witticism I'll often toss at trainees (in many languages,
> >> and especially in UX): just because we can do it, doesn't make it a good
> >> idea!
> >>
> >
> > Programming. We were so busy with whether we COULD that we didn't stop
> > to think if we SHOULD.
> >
> > I think that's basically my whole life.
>
> Don't be too hard on yourself.
>
> My life-advice has always been "don't do anything I wouldn't do"
> - which pretty-much gives you carte blanche.
>

I would NEVER give that advice to anyone. They would leave the dishes
unwashed, and a number of other problems :)

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


Re: Extract lines from file, add to new files

2024-01-14 Thread Chris Angelico via Python-list
On Mon, 15 Jan 2024 at 12:12, dn via Python-list  wrote:
> Here's another witticism I'll often toss at trainees (in many languages,
> and especially in UX): just because we can do it, doesn't make it a good
> idea!
>

Programming. We were so busy with whether we COULD that we didn't stop
to think if we SHOULD.

I think that's basically my whole life.

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


Re: Extract lines from file, add to new files

2024-01-14 Thread Chris Angelico via Python-list
On Mon, 15 Jan 2024 at 09:40, dn via Python-list  wrote:
> The basic challenge came from my earlier (and blasé) repetition of the
> Python refrain "everything in Python is an object". Which led to:
>
> <<<
> For example, you may say "functions in Python are
> objects", but you cannot put a function definition in the head of the
> for loop clause.
>  >>>
>
> Which is logical - to some degree, and in-isolation.
>
>  for def a_function( etc )... in iterable/iterator:
>
> does not make sense. The 'head' (a more generic name, where Python says
> "target_list", that refines down to 'something which can identify the
> generated-value'.
>
> So, no, there's an "everything" which (might be) an object but which
> cannot be used in that scenario.

More accurately, every VALUE in Python is an object. This does not
mean that syntax is an object. Very few languages would say that every
single grammatical element is a value.

Yes, it's sloppy to say "everything" is an object, but it's also
rather nonintuitive to claim that, therefore, syntax elements are all
objects. It's like claiming that everything that this dealership sells
is a car (or "everything in this dealership is a car"), and therefore
the dealership's name must itself be a car.

> That said, does anyone think that something like:
>
>  for a_function( etc ) in iterable/iterator:
>
> is acceptable?
> - see both Python definition and (full-)quotation.
>
> I've not come-across a language which does allow such - YMMV/mea culpa;
> and am struggling to see how it could possibly be useful.

You could do something close to that:

for a_function(etc)[0] in iterable: ...

because an assignment target can contain an arbitrary expression
followed by the subscript.

> * Looking at the correspondent's email-address (cf 'handle') - and as an
> unfair stereotype, raises the question of issues related to (English)
> language-skills - which, arrogantly implies/assumes that native
> English-speakers are all highly-capable. (?) A negative-interpretation
> is to note his apparent intelligence, but wonder if failing to represent
> others' comments fairly is deliberate, or carelessness. Is there an
> irony in behaving/failing in such, whilst attempting to hold Python's
> structure to some golden-ideal?

Seems likely.

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


Re: Extract lines from file, add to new files

2024-01-14 Thread Chris Angelico via Python-list
On Mon, 15 Jan 2024 at 08:15, Left Right  wrote:
> Python grammar rules prevent function definition from
> appearing in left-hand side of the head of the for loop.  However, a
> variable declaration, which is also a statement, is allowed there.

What is a "variable declaration" in Python? Please elaborate.

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


Re: Extract lines from file, add to new files

2024-01-14 Thread Chris Angelico via Python-list
On Mon, 15 Jan 2024 at 00:27, Left Right  wrote:
>
> > What do you mean?
> >
> > for x in lambda: ...:
> >   ...
> >
> > Perfectly grammatical.
>
> 1. You put the lambda definition in the wrong place (it should be in
> the left-hand side, or as Python calls it "star_targets", but you put
> it into "star_expressions", which would be where the right-hand side
> is drawn from).
> 2. You used what Python calls "lambdadef" in place of what Python
> calls "function_def". I.e. lambda definition and function definition
> are two different things, at least as far as grammar is considered.
>
> So, you solved a different problem.

You said function. I made a function. You said "head of a for loop
clause". I put it there. Problem was underspecified.

But if you're trying to tell me that a def statement should be a valid
assignment target, I don't know what you're smoking, but I want you to
keep it a long way away from me. Can you name ANY language in which
that would make the slightest bit of sense?

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


Re: Extract lines from file, add to new files

2024-01-14 Thread Chris Angelico via Python-list
On Sun, 14 Jan 2024 at 23:28, Left Right  wrote:
> Having worked with a bunch of different grammar languages, the one
> used for Python isn't a recognizable BNF derivative.

That might possibly be because it isn't? It's not BNF. It's PEG. Or
are you a long way behind the times?

> For example, you may say "functions in Python are
> objects", but you cannot put a function definition in the head of the
> for loop clause.

What do you mean?

for x in lambda: ...:
   ...

Perfectly grammatical.

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


Re: Extract lines from file, add to new files

2024-01-13 Thread Chris Angelico via Python-list
On Sun, 14 Jan 2024 at 14:43, dn via Python-list  wrote:
> Similarly, whilst we could write:
>
> a, b, c = 1, 2, 3
>

I would only do this when it aligns particularly well with the
algorithm being implemented. For example, you could start a Fibonacci
evaluator with "a, b = 0, 1". Otherwise, there's not all that much
reason to unpack three constants in this way.

(Though I am much more likely to use multiple initialization to set a
bunch of things to the SAME value, lilke "a = b = c = 0".)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extract lines from file, add to new files

2024-01-12 Thread Chris Angelico via Python-list
On Sat, 13 Jan 2024 at 13:11, Left Right via Python-list
 wrote:
>
>  Very few
> languages allow arbitrary complex expressions in the same place they
> allow variable introduction.

What do you mean by this? Most languages I've worked with allow
variables to be initialized with arbitrary expressions, and a lot of
languages allow narrowly-scoped variables.

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


Re: Extract lines from file, add to new files

2024-01-11 Thread Chris Angelico via Python-list
On Fri, 12 Jan 2024 at 08:56, Left Right via Python-list
 wrote:
>
> By the way, in an attempt to golf this problem, I discovered this,
> which seems like a parser problem:

When you jump immediately to "this is a bug", all you do is make
yourself look like an idiot. Unsurprisingly, this is NOT a bug, this
is simply that you didn't understand what was going on. The grammar
isn't easy to read, and it's usually better to read the documentation
instead.

(Plus, golfing isn't really a goal in Python, and you didn't  shorten
the code by much at all. Good job.)

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


Re: Aw: Re: mypy question

2023-12-30 Thread Chris Angelico via Python-list
On Sun, 31 Dec 2023 at 03:38, Thomas Passin via Python-list
 wrote:
> I am not very expert in Python type hints.  In working up the example
> program I just posted, I got an error message from mypy that remarked
> that "list" is invariant, and to try Sequence which is "covariant".  I
> don't know what that means (and I haven't looked into it yet), but when
> I changed from list to Sequence as suggested, mypy stopped complaining.
>

Ah, I think you've hit on the problem there. Consider this:

def add_item(stuff: dict[str: str | int]):
stuff["spam"] = "ham"
stuff["vooom"] = 1_000_000

Is it valid to pass this function a dict[str: str]? No, because it's
going to add an integer into it.

Hopefully that helps explain what's going on a bit.

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


Re: How/where to store calibration values - written by program A, read by program B

2023-12-30 Thread Chris Green via Python-list
Peter J. Holzer  wrote:
> [-- text/plain, encoding quoted-printable, charset: us-ascii, 40 lines --]
> 
> On 2023-12-29 09:01:24 -0800, Grant Edwards via Python-list wrote:
> > On 2023-12-28, Peter J. Holzer via Python-list  
> > wrote:
> > > On 2023-12-28 05:20:07 +, rbowman via Python-list wrote:
> > >> On Wed, 27 Dec 2023 03:53:42 -0600, Greg Walters wrote:
> > >> > The biggest caveat is that the shared variable MUST exist before it can
> > >> > be examined or used (not surprising).
> > >> 
> > >> There are a few other questions. Let's say config.py contains a variable 
> > >> like 'font' that is a user set preference or a calibration value 
> > >> calculated by A to keep with the thread title. Assuming both scripts are 
> > >> running, how does the change get propagated to B after it is set in A
> > >
> > > It isn't. The variable is set purely in memory. This is a mechanism to
> > > share a value between multiple modules used by the same process, not to
> > > share between multiple processes (whether they run the same or different
> > > scripts)
> > >
> > >> and written to the shared file?
> > >
> > > Nothing is ever written to a file.
> > 
> > Then how does it help the OP to propogate clibration values from one
> > program to another or from one program run to the next run?
> 
> It doesn't. See his second mail in this thread, where he explains it in
> a bit more detail. I think he might be a bit confused in his
> terminology.
> 
If I am the OP (I suspect I may be) I have gone with JSON stored in a
file to provide what I need.  The Python json package is very simple
to use and with an 'indent=' setting the resulting json is reasonably
human readable which is all I need.

Thus programs simply read the values from the json file into a
dictionary of dictionaries and the 'updater of values' program can
write them back after changes. 

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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2023-12-29 Thread Chris Angelico via Python-list
On Sat, 30 Dec 2023 at 14:06, Mike Dewhirst via Python-list
 wrote:
>
> On 29/12/2023 12:09 pm, Félix An via Python-list wrote:
> > On 2023-12-25 12:36, Mike Dewhirst wrote:
> >>
> >> 3. You cannot trust Microsoft. You can trust Python Software
> >> Foundation. Python from PSF works the same in all environments - or
> >> if not it is a bug. Python from Microsoft is tweaked to satisfy their
> >> aforementioned strategy of locking in users to Windows.
> >>
> >
> > I strongly disagree with this.
>
> Not sure which part of the above you strongly disagree with. I might
> seem a bit OTT with "You cannot trust Microsoft" but I did put it in a
> specific context.
>
> PSF does try to make Python work identically in all operating systems it
> supports. The OP was using py.exe which I discovered (just now - and it
> is why I'm writing this) exists on my Windows 10 machine. I have never
> installed any Python other than personally downloaded from the
> python.org website - therefore py.exe must have come from PSF!
>
> I had assumed the OP had installed Python from the Microsoft shop and
> that's where py.exe must have come from.
>
> I learn something every day.

If you'd done a little research, you might have found this:

https://peps.python.org/pep-0397/

Yes, it is from the official launcher. I don't see why you'd expect
Microsoft to go to the effort of building their own launcher when it
can be available for every Python user.

> > I don't get all the irrational hate for Microsoft that exists within
> > the Linux community.
>
> Perhaps you are too young to remember when Steve Ballmer was head of
> Microsoft?

How relevant is this?

I remember the days when OS/2 was the big target, and Microsoft was
the greatest anti-OS/2 voice out there. Does that affect the way I use
tools today? Is it even slightly relevant?

I remember when Intel had floating-point division issues in their
FPUs. Do I tell people "don't do floating-point math on Intel
processors"? Is it relevant?

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


Re: What is Install-Paths-To in WHEEL file?

2023-12-29 Thread Chris Angelico via Python-list
On Sat, 30 Dec 2023 at 06:58, Left Right  wrote:
> My understanding is that "welcome and encourage participation by
> everyone" is in stark contradiction to banning someone disagreeing
> with you.

Then your understanding is flat-out wrong. Encouraging participation
by everyone DOES mean deleting what is unproductive, offensive, and
likely to discourage participation.

Your entire argument is based on misconceptions. Go play in your own
sandbox somewhere, see if you can make something where everyone is
welcome, including the toxic AND the people who dislike toxicity.

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


Re: What is Install-Paths-To in WHEEL file?

2023-12-29 Thread Chris Angelico via Python-list
On Sat, 30 Dec 2023 at 01:37, Left Right  wrote:
>
> > Yeah, because you have the God-given RIGHT to be able to say anything
> > you like, on anyone's web site, and nobody's allowed to delete
> > anything you say! That's how it goes, right?
>
> I don't believe in god, and I don't believe he / she can give me
> rights.  What I believe in is that Python is a public good, and its
> status is enshrined in the license it uses.

Is it? I'm not a lawyer, but I really don't think that that's what the
license entitles you to. Can you quote the relevant parts of it?

> > Don't let the door hit you on the way out.
>
> Oh, great. Here we go again.  You don't even know what this discussion
> is about, but decided to be rude.

Oh trust me, I saw the discussion previously. I know what it is about.
And when it comes to rudeness, let's just say, you reap what you sow.

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


Re: What is Install-Paths-To in WHEEL file?

2023-12-29 Thread Chris Angelico via Python-list
On Sat, 30 Dec 2023 at 01:16, Left Right via Python-list
 wrote:
>
> That's not the discussion that was toxic. But the one that was --
> doesn't exist anymore since the forum owners deleted it.
>
> The part where the forum owners delete whatever they disagree with is
> the toxic part.

Yeah, because you have the God-given RIGHT to be able to say anything
you like, on anyone's web site, and nobody's allowed to delete
anything you say! That's how it goes, right?

You're most welcome to avoid the Python Discourse if you dislike
moderated forums, but do be aware that python-list is ALSO moderated,
and that completely unmoderated forums are far far more toxic than
anything I've seen on the Python Discourse.

Don't let the door hit you on the way out.

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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2023-12-28 Thread Chris Angelico via Python-list
On Fri, 29 Dec 2023 at 12:23, Félix An via Python-list
 wrote:
>
> On 2023-12-25 12:36, Mike Dewhirst wrote:
> >
> > 3. You cannot trust Microsoft. You can trust Python Software Foundation. 
> > Python from PSF works the same in all environments - or if not it is a bug. 
> > Python from Microsoft is tweaked to satisfy their aforementioned strategy 
> > of locking in users to Windows.
> >
>
> I strongly disagree with this. I don't get all the irrational hate for
> Microsoft that exists within the Linux community.

It's worth noting that Mike Dewhirst is NOT a spokesman for the Linux
community. One of the cool benefits freedom brings is that anyone's
allowed to be wrong :)

Not ALL of us hate Microsoft. I store the vast majority of my code on
GitHub, and it didn't make any difference when MS bought that company
(it was already a company, and their interests were always to make
money, and that was okay with me).

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


Re: >>> %matplotlib inline results in SyntaxError: invalid syntax

2023-12-25 Thread Chris Angelico via Python-list
On Tue, 26 Dec 2023 at 07:27, Chris Grace via Python-list
 wrote:
> I'd also recommend a newer version of python. Python 3.4 reached end of
> life almost 5 years ago.

Uhh, putting this in perspective... until a spammer revived the thread
just now, it was asked, answered, and finished with, all back in 2016.

I don't think anyone's still waiting on answers here.

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


Re: >>> %matplotlib inline results in SyntaxError: invalid syntax

2023-12-25 Thread Chris Grace via Python-list
"%matplotlib inline" is a magic command that changes how plots render when
working with IPython. Read more here: https://stackoverflow.com/a/43028034

The article you linked assumes you are working in an IPython shell, not
IDLE. This is common in the data science world.

You may already have IPython installed. Try running it from a command line
with `python -m IPython`. If that doesn't work, you can first install it
with `python -m pip install IPython`, then run the 1st command.

IPython is commonly used as a Jupyter Notebook kernel. See
https://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/index.html
for more information about Jupyter Notebook.

I'd also recommend a newer version of python. Python 3.4 reached end of
life almost 5 years ago. Some of the packages used in the linked article no
longer officially support python 3.4. That doesn't necessarily mean that
you'll experienced issues using python 3.4, but much has changed in the 7
years since that article was written.

On Mon, Dec 25, 2023, 2:53 PM Alan Gauld via Python-list <
python-list@python.org> wrote:

> On 25/12/2023 05:34, geetanajali homes via Python-list wrote:
>
> >> import numpy as np
> >> import pandas as pd
> >> import random
> >> import matplotlib.pyplot as plt
> >> %matplotlib inline
> >>
> >> I get an error on the last line. I am running this code in Idle Python
> >> 3.4.4 Shell...
>
> Python names can't start with a % (its the modulo or
> string formatting operator).
>
> I know nothing of the innards of matplotlib so I can only
> suggest a closer examination of their tutorial information.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2023-12-24 Thread Chris Angelico via Python-list
On Mon, 25 Dec 2023 at 15:42, Mike Dewhirst via Python-list
 wrote:
>
> Apologies for top posting - my phone seems unable to do otherwise.
>
> Here's my view - which may not be popular.

You're right about that part, anyhow :)

> 4. Shebang lines are pretty much redundant now that most python interpreters 
> are run from venvs

Strongly dispute that. The rest. you're entitled to your opinions
(they happen to be wrong, but you're entitled to them :) ), but this
is a statement of fact that I would need to see some evidence for.

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


Re: How/where to store calibration values - written by program A, read by program B

2023-12-06 Thread Chris Green via Python-list
Thank you everyone for all the suggestions, I now have several
possibilities to follow up. :-)

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


Re: How/where to store calibration values - written by program A, read by program B

2023-12-06 Thread Chris Green via Python-list
Thomas Passin  wrote:
> On 12/5/2023 11:50 AM, MRAB via Python-list wrote:
> > On 2023-12-05 14:37, Chris Green via Python-list wrote:
> >> Is there a neat, pythonic way to store values which are 'sometimes'
> >> changed?
> >>
> >> My particular case at the moment is calibration values for ADC inputs
> >> which are set by running a calibration program and used by lots of
> >> programs which display the values or do calculations with them.
> >>
> >>  From the program readability point of view it would be good to have a
> >> Python module with the values in it but using a Python program to
> >> write/update a Python module sounds a bit odd somehow.
> >>
> >> I could simply write the values to a file (or a database) and I
> >> suspect that this may be the best answer but it does make retrieving
> >> the values different from getting all other (nearly) constant values.
> >>
> >> Are there any Python modules aimed specifically at this sort of
> >> requirement?
> >>
> > Some kind of key/value store sounds like the correct solution. I 
> > wouldn't go as far a database - that's overkill for a few calibration 
> > values.
> > 
> > I might suggest TOML, except that Python's tomllib (Python 3.11+) is 
> > read-only!
> > 
> > Personally, I'd go for lines of:
> > 
> >      key1: value1
> >      key2: value2
> > 
> > Simple to read, simple to write.
> 
> Just go with an .ini file. Simple, well-supported by the standard 
> library. And it gives you key/value pairs.
> 
My requirement is *slightly* more complex than just key value pairs,
it has one level of hierarchy, e.g.:-

KEY1:
  a: v1
  c: v3
  d: v4
KEY2:
  a: v7
  b: v5
  d: v6

Different numbers of value pairs under each KEY.

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


Re: How/where to store calibration values - written by program A, read by program B

2023-12-06 Thread Chris Green via Python-list
Paul Rubin  wrote:
> Chris Green  writes:
> > I could simply write the values to a file (or a database) and I
> > suspect that this may be the best answer but it does make retrieving
> > the values different from getting all other (nearly) constant values.
> 
> I've used configparser for this, though its intention is files that are
> manually edited, rather than updated by a program.
> 
> You can also read and dump a json file or pickle file.  I prefer json to
> pickle for most purposes these days.
> 
> I don't like YAML and I don't like the proliferation of markup formats
> of this type.  So while I don't know exactly what TOML is, I figure it
> must be bad.
> 
> I sometimes use ast.literal_eval though it is Python specific.
> 
That's interesting, I'll add it to my armoury anyway. :-)


> Of course there is also sqlite but that is probably overkill.

It's what my current code uses but does feel a bit OTT and it isn't
particularly convenient to view when debugging. 

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


How/where to store calibration values - written by program A, read by program B

2023-12-05 Thread Chris Green via Python-list
Is there a neat, pythonic way to store values which are 'sometimes'
changed?

My particular case at the moment is calibration values for ADC inputs
which are set by running a calibration program and used by lots of
programs which display the values or do calculations with them.

From the program readability point of view it would be good to have a
Python module with the values in it but using a Python program to
write/update a Python module sounds a bit odd somehow.

I could simply write the values to a file (or a database) and I
suspect that this may be the best answer but it does make retrieving
the values different from getting all other (nearly) constant values.

Are there any Python modules aimed specifically at this sort of
requirement?

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


Re: argparse argument post-processing

2023-11-27 Thread Chris Angelico via Python-list
On Mon, 27 Nov 2023 at 22:31, Dom Grigonis via Python-list
 wrote:
>
> Hi all,
>
> I have a situation, maybe someone can give some insight.
>
> Say I want to have input which is comma separated array (e.g. 
> paths='path1,path2,path3') and convert it to the desired output - list:

This is a single argument.

> Now the second case. I want input to be space separated array - bash array. 
> And I want space-separated string returned. My current approach is:
> import argparse
> parser = argparse.ArgumentParser()
> parser.add_argument('paths', nargs='+')
> args = parser.parse_args()
> paths = ' '.join(args.paths)
> But what I am looking for is a way to do this, which is intrinsic to 
> `argparse` module. Reason being I have a fair amount of such cases and I 
> don’t want to do post-processing, where post-post-processing happens (after 
> `parser.parse_args()`).
>

This is parsing multiple arguments.

If you want it space-separated, you can do that, just as a single
argument. Otherwise, what you're doing is taking multiple arguments
and joining them. I'm not sure what you expect to see, but your
examples here pretty clearly show that you are taking multiple
arguments, and joining them with spaces.

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


Re: Newline (NuBe Question)

2023-11-26 Thread Chris Angelico via Python-list
On Mon, 27 Nov 2023 at 13:52, AVI GROSS via Python-list
 wrote:
>  Be that as it
> may, and I have no interest in this topic, in the future I may use the ever
> popular names of Primus, Secundus and Tertius and get blamed for using
> Latin.
>

Imperious Prima flashes forth her edict to "begin it". In gentler tone
Secunda hopes there will be nonsense in it. While Tertia interrupts
the tale not more than once a minute.

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


Re: RE: Newline (NuBe Question)

2023-11-26 Thread Chris Angelico via Python-list
On Mon, 27 Nov 2023 at 06:15,  wrote:
> But I learn from criticism. If I ever write a program like that and do not
> feel like typing, will this do?
>
> dents = [ ...]
>
> Or will that not include students who happen to be edentulous?
>

If they're learning to drive, this variable name would make complete sense.

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


Re: RE: Newline (NuBe Question)

2023-11-26 Thread Chris Angelico via Python-list
On Sun, 26 Nov 2023 at 21:08, Michael F. Stemper via Python-list
 wrote:
>
> On 24/11/2023 21.45, avi.e.gr...@gmail.com wrote:
> > Grizz[l]y,
> >
> > I think the point is not about a sorted list or sorting in general It is
> > about reasons why maintaining a data structure such as a list in a program
> > can be useful beyond printing things once. There are many possible examples
> > such as having a list of lists containing a record where the third item is a
> > GPA for the student and writing a little list comprehension that selects a
> > smaller list containing only students who are Magna Cum Laude or Summa Cum
> > Laude.
> >
> > studs = [
> >["Peter", 82, 3.53],
> >["Paul", 77, 2.83],
> >["Mary", 103, 3.82]
> > ]
>
> I've seen Mary, and she didn't look like a "stud" to me.
>

That's what happens when you abbreviate "student" though :) Don't
worry, there's far FAR worse around the place, and juvenile brains
will always find things to snigger at, usually in mathematical
libraries with "cumulative" functions.

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


Re: Silly/crazy problem with sqlite

2023-11-26 Thread Chris Green via Python-list
Stefan Ram  wrote:
> Chris Green  writes:
> >I have to say this seems very non-pythonesque to me, the 'obvious'
> >default simply doesn't work right, and I really can't think of a case
> >where the missing comma would make any sense at all.
> 
> |6.15 Expression lists
> ...
> |an expression list containing at least one comma yields a tuple.
> ...
> The Python Language Reference, Release 3.13.0a0;
> Guido van Rossum and the Python development team;
> October 10, 2023.
> 
I wasn't meaning that it wasn't correct Python, more that doing the
obvious doesn't work which, in Python, it usually does in my
experience. 

The error message could be a bit more helpful too, maybe one of those
"... did you mean ?" ones could point one in the right direction.

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


Re: Silly/crazy problem with sqlite

2023-11-25 Thread Chris Green via Python-list
Chris Green  wrote:
> This is driving me crazy, I'm running this code:-

OK, I've found what's wrong:-

> cr.execute(sql, ('%' + "2023-11" + '%'))

should be:-

cr.execute(sql, ('%' +  x + '%',) )


I have to say this seems very non-pythonesque to me, the 'obvious'
default simply doesn't work right, and I really can't think of a case
where the missing comma would make any sense at all.

Maybe I've had too much to eat and drink tonight! :-)

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


Silly/crazy problem with sqlite

2023-11-25 Thread Chris Green via Python-list
This is driving me crazy, I'm running this code:-

#!/usr/bin/env python3 
# 
# 
# Show the electric fence history, default to last 24 hours 
# 
import sqlite3
import datetime
import sys

today = datetime.datetime.now()
today = str(today)
x = str(today[0:10])
print(x)

fdb = sqlite3.connect("/home/chris/.share/newbourne.db")
cr = fdb.cursor()

sql = "SELECT * FROM fence where datetime LIKE ?"
cr.execute(sql, ('%' + "2023-11" + '%'))
rv = cr.fetchall()
for d in rv:
print(d)
fdb.commit()
fdb.close()

Forget about the 'today =' bits, they no longer do anything.

When I run the above I get:-

chris@esprimo$ fence.py
2023-11-24
Traceback (most recent call last):
  File "/home/chris/dev/bin/fence.py", line 19, in  cr.execute(sql, 
('%' + "2023-11" + '%')) sqlite3.ProgrammingError: Incorrect number of bindings 
supplied.  The current statement uses 1, and there are 9 supplied.
chris@esprimo$ 

It's treating the "2023-11" plus % at each end as separate variables to
the binding, this is crazy!  I've done similar elsewhere and it works
OK, what on earth am I doing wrong here?  It has to be something very
silly but I can't see it at the moment.

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


Re: xor operator

2023-11-13 Thread Chris Angelico via Python-list
On Tue, 14 Nov 2023 at 11:40, Chris Angelico  wrote:
> Here's a couple of excellent videos on error correction, and you'll
> see XOR showing up as a crucial feature:
>
> https://www.youtube.com/watch?v=X8jsijhllIA
> https://www.youtube.com/watch?v=h0jloehRKas
>

I just flipped through that 3blue1brown video again, and as it turns
out, the actual part where he talks about multi-argument XOR happens
in part two (it's barely touched on at the very end as he's
introducing part two).

https://www.youtube.com/watch?v=b3NxrZOu_CE

Honestly though, the full video is well worth watching. More modern
error correction systems are slightly different, but will still be
built on many of the same principles.

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


Re: xor operator

2023-11-13 Thread Chris Angelico via Python-list
On Tue, 14 Nov 2023 at 12:02, Dom Grigonis via Python-list
 wrote:
> As I am here, I will dare to ask if there is no way that `sign` function is 
> going to be added to `math` or `builtins`.
>

https://docs.python.org/3/library/math.html#math.copysign

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


Re: xor operator

2023-11-13 Thread Chris Angelico via Python-list
On Tue, 14 Nov 2023 at 11:29, Dom Grigonis via Python-list
 wrote:
>
>
> > Except the 'any' and 'all' builtins are _exactly_ the same as bitwise
> > or and and applided to many bits. To do something "in line" with that
> > using the 'xor' operator would return True for an odd number of True
> > values and False for an even Number of True values.
>
> Fair point.
>
> Have you ever encountered the need for xor for many bits (the one that I am 
> NOT referring to)? Would be interested in what sort of case it could be 
> useful.

Yes, parity checking. That's why I namedropped that in my prior
response - it's an easy thing to search the web for if you want to
know more about it.

Here's a couple of excellent videos on error correction, and you'll
see XOR showing up as a crucial feature:

https://www.youtube.com/watch?v=X8jsijhllIA
https://www.youtube.com/watch?v=h0jloehRKas

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


Re: xor operator

2023-11-13 Thread Chris Angelico via Python-list
On Tue, 14 Nov 2023 at 10:00, Dom Grigonis via Python-list
 wrote:
>
> I am not asking. Just inquiring if the function that I described could be 
> useful for more people.
>
> Which is: a function with API that of `all` and `any` and returns `True` if 
> specified number of elements is True.
>
> It is not a generalised `xor` in strict programatic space. I.e. NOT bitwise 
> xor applied to many bits.
> This is more in line with cases that `any` and `all` builtins are used.
>

A generalization of XOR is exactly what Grant and I said, though: a
parity check. See for example:

https://en.wikipedia.org/wiki/Exclusive_or
https://reference.wolfram.com/language/ref/Xor.html

It tells you whether you have an odd or even number of true values.

Now, if you want something that short-circuits a counting function,
that's definitely doable, but it's a sum-and-compare, not xor. Also,
it's quite specialized so it's unlikely to end up in the stdlib.

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


Re: xor operator

2023-11-13 Thread Chris Angelico via Python-list
On Tue, 14 Nov 2023 at 08:57, Axel Reichert via Python-list
 wrote:
>
> Barry  writes:
>
> > I do not understand how xor(iterator) works.
> > I thought xor takes exactly 2 args.
>
> See
>
>   https://mathworld.wolfram.com/XOR.html
>
> for some background (I was not aware of any generalizations for more
> than 2 arguments either).
>

Generalization to more arguments usually means calculating parity -
that is, it tells you whether you have an odd or even number of true
results. Which means that short-circuiting is nonsensical.

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


Re: Beep on WIndows 11

2023-11-12 Thread Chris Angelico via Python-list
On Mon, 13 Nov 2023 at 04:13, MRAB via Python-list
 wrote:
> In the old days, with a BBC micro, that was simple. It had 3 tone
> channels and 1 white noise channel, with control over frequency,
> duration and volume, beeps on different channels could be synchronised
> to start at the same time, there was a sound queue so that the SOUND
> command returned immediately, and there was an ENVELOPE command for
> controlling the attack, decay, sustain and release. All this on an 8-bit
> machine!
>
> My current PC is way more powerful. 64-bit processor, GBs of RAM, etc.
> Python offers winsound.Beep. 1 tone, no volume control, and it blocks
> while beeping.

I learned to make a computer beep using the programmable timer chip
(8254?). Send it signals on the I/O port saying "timer chip, speaker
signal, counter = N" (where N is the fundamental clock divided by the
frequency I wanted), and then "speaker, respond to timer chip". Then
you wait the right length of time, then send "speaker, stop responding
to timer chip".

Of course, I had a bug in the "wait the right length of time" part,
and my program stopped running.

My family was not amused.

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


Re: Beep on WIndows 11

2023-11-12 Thread Chris Angelico via Python-list
On Sun, 12 Nov 2023 at 21:27, Y Y via Python-list
 wrote:
>
> I am curious and humble to ask: What is the purpose of a BEEP?
>

There are several purposes. I can't say which of these are relevant to
the OP, but some or all of them could easily be.

* A very very simple notification that can be triggered by any program
* An audio cue that is not routed to your regular audio system (good
if you use headphones but are AFK)
* An extremely low level signal that requires little-to-no processing power
* An emergency signal that does not even require a CPU (probably not
in this instance though!)
* Imitating a pre-existing audio signal that works by beeping

Depending on what's needed, a more complex system might suffice (for
example, I cover the first two points by having an entire separate
audio subsystem with its own dedicated speakers, which I can invoke
using VLC in a specific configuration); but a basic beep is definitely
of value. I suspect in this situation that the first point is
important here, but it's up to the OP to elaborate.

(Note that the "no CPU emergency sound" option usually requires a
motherboard-mounted speaker or speaker header, which not all have
these days. Sad.)

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


Re: Checking if email is valid

2023-11-06 Thread Chris Angelico via Python-list
On Tue, 7 Nov 2023 at 10:11, Greg Ewing via Python-list
 wrote:
>
> On 7/11/23 7:45 am, Mats Wichmann wrote:
> > Continuing with the example, if you have a single phone number field, or
> > let a mobile number be entered in a field marked for landline, you will
> > probably assume you can text to that number.
>
> But if the site can detect that you've entered a mobile number into
> the landline field or vice versa and reject it, then it can figure out
> whether it can text to a given numner or not without you having
> to tell it!
>

Oh yes, it totally can. Never mind that some mobile numbers are able
to accept text messages but not calls, nor that some landline numbers
can accept text messages as well as calls :)

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


Re: Checking if email is valid

2023-11-06 Thread Chris Angelico via Python-list
On Tue, 7 Nov 2023 at 07:10, Mats Wichmann via Python-list
 wrote:
> Suggests maybe labeling should be something like:
>
> * Number you want to be called on
> * Number for texted security messages, if different
>
> Never seen that, though :-)
>

My responses would be:

* Don't.
* That's what cryptographic keys are for.

:)

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


Re: Checking if email is valid

2023-11-06 Thread Chris Angelico via Python-list
On Tue, 7 Nov 2023 at 02:05, Jon Ribbens via Python-list
 wrote:
> That was another thing that I used to find ridiculous, but seems to have
> improved somewhat in recent years - website error pages that said "please
> contact us to let us know about this error". I'm sorry, what? You want
> me to contact you to tell you about what your own website is doing? How
> does that make any sense? Websites should be self-reporting problems.

Actually, I think those serve a very important purpose. The reports
are almost certainly being discarded unread; the value of such a
reporting system is to give the user the sensation that they've "done
something" to "help". It makes some people feel better about running
into a bug.

But you're right, they serve little purpose in solving web site problems.

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


Re: pip/pip3 confusion and keeping up to date

2023-11-05 Thread Chris Green via Python-list
Jon Ribbens  wrote:
> On 2023-11-03, Karsten Hilbert  wrote:
> > Am Thu, Nov 02, 2023 at 04:07:33PM -0600 schrieb Mats Wichmann via 
> > Python-list:
> >> >So they now have only python3 and there is no python executable in
> >> >PATH.
> >>
> >> FWIW, for this you install the little stub package python-is-python3.
> >> Especially if you want to keep a python2 installation around -
> >> "python" will still be python3 in this case.
> >
> > Since you seem knowledgeable in this area: Do you know of a
> > resource for learning the *canonical* way of packaging a
> > Python application for installation via apt which
> >
> > - needs some packages available via apt
> > - needs some packages only available via pip
> > - needs some packages newer than what is available via apt
> >
> > ?
> 
> I suspect the answer to that is that you would have to:
> 
>   * create packages yourself for the unpackaged dependencies
>   * create a dependency graph of *every* Python package in the package
> repository (whether or not the package is relevant to what you're doing)
>   * work out what versions of every Python package are required in order
> to have a dependency graph that can be successfully resolved, taking
> into account the requirements of your new package also
>   * contact every single maintainer of every single one of the packages
> that needs updating and persuade them to update their packages and
> reassure them that you are getting all the other package maintainers
> to update their packages accordingly and that you have a plan and
> that you know what you're doing
> 
>   ... screen fades to black, title card "3 years later", fade in to ...
> 
>   * publish your package
> 
Surely it's not that bad, the vast bulk of Debian, Ubuntu and other
distributions are installed via systems that sort out dependencies once
given a particular package's requirements.  Python is surely not
unique in its dependency requirements.

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


Re: pip/pip3 confusion and keeping up to date

2023-11-03 Thread Chris Green via Python-list
Jon Ribbens  wrote:
> On 2023-11-02, Chris Green  wrote:
> > Jon Ribbens  wrote:
> >> On 2023-11-02, Chris Green  wrote:
> >> > I have a couple of systems which used to have python2 as well as
> >> > python3 but as Ubuntu and Debian verions have moved on they have
> >> > finally eliminated all dependencies on python2.
> >> >
> >> > So they now have only python3 and there is no python executable in
> >> > PATH. 
> >> >
> >> > There's still both /usr/bin/pip and /usr/bin/pip3 but they're
> >> > identical so presuably I can now simply use pip and it will be a
> >> > python3 pip.
> >> >
> >> >
> >> > So, going on from this, how do I do the equivalent of "apt update; apt
> >> > upgrade" for my globally installed pip packages?
> >> 
> >> I'm not sure what that question has to do with everything that preceded
> >> it, but you don't want to install python packages globally using pip.
> >> Either install them with 'apt', or install them in a virtual environment.
> >
> > Why in a virtual environment?  When I install a package whether from
> > apt or from pip I want everyone/everything on my system to be able to
> > use it.
> 
> Because pip barely plays well by itself, let alone with other package
> managers at the same time.
> 
Well that's a criticism of pip rather than of how I use it! :-)

OK, there are risks.


> > I do only install a few things using pip.
> 
> Are they not available in your system's package manager?
> I guess you might get away with "sudo -H pip install -U foo"
> for a couple of things, if they don't have many dependencies.

I obviously check the package manager and also other sources which
work through apt before resorting to using pip.

The sort of thing I have to use pip for is software for odd I2C sensor
devices and such.  These rarely have any dependencies or they are all
the same dependencies as the other I2C device software.  So,
hopefully, I won't hit any big problems.  I have to say that so far I
haven't been bitten.  

I would point out that this is mostly for a headless Beaglebone Black
single board computer (comparable with a Raspberry Pi) with only a
minimal 'console' installation of Debian so it's a pretty minimal
system.

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


Re: Checking if email is valid

2023-11-02 Thread Chris Angelico via Python-list
On Fri, 3 Nov 2023 at 12:21, AVI GROSS via Python-list
 wrote:
> My guess is that a first test of an email address might be to see if a decent 
> module of that kind fills out the object to your satisfaction. You can then 
> perhaps test parts of the object, rather than everything at once, to see if 
> it is obviously invalid. As an example, what does u...@alpha...com with 
> what seems to be lots of meaningless periods, get parsed into?
>

What do you mean by "obviously invalid"? Have you read the RFC?

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


Re: Checking if email is valid

2023-11-02 Thread Chris Angelico via Python-list
On Fri, 3 Nov 2023 at 07:17, Jon Ribbens via Python-list
 wrote:
>
> On 2023-11-02, Simon Connah  wrote:
> > Valid as in conforms to the standard. Although having looked at the
> > standard that might be more difficult than originally planned.
>
> Yes. Almost nobody actually implements "the standard" as in RFC 2822
> section 3.4.1 (which can contain, for example, non-printable control
> characters, and comments), nor is it particularly clear that they
> should. So while checking against "the spec" might sound right, it's
> highly unlikely that it's what you actually want. Would you really
> want to allow:
>
> (jam today) "chris @ \"home\""@ (Chris's host.)public.example
>
> for example? And would you be able to do anything with it if you did?

If by checking against the spec you mean "sending an email to it with
a code or magic link", then sure, allow that! It's still short
enough to fit on one line, even. Seems fine to me.

Of course, since that one is in the .example TLD, it's not actually
going to succeed, but now I'm curious whether you could craft a mail
server that mandates the Queen's rule of "jam tomorrow, jam yesterday,
but never jam today". That part is technically a comment, but it's a
clear violation of a royal decree, so that should cause the email to
bounce. It's jam every OTHER day, and today isn't any OTHER day.

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


Re: pip/pip3 confusion and keeping up to date

2023-11-02 Thread Chris Green via Python-list
Jon Ribbens  wrote:
> On 2023-11-02, Chris Green  wrote:
> > I have a couple of systems which used to have python2 as well as
> > python3 but as Ubuntu and Debian verions have moved on they have
> > finally eliminated all dependencies on python2.
> >
> > So they now have only python3 and there is no python executable in
> > PATH. 
> >
> > There's still both /usr/bin/pip and /usr/bin/pip3 but they're
> > identical so presuably I can now simply use pip and it will be a
> > python3 pip.
> >
> >
> > So, going on from this, how do I do the equivalent of "apt update; apt
> > upgrade" for my globally installed pip packages?
> 
> I'm not sure what that question has to do with everything that preceded
> it, but you don't want to install python packages globally using pip.
> Either install them with 'apt', or install them in a virtual environment.

Why in a virtual environment?  When I install a package whether from
apt or from pip I want everyone/everything on my system to be able to
use it.

I do only install a few things using pip.

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


Re: pip/pip3 confusion and keeping up to date

2023-11-02 Thread Chris Green via Python-list
Jon Ribbens  wrote:
> On 2023-11-02, Dieter Maurer  wrote:
> > Chris Green wrote at 2023-11-2 10:58 +:
> >> ...
> >>So, going on from this, how do I do the equivalent of "apt update; apt
> >>upgrade" for my globally installed pip packages?
> >
> > `pip list -o` will tell you for which packages there are upgrades
> > available.
> > `pip install -U ...` will upgrade packages.
> >
> > Be careful, though.
> > With `apt`, you usually have (`apt`) sources representing a consistent
> > package universe. Someone tests that package upgrades in this
> > universe do not break other packages (in this universe).
> > Because of this, upgrading poses low risk.
> >
> > `PyPI` does not guarantes consistency. A new package version
> > may be incompatible to a previous one -- and with other
> > package you have installed.
> >
> > I do not think that you would want to auto-upgrade all installed
> > packages.
> 
> Indeed. What you're describing is a very unfortunate failing of pip.
> 'Upgrade' doesn't even follow requirements when you tell it what to
> upgrade - e.g. if you do "pip install foo" and foo requires "bar<2"
> so you end up with:
> 
>PackageVersion
>-- -
>foo1.0.0
>bar1.2.0
> 
> and then a new version 1.3.0 of bar comes out and you do
> "pip install -U foo", pip will not upgrade bar even though it could
> and should, because foo is already at the latest version so pip won't
> even look at its dependencies.
> 
> Indeed there is no way of knowing that you should upgrade bar without
> manually following all the dependency graphs. ("pip list -o" will tell
> you there's a newer version, but that isn't the same - e.g. if the new
> version of bar was 2.0.0 then "pip list -o" will list it, but you should
> not upgrade to it.)
> 
> You can do "pip install -I foo", which will pointlessly reinstall foo
> and then presumably upgrade bar as well, thus probably getting to the
> right result via a rather roundabout route, but I'm not sure if that
> does indeed work properly and if it is a reliable and recommended way
> of doing things.

It is a bit of a minefield isn't it.  I try to minimise my use of
packages installed using pip for this very reason.  Maybe the safest
route would simply be to uninstall everything and then re-install it.
·
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   7   8   9   10   >