Re: Help needed - - running into issues with python and its tools

2024-08-04 Thread Mats Wichmann via Python-list

On 8/3/24 20:03, o1bigtenor via Python-list wrote:


My question was, is and will be (and the doc absolutely doesn't cover it)
how do I install a different version in the venv so that python 3.11.x on
the
system is not discombobulated by the python 3.12.x in the venv.
That python 3.12 would let me run the tools needed.
(Its the how to install the next version of python that I just haven't been
able to find information on - - - and I would be looking for information
on how to install on a *nix.)


To get a different Python "in" the venv, you use the version you want in 
the construction of the venv. For example:



$ python3.13 -m venv new_venv
$ new_venv/bin/python --version
Python 3.13.0b4
$ source new_venv/bin/activate
...




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


Re: Help needed - - running into issues with python and its tools

2024-08-04 Thread Peter J. Holzer via Python-list
On 2024-08-03 15:17:11 -0500, o1bigtenor via Python-list wrote:
> One of the tools I need to be able to use is esptools - -  well in the
> devuan world you need to run that on either Devaun 3 or 5 - - - its just
> not available on devuan 4.

Couldn't you just upgrade to Devuan 5, then?


> Tried installing all the tools I need using downloads and .deb installs but
> then I need to have python3.12 and that's also not part of Devuan4.

It seems weird that something would work with the (presumably) older
version of Python in Devuan 3 and the (presumably) newer version of
Python in Devuan 5, but not with the version in Devuan 4.


> Not versed enough to set up a good venv (if that's possible) so that I
> could work in that specific venv and have my cake (and get to eat it too
> (grin!).

You need to install Python first to create a venv. AFAIK there is no way
to set up a venv first and then install Python into it.

Does Devuan have a testing or unstable suite? You might be able to
install a newer Python version from that. If not your best bet is to
install Python from source.

hp


-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed - - running into issues with python and its tools

2024-08-03 Thread o1bigtenor via Python-list
On Sat, Aug 3, 2024 at 7:11 PM dn via Python-list 
wrote:

> On 4/08/24 09:34, o1bigtenor via Python-list wrote:
> > On Sat, Aug 3, 2024 at 4:06 PM dn via Python-list <
> python-list@python.org>
> > wrote:
> >
> >> On 4/08/24 08:17, o1bigtenor via Python-list wrote:
> >>> Greetings
> >>>
> >>> Looking at ESP8266 and wanting to program it using micropython (really
> >>> don't want to have to learn C++ (not enough hours in the day as it
> >> is!!)).
> >>>
> >>> One of the tools I need to be able to use is esptools - -  well in the
> >>> devuan world you need to run that on either Devaun 3 or 5 - - - its
> just
> >>> not available on devuan 4.
> >>>
> >>> Tried installing all the tools I need using downloads and .deb installs
> >> but
> >>> then I need to have python3.12 and that's also not part of Devuan4.
> >>>
> >>> Not versed enough to set up a good venv (if that's possible) so that I
> >>> could work in that specific venv and have my cake (and get to eat it
> too
> >>> (grin!).
> >>>
> >>> Suggestions - - - ideas - - - please?
> >>
> >> Sorry if this offends, but this is a list of short-cuts and reasons why
> >> they don't work (immediately).
> >>
> >>
> >> Have just come from a discussion about 'how to start a project'. Amongst
> >> the questions to ask are: "what resources do we have (or can add) to
> >> achieve?".
> >>
> >
> > Fair question details interleaved - - -
> >
> >>
> >> In this case, if Python-skill is a "personnel-resource" (and C++ a
> >> "constraint"), will question the ESP over Raspberry Pi (say)?
> >>
> >
> > Well - - - RPi world technical specs is usable from -20 to 60 C (iirc on
> > the top number)
> > and for my project I absolutely need to have usability to at least -40 -
> -
> > could possibly do a bit less but -35 C is a hard requirement so the RPi
> > and Pico (which I would like to use) is out but ESP8266 runs in that -40
> to
> > 65 C
> > range.
>
> Interesting, but creates a mis-match of tools - battles for you to fight...
>

Not really - - - it takes a computer with psytool and about 5 or 6 other
python3.12
programs to load the microcontroller.
It is in writing the program for the microcontroller that micropython is
used not at
all in the loading.

>
>
> >> Why talking of Python 3.12 when the solution involves MicroPython?
> >>
> >
> > Because one uses psytool on one computer to transfer a program to the
> > MicroPython system.  In fact there are a set of tools that need
> Python3.12
> > to be able to do this and therefore the question.
> >
> >>
> >>
> >> Perhaps need to take a step back and look at 'options' - relate needs to
> >> resources, and evaluate the impact of each decision on later ones - as
> >> well as against your personal skills (modify objectives to limits, or
> >> accept that some learning/training will be necessary as pre-requisite to
> >> (being able to) attack the project).
> >>
> >> I have been investigating using a venv but am not finding clear
> directions
> > so
> > that I could set up Python3.12 inside (along with the other needed
> tools).
> > The
> > more I'm looking the less useful most of the information I'm finding is
> > becoming.
> > Therefore I thought I would go to the python gurus for information - - -
> > which I
> > have.
> >
> > So please - - - how do I set up a venv so that I can install and run
> python
> > 3.12
> > (and other needed programs related to 3.12) inside?
>
> If you mean venv itself, which "directions" have you reviewed?
> This one (https://python.land/virtual-environments/virtualenv) seems
> very straight-forward and shows "What's inside a venv?" to include
> python.exe. Given that venv is more-or-less the official/traditional
> solution, what are you doing differently - perhaps the question is
> lacking detail.
>
> Interesting - - - that's the doc I have been reading.

My question was, is and will be (and the doc absolutely doesn't cover it)
how do I install a different version in the venv so that python 3.11.x on
the
system is not discombobulated by the python 3.12.x in the venv.
That python 3.12 would let me run the tools needed.
(Its the how to install the next version of python that I just haven't been
able to find information on - - - and I would be looking for information
on how to install on a *nix.)


> Personally, I'm using Poetry (https://python-poetry.org) which seemed
> just as easy to pick-up; plus pyenv to maintain multiple versions of
> Python on one machine.
>
>
Will give python-poetry a look.

Have been looking at pyenv but that seems to be a whole rat's nest of other
stuff to install and its using a bunch of different tools to get there - -
- is it
necessary - - - yes or no (in the running of multiple python versions on
the
same machine).

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


Re: Help needed - - running into issues with python and its tools

2024-08-03 Thread o1bigtenor via Python-list
On Sat, Aug 3, 2024 at 6:20 PM Cameron Simpson via Python-list <
python-list@python.org> wrote:

> On 03Aug2024 16:34, o1bigtenor  wrote:
> >So please - - - how do I set up a venv so that I can install and run
> >python
> >3.12
> >(and other needed programs related to 3.12) inside?
>
> Maybe this github comment will help with this:
>
> https://github.com/orgs/micropython/discussions/10255#discussioncomment-671
>

Not really.

A computer that has psytool + about 5 or 6 other python 3.12 tools is
needed to load
the microcontroller so I don't see how having venv in the microcontroller
would help the
loading of software onto the microcontroller.

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


Re: Help needed - - running into issues with python and its tools

2024-08-03 Thread dn via Python-list

On 4/08/24 09:34, o1bigtenor via Python-list wrote:

On Sat, Aug 3, 2024 at 4:06 PM dn via Python-list 
wrote:


On 4/08/24 08:17, o1bigtenor via Python-list wrote:

Greetings

Looking at ESP8266 and wanting to program it using micropython (really
don't want to have to learn C++ (not enough hours in the day as it

is!!)).


One of the tools I need to be able to use is esptools - -  well in the
devuan world you need to run that on either Devaun 3 or 5 - - - its just
not available on devuan 4.

Tried installing all the tools I need using downloads and .deb installs

but

then I need to have python3.12 and that's also not part of Devuan4.

Not versed enough to set up a good venv (if that's possible) so that I
could work in that specific venv and have my cake (and get to eat it too
(grin!).

Suggestions - - - ideas - - - please?


Sorry if this offends, but this is a list of short-cuts and reasons why
they don't work (immediately).


Have just come from a discussion about 'how to start a project'. Amongst
the questions to ask are: "what resources do we have (or can add) to
achieve?".



Fair question details interleaved - - -



In this case, if Python-skill is a "personnel-resource" (and C++ a
"constraint"), will question the ESP over Raspberry Pi (say)?



Well - - - RPi world technical specs is usable from -20 to 60 C (iirc on
the top number)
and for my project I absolutely need to have usability to at least -40 - -
could possibly do a bit less but -35 C is a hard requirement so the RPi
and Pico (which I would like to use) is out but ESP8266 runs in that -40 to
65 C
range.


Interesting, but creates a mis-match of tools - battles for you to fight...



Why talking of Python 3.12 when the solution involves MicroPython?



Because one uses psytool on one computer to transfer a program to the
MicroPython system.  In fact there are a set of tools that need Python3.12
to be able to do this and therefore the question.




Perhaps need to take a step back and look at 'options' - relate needs to
resources, and evaluate the impact of each decision on later ones - as
well as against your personal skills (modify objectives to limits, or
accept that some learning/training will be necessary as pre-requisite to
(being able to) attack the project).

I have been investigating using a venv but am not finding clear directions

so
that I could set up Python3.12 inside (along with the other needed tools).
The
more I'm looking the less useful most of the information I'm finding is
becoming.
Therefore I thought I would go to the python gurus for information - - -
which I
have.

So please - - - how do I set up a venv so that I can install and run python
3.12
(and other needed programs related to 3.12) inside?


If you mean venv itself, which "directions" have you reviewed?
This one (https://python.land/virtual-environments/virtualenv) seems 
very straight-forward and shows "What's inside a venv?" to include 
python.exe. Given that venv is more-or-less the official/traditional 
solution, what are you doing differently - perhaps the question is 
lacking detail.

(see also @Cameron's take)

Personally, I'm using Poetry (https://python-poetry.org) which seemed 
just as easy to pick-up; plus pyenv to maintain multiple versions of 
Python on one machine.


--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed - - running into issues with python and its tools

2024-08-03 Thread Cameron Simpson via Python-list

On 03Aug2024 16:34, o1bigtenor  wrote:
So please - - - how do I set up a venv so that I can install and run 
python

3.12
(and other needed programs related to 3.12) inside?


Maybe this github comment will help with this:
https://github.com/orgs/micropython/discussions/10255#discussioncomment-671
--
https://mail.python.org/mailman/listinfo/python-list


Re: Installation of Slixfeed with pip fails

2024-08-03 Thread Thomas Passin via Python-list

On 8/3/2024 2:49 PM, Barry Scott via Python-list wrote:




On 30 Jul 2024, at 18:36, Schimon Jehudah via Python-list 
 wrote:

Greetings, to one and all!

My name is Schimon, and I am the developer of a news chat bot for the
XMPP network, called Slixfeed.

I have recently added support for OMEMO encryption, and a friend of
mine has reported that there is an issue installing it with pip.

I suppoes this is a fault of a package at PyPi, or a fault at my
pyproject.toml.

This is the link to the project:
https://git.xmpp-it.net/sch/Slixfeed#getting-started

Please advise,


This question is like asking "My car won't run. I suppose it's the 
engine. Please advise."



Please duplicate the problem and if after doing that you have not fixed
the problem post details here.

Barry




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





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


Re: Help needed - - running into issues with python and its tools

2024-08-03 Thread o1bigtenor via Python-list
On Sat, Aug 3, 2024 at 4:06 PM dn via Python-list 
wrote:

> On 4/08/24 08:17, o1bigtenor via Python-list wrote:
> > Greetings
> >
> > Looking at ESP8266 and wanting to program it using micropython (really
> > don't want to have to learn C++ (not enough hours in the day as it
> is!!)).
> >
> > One of the tools I need to be able to use is esptools - -  well in the
> > devuan world you need to run that on either Devaun 3 or 5 - - - its just
> > not available on devuan 4.
> >
> > Tried installing all the tools I need using downloads and .deb installs
> but
> > then I need to have python3.12 and that's also not part of Devuan4.
> >
> > Not versed enough to set up a good venv (if that's possible) so that I
> > could work in that specific venv and have my cake (and get to eat it too
> > (grin!).
> >
> > Suggestions - - - ideas - - - please?
>
> Sorry if this offends, but this is a list of short-cuts and reasons why
> they don't work (immediately).
>
>
> Have just come from a discussion about 'how to start a project'. Amongst
> the questions to ask are: "what resources do we have (or can add) to
> achieve?".
>

Fair question details interleaved - - -

>
> In this case, if Python-skill is a "personnel-resource" (and C++ a
> "constraint"), will question the ESP over Raspberry Pi (say)?
>

Well - - - RPi world technical specs is usable from -20 to 60 C (iirc on
the top number)
and for my project I absolutely need to have usability to at least -40 - -
could possibly do a bit less but -35 C is a hard requirement so the RPi
and Pico (which I would like to use) is out but ESP8266 runs in that -40 to
65 C
range.

>
> Why talking of Python 3.12 when the solution involves MicroPython?
>

Because one uses psytool on one computer to transfer a program to the
MicroPython system.  In fact there are a set of tools that need Python3.12
to be able to do this and therefore the question.

>
>
> Perhaps need to take a step back and look at 'options' - relate needs to
> resources, and evaluate the impact of each decision on later ones - as
> well as against your personal skills (modify objectives to limits, or
> accept that some learning/training will be necessary as pre-requisite to
> (being able to) attack the project).
>
> I have been investigating using a venv but am not finding clear directions
so
that I could set up Python3.12 inside (along with the other needed tools).
The
more I'm looking the less useful most of the information I'm finding is
becoming.
Therefore I thought I would go to the python gurus for information - - -
which I
have.

So please - - - how do I set up a venv so that I can install and run python
3.12
(and other needed programs related to 3.12) inside?

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


Re: Help needed - - running into issues with python and its tools

2024-08-03 Thread dn via Python-list

On 4/08/24 08:17, o1bigtenor via Python-list wrote:

Greetings

Looking at ESP8266 and wanting to program it using micropython (really
don't want to have to learn C++ (not enough hours in the day as it is!!)).

One of the tools I need to be able to use is esptools - -  well in the
devuan world you need to run that on either Devaun 3 or 5 - - - its just
not available on devuan 4.

Tried installing all the tools I need using downloads and .deb installs but
then I need to have python3.12 and that's also not part of Devuan4.

Not versed enough to set up a good venv (if that's possible) so that I
could work in that specific venv and have my cake (and get to eat it too
(grin!).

Suggestions - - - ideas - - - please?


Sorry if this offends, but this is a list of short-cuts and reasons why 
they don't work (immediately).



Have just come from a discussion about 'how to start a project'. Amongst 
the questions to ask are: "what resources do we have (or can add) to 
achieve?".


In this case, if Python-skill is a "personnel-resource" (and C++ a 
"constraint"), will question the ESP over Raspberry Pi (say)?


Why talking of Python 3.12 when the solution involves MicroPython?


Perhaps need to take a step back and look at 'options' - relate needs to 
resources, and evaluate the impact of each decision on later ones - as 
well as against your personal skills (modify objectives to limits, or 
accept that some learning/training will be necessary as pre-requisite to 
(being able to) attack the project).


--
Regards =dn

--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Help needed - - running into issues with python and its tools

2024-08-03 Thread o1bigtenor via Python-list
Greetings

Looking at ESP8266 and wanting to program it using micropython (really
don't want to have to learn C++ (not enough hours in the day as it is!!)).

One of the tools I need to be able to use is esptools - -  well in the
devuan world you need to run that on either Devaun 3 or 5 - - - its just
not available on devuan 4.

Tried installing all the tools I need using downloads and .deb installs but
then I need to have python3.12 and that's also not part of Devuan4.

Not versed enough to set up a good venv (if that's possible) so that I
could work in that specific venv and have my cake (and get to eat it too
(grin!).

Suggestions - - - ideas - - - please?

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


Re: Installation of Slixfeed with pip fails

2024-08-03 Thread Barry Scott via Python-list



> On 30 Jul 2024, at 18:36, Schimon Jehudah via Python-list 
>  wrote:
> 
> Greetings, to one and all!
> 
> My name is Schimon, and I am the developer of a news chat bot for the
> XMPP network, called Slixfeed.
> 
> I have recently added support for OMEMO encryption, and a friend of
> mine has reported that there is an issue installing it with pip.
> 
> I suppoes this is a fault of a package at PyPi, or a fault at my
> pyproject.toml.
> 
> This is the link to the project:
> https://git.xmpp-it.net/sch/Slixfeed#getting-started
> 
> Please advise,

Please duplicate the problem and if after doing that you have not fixed
the problem post details here.

Barry



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

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


[RELEASE] Python 3.13.0 release candidate 1 released

2024-08-01 Thread Thomas Wouters via Python-list
Python 3.13 *release candidate 1* is now available.

https://www.python.org/downloads/release/python-3130rc1/

This
is the first release candidate of Python 3.13.0

This release, *3.13.0rc1*, is the penultimate release preview. Entering the
release candidate phase, only reviewed code changes which are clear bug
fixes are allowed between this release candidate and the final release. The
second candidate (and the last planned release preview) is scheduled for
Tuesday, 2024-09-03, while the official release of 3.13.0 is scheduled for
Tuesday, 2024-10-01.

There will be *no ABI changes* from this point forward in the 3.13 series,
and the goal is that there will be as few code changes as possible.
Call
to action

We strongly encourage maintainers of third-party Python projects to prepare
their projects for 3.13 compatibilities during this phase, and where
necessary publish Python 3.13 wheels on PyPI to be ready for the final
release of 3.13.0. Any binary wheels built against Python 3.13.0rc1 *will
work* with future versions of Python 3.13. As always, report any issues to the
Python bug tracker .

Please keep in mind that this is a preview release and while it’s as close
to the final release as we can get it, its use is *not* recommended for
production environments.
Core
developers: time to work on documentation now

   - Are all your changes properly documented?
   - Are they mentioned in What’s New
   ?
   - Did you notice other changes you know of to have insufficient
   documentation?

Major
new features of the 3.13 series, compared to 3.12

Some of the new major new features and changes in Python 3.13 are:
New
features

   - A new and improved interactive interpreter
   
,
   based on PyPy ’s, featuring multi-line editing and
   color support, as well as colorized exception tracebacks
   
   .
   - An *experimental* free-threaded build mode
   ,
   which disables the Global Interpreter Lock, allowing threads to run more
   concurrently. The build mode is available as an experimental feature in the
   Windows and macOS installers as well.
   - A preliminary, *experimental* JIT
   ,
   providing the ground work for significant performance improvements.
   - The locals() builtin function (and its C equivalent) now has well-defined
   semantics when mutating the returned mapping
   
,
   which allows debuggers to operate more consistently.
   - The (cyclic) garbage collector is now incremental
   
,
   which should mean shorter pauses for collection in programs with a lot of
   objects.
   - A modified version of mimalloc 
   is now included, optional but enabled by default if supported by the
   platform, and required for the free-threaded build mode.
   - Docstrings now have their leading indentation stripped
   ,
   reducing memory use and the size of .pyc files. (Most tools handling
   docstrings already strip leading indentation.)
   - The dbm module  has a
   new dbm.sqlite3 backend
    that is used by
   default when creating new files.
   - The minimum supported macOS version was changed from 10.9 to *10.13
   (High Sierra)*. Older macOS versions will not be supported going forward.
   - WASI is now a Tier 2 supported platform
   . Emscripten is no longer
an officially
   supported platform
    (but
   Pyodide  continues to support Emscripten).
   - iOS is now a Tier 3 supported platform
   , with Android on the way as well
   

Re: Predicting an object over an pretrained model is not working

2024-07-31 Thread marc nicole via Python-list
You invitation to read on machine is not helping, if you wanna enlighten us
on this specific case otherwise pls spare me such comments which i know

On Wed, 31 Jul 2024, 16:00 Grant Edwards via Python-list, <
python-list@python.org> wrote:

> On 2024-07-31, marc nicole via Python-list  wrote:
>
> > I suppose the meaning of those numbers comes from this line
> > predicts_dict[class_name].append([int(xmin), int(ymin), int(xmax),
> > int(ymax), P[index]]) as well as the yolo inference call. But i was
> > expecting zeros for all classes except smallball.
>
> That's not how machine learning and object recognition works.
>
> > Because the image only shows that,
>
> You know that. The machine doesn't.
>
> > and that a train and a sheep wont have any target position or any
> > probability whatsoever in the image weirdobject.jpg
>
> That depends on the training data and how the model works.
>
> You should probably do some reading on neural networks, machine
> learning, and pattern/object recognition. You appear to be trying to
> use tools without understanding what they do or how they work.
>
> --
> Grant
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Predicting an object over an pretrained model is not working

2024-07-31 Thread Grant Edwards via Python-list
On 2024-07-31, marc nicole via Python-list  wrote:

> I suppose the meaning of those numbers comes from this line
> predicts_dict[class_name].append([int(xmin), int(ymin), int(xmax),
> int(ymax), P[index]]) as well as the yolo inference call. But i was
> expecting zeros for all classes except smallball.

That's not how machine learning and object recognition works.

> Because the image only shows that,

You know that. The machine doesn't.

> and that a train and a sheep wont have any target position or any
> probability whatsoever in the image weirdobject.jpg

That depends on the training data and how the model works.

You should probably do some reading on neural networks, machine
learning, and pattern/object recognition. You appear to be trying to
use tools without understanding what they do or how they work.

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


Re: Predicting an object over an pretrained model is not working

2024-07-31 Thread marc nicole via Python-list
I suppose the meaning of those numbers comes from this line
predicts_dict[class_name].append([int(xmin), int(ymin), int(xmax), int(ymax),
P[index]]) as well as the yolo inference call. But i was expecting zeros
for all classes except smallball. Because the image only shows that, and
that a train and a sheep wont have any target position or any probability
whatsoever in the image weirdobject.jpg


On Wed, 31 Jul 2024, 00:19 dn via Python-list, 
wrote:

> On 31/07/24 06:18, marc nicole via Python-list wrote:
> > Hello all,
> >
> > I want to predict an object by given as input an image and want to have
> my
> > model be able to predict the label. I have trained a model using
> tensorflow
> > based on annotated database where the target object to predict was added
> to
> > the pretrained model. the code I am using is the following where I set
> the
> > target object image as input and want to have the prediction output:
>
> ...
>
>
> > WHile I expect only the dict to contain the small_ball key
>
> > How's that is possible? where's the prediction output?How to fix the
> code?
>
>
> To save us lots of reading and study to be able to help you, please advise:
>
> 1 what are the meanings of all these numbers?
>
> > 'sheep': [[233.0, 92.0, 448.0, -103.0,
> >> 5.3531270027160645], [167.0, 509.0, 209.0, 101.0, 4.947688579559326],
> >> [0.0, 0.0, 448.0, 431.0, 3.393721580505371]]
>
> 2 (assuming it hasn't) why the dict has not been sorted into a
> meaningful order
>
> 3 how can one tell that the image is more likely to be a sheep than a
> train?
>
> --
> Regards,
> =dn
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Predicting an object over an pretrained model is not working

2024-07-30 Thread dn via Python-list

On 31/07/24 06:18, marc nicole via Python-list wrote:

Hello all,

I want to predict an object by given as input an image and want to have my
model be able to predict the label. I have trained a model using tensorflow
based on annotated database where the target object to predict was added to
the pretrained model. the code I am using is the following where I set the
target object image as input and want to have the prediction output:


...



WHile I expect only the dict to contain the small_ball key



How's that is possible? where's the prediction output?How to fix the code?



To save us lots of reading and study to be able to help you, please advise:

1 what are the meanings of all these numbers?


'sheep': [[233.0, 92.0, 448.0, -103.0,

5.3531270027160645], [167.0, 509.0, 209.0, 101.0, 4.947688579559326],
[0.0, 0.0, 448.0, 431.0, 3.393721580505371]]


2 (assuming it hasn't) why the dict has not been sorted into a 
meaningful order


3 how can one tell that the image is more likely to be a sheep than a train?

--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Predicting an object over an pretrained model is not working

2024-07-30 Thread Thomas Passin via Python-list

On 7/30/2024 4:49 PM, marc nicole wrote:
OK, but how's the probability of small_ball greater than others? I can't 
find it anyway, what's its value?


It's your code. I wouldn't know. I suppose it's represented somewhere in 
all those parameters. You need to understand what those function calls 
are returning.  It's documented somewhere, right?


And you really do need to know the probabilities of the competing images 
because otherwise you won't know how confident you can be that the 
identification is a strong one.


Le mar. 30 juil. 2024 à 21:37, Thomas Passin via Python-list 
mailto:python-list@python.org>> a écrit :


On 7/30/2024 2:18 PM, marc nicole via Python-list wrote:
 > Hello all,
 >
 > I want to predict an object by given as input an image and want
to have my
 > model be able to predict the label. I have trained a model using
tensorflow
 > based on annotated database where the target object to predict
was added to
 > the pretrained model. the code I am using is the following where
I set the
 > target object image as input and want to have the prediction output:
 >
 >
 >
 >
 >
 >
 >
 >
 > class MultiObjectDetection():
 >
 >      def __init__(self, classes_name):
 >
 >          self._classes_name = classes_name
 >          self._num_classes = len(classes_name)
 >
 >          self._common_params = {'image_size': 448, 'num_classes':
 > self._num_classes,
 >                  'batch_size':1}
 >          self._net_params = {'cell_size': 7, 'boxes_per_cell':2,
 > 'weight_decay': 0.0005}
 >          self._net = YoloTinyNet(self._common_params,
self._net_params,
 > test=True)
 >
 >      def predict_object(self, image):
 >          predicts = self._net.inference(image)
 >          return predicts
 >
 >      def process_predicts(self, resized_img, predicts, thresh=0.2):
 >          """
 >          process the predicts of object detection with one image
input.
 >
 >          Args:
 >              resized_img: resized source image.
 >              predicts: output of the model.
 >              thresh: thresh of bounding box confidence.
 >          Return:
 >              predicts_dict: {"stick": [[x1, y1, x2, y2, scores1],
[...]]}.
 >          """
 >          cls_num = self._num_classes
 >          bbx_per_cell = self._net_params["boxes_per_cell"]
 >          cell_size = self._net_params["cell_size"]
 >          img_size = self._common_params["image_size"]
 >          p_classes = predicts[0, :, :, 0:cls_num]
 >          C = predicts[0, :, :, cls_num:cls_num+bbx_per_cell] # two
 > bounding boxes in one cell.
 >          coordinate = predicts[0, :, :, cls_num+bbx_per_cell:] # all
 > bounding boxes position.
 >
 >          p_classes = np.reshape(p_classes, (cell_size, cell_size,
1, cls_num))
 >          C = np.reshape(C, (cell_size, cell_size, bbx_per_cell, 1))
 >
 >          P = C * p_classes # confidencefor all classes of all
bounding
 > boxes (cell_size, cell_size, bounding_box_num, class_num) = (7, 7, 2,
 > 1).
 >
 >          predicts_dict = {}
 >          for i in range(cell_size):
 >              for j in range(cell_size):
 >                  temp_data = np.zeros_like(P, np.float32)
 >                  temp_data[i, j, :, :] = P[i, j, :, :]
 >                  position = np.argmax(temp_data) # refer to the class
 > num (with maximum confidence) for every bounding box.
 >                  index = np.unravel_index(position, P.shape)
 >
 >                  if P[index] > thresh:
 >                      class_num = index[-1]
 >                      coordinate = np.reshape(coordinate, (cell_size,
 > cell_size, bbx_per_cell, 4)) # (cell_size, cell_size,
 > bbox_num_per_cell, coordinate)[xmin, ymin, xmax, ymax]
 >                      max_coordinate = coordinate[index[0],
index[1], index[2], :]
 >
 >                      xcenter = max_coordinate[0]
 >                      ycenter = max_coordinate[1]
 >                      w = max_coordinate[2]
 >                      h = max_coordinate[3]
 >
 >                      xcenter = (index[1] + xcenter) *
(1.0*img_size /cell_size)
 >                      ycenter = (index[0] + ycenter) *
(1.0*img_size /cell_size)
 >
 >                      w = w * img_size
 >                      h = h * img_size
 >                      xmin = 0 if (xcenter - w/2.0 < 0) else
(xcenter - w/2.0)
 >                      ymin = 0 if (xcenter - w/2.0 < 0) else
(ycenter - h/2.0)
 >                      xmax = resized_img.shape[0] if (xmin + w) >
 > resized_img.shape[0] else (xmin + w)
 >                      ymax = resized_img.shape[1] if (ymin + h) >
 > 

Re: Predicting an object over an pretrained model is not working

2024-07-30 Thread marc nicole via Python-list
OK, but how's the probability of small_ball greater than others? I can't
find it anyway, what's its value?

Le mar. 30 juil. 2024 à 21:37, Thomas Passin via Python-list <
python-list@python.org> a écrit :

> On 7/30/2024 2:18 PM, marc nicole via Python-list wrote:
> > Hello all,
> >
> > I want to predict an object by given as input an image and want to have
> my
> > model be able to predict the label. I have trained a model using
> tensorflow
> > based on annotated database where the target object to predict was added
> to
> > the pretrained model. the code I am using is the following where I set
> the
> > target object image as input and want to have the prediction output:
> >
> >
> >
> >
> >
> >
> >
> >
> > class MultiObjectDetection():
> >
> >  def __init__(self, classes_name):
> >
> >  self._classes_name = classes_name
> >  self._num_classes = len(classes_name)
> >
> >  self._common_params = {'image_size': 448, 'num_classes':
> > self._num_classes,
> >  'batch_size':1}
> >  self._net_params = {'cell_size': 7, 'boxes_per_cell':2,
> > 'weight_decay': 0.0005}
> >  self._net = YoloTinyNet(self._common_params, self._net_params,
> > test=True)
> >
> >  def predict_object(self, image):
> >  predicts = self._net.inference(image)
> >  return predicts
> >
> >  def process_predicts(self, resized_img, predicts, thresh=0.2):
> >  """
> >  process the predicts of object detection with one image input.
> >
> >  Args:
> >  resized_img: resized source image.
> >  predicts: output of the model.
> >  thresh: thresh of bounding box confidence.
> >  Return:
> >  predicts_dict: {"stick": [[x1, y1, x2, y2, scores1],
> [...]]}.
> >  """
> >  cls_num = self._num_classes
> >  bbx_per_cell = self._net_params["boxes_per_cell"]
> >  cell_size = self._net_params["cell_size"]
> >  img_size = self._common_params["image_size"]
> >  p_classes = predicts[0, :, :, 0:cls_num]
> >  C = predicts[0, :, :, cls_num:cls_num+bbx_per_cell] # two
> > bounding boxes in one cell.
> >  coordinate = predicts[0, :, :, cls_num+bbx_per_cell:] # all
> > bounding boxes position.
> >
> >  p_classes = np.reshape(p_classes, (cell_size, cell_size, 1,
> cls_num))
> >  C = np.reshape(C, (cell_size, cell_size, bbx_per_cell, 1))
> >
> >  P = C * p_classes # confidencefor all classes of all bounding
> > boxes (cell_size, cell_size, bounding_box_num, class_num) = (7, 7, 2,
> > 1).
> >
> >  predicts_dict = {}
> >  for i in range(cell_size):
> >  for j in range(cell_size):
> >  temp_data = np.zeros_like(P, np.float32)
> >  temp_data[i, j, :, :] = P[i, j, :, :]
> >  position = np.argmax(temp_data) # refer to the class
> > num (with maximum confidence) for every bounding box.
> >  index = np.unravel_index(position, P.shape)
> >
> >  if P[index] > thresh:
> >  class_num = index[-1]
> >  coordinate = np.reshape(coordinate, (cell_size,
> > cell_size, bbx_per_cell, 4)) # (cell_size, cell_size,
> > bbox_num_per_cell, coordinate)[xmin, ymin, xmax, ymax]
> >  max_coordinate = coordinate[index[0], index[1],
> index[2], :]
> >
> >  xcenter = max_coordinate[0]
> >  ycenter = max_coordinate[1]
> >  w = max_coordinate[2]
> >  h = max_coordinate[3]
> >
> >  xcenter = (index[1] + xcenter) * (1.0*img_size
> /cell_size)
> >  ycenter = (index[0] + ycenter) * (1.0*img_size
> /cell_size)
> >
> >  w = w * img_size
> >  h = h * img_size
> >  xmin = 0 if (xcenter - w/2.0 < 0) else (xcenter -
> w/2.0)
> >  ymin = 0 if (xcenter - w/2.0 < 0) else (ycenter -
> h/2.0)
> >  xmax = resized_img.shape[0] if (xmin + w) >
> > resized_img.shape[0] else (xmin + w)
> >  ymax = resized_img.shape[1] if (ymin + h) >
> > resized_img.shape[1] else (ymin + h)
> >
> >  class_name = self._classes_name[class_num]
> >  predicts_dict.setdefault(class_name, [])
> >  predicts_dict[class_name].append([int(xmin),
> > int(ymin), int(xmax), int(ymax), P[index]])
> >
> >  return predicts_dict
> >
> >  def non_max_suppress(self, predicts_dict, threshold=0.5):
> >  """
> >  implement non-maximum supression on predict bounding boxes.
> >  Args:
> >  predicts_dict: {"stick": [[x1, y1, x2, y2, scores1],
> [...]]}.
> >  threshhold: iou threshold
> >  Return:
> >  predicts_dict processed by non-maximum suppression
> >  """
> >  

Re: Predicting an object over an pretrained model is not working

2024-07-30 Thread Thomas Passin via Python-list

On 7/30/2024 2:18 PM, marc nicole via Python-list wrote:

Hello all,

I want to predict an object by given as input an image and want to have my
model be able to predict the label. I have trained a model using tensorflow
based on annotated database where the target object to predict was added to
the pretrained model. the code I am using is the following where I set the
target object image as input and want to have the prediction output:








class MultiObjectDetection():

 def __init__(self, classes_name):

 self._classes_name = classes_name
 self._num_classes = len(classes_name)

 self._common_params = {'image_size': 448, 'num_classes':
self._num_classes,
 'batch_size':1}
 self._net_params = {'cell_size': 7, 'boxes_per_cell':2,
'weight_decay': 0.0005}
 self._net = YoloTinyNet(self._common_params, self._net_params,
test=True)

 def predict_object(self, image):
 predicts = self._net.inference(image)
 return predicts

 def process_predicts(self, resized_img, predicts, thresh=0.2):
 """
 process the predicts of object detection with one image input.

 Args:
 resized_img: resized source image.
 predicts: output of the model.
 thresh: thresh of bounding box confidence.
 Return:
 predicts_dict: {"stick": [[x1, y1, x2, y2, scores1], [...]]}.
 """
 cls_num = self._num_classes
 bbx_per_cell = self._net_params["boxes_per_cell"]
 cell_size = self._net_params["cell_size"]
 img_size = self._common_params["image_size"]
 p_classes = predicts[0, :, :, 0:cls_num]
 C = predicts[0, :, :, cls_num:cls_num+bbx_per_cell] # two
bounding boxes in one cell.
 coordinate = predicts[0, :, :, cls_num+bbx_per_cell:] # all
bounding boxes position.

 p_classes = np.reshape(p_classes, (cell_size, cell_size, 1, cls_num))
 C = np.reshape(C, (cell_size, cell_size, bbx_per_cell, 1))

 P = C * p_classes # confidencefor all classes of all bounding
boxes (cell_size, cell_size, bounding_box_num, class_num) = (7, 7, 2,
1).

 predicts_dict = {}
 for i in range(cell_size):
 for j in range(cell_size):
 temp_data = np.zeros_like(P, np.float32)
 temp_data[i, j, :, :] = P[i, j, :, :]
 position = np.argmax(temp_data) # refer to the class
num (with maximum confidence) for every bounding box.
 index = np.unravel_index(position, P.shape)

 if P[index] > thresh:
 class_num = index[-1]
 coordinate = np.reshape(coordinate, (cell_size,
cell_size, bbx_per_cell, 4)) # (cell_size, cell_size,
bbox_num_per_cell, coordinate)[xmin, ymin, xmax, ymax]
 max_coordinate = coordinate[index[0], index[1], index[2], 
:]

 xcenter = max_coordinate[0]
 ycenter = max_coordinate[1]
 w = max_coordinate[2]
 h = max_coordinate[3]

 xcenter = (index[1] + xcenter) * (1.0*img_size /cell_size)
 ycenter = (index[0] + ycenter) * (1.0*img_size /cell_size)

 w = w * img_size
 h = h * img_size
 xmin = 0 if (xcenter - w/2.0 < 0) else (xcenter - w/2.0)
 ymin = 0 if (xcenter - w/2.0 < 0) else (ycenter - h/2.0)
 xmax = resized_img.shape[0] if (xmin + w) >
resized_img.shape[0] else (xmin + w)
 ymax = resized_img.shape[1] if (ymin + h) >
resized_img.shape[1] else (ymin + h)

 class_name = self._classes_name[class_num]
 predicts_dict.setdefault(class_name, [])
 predicts_dict[class_name].append([int(xmin),
int(ymin), int(xmax), int(ymax), P[index]])

 return predicts_dict

 def non_max_suppress(self, predicts_dict, threshold=0.5):
 """
 implement non-maximum supression on predict bounding boxes.
 Args:
 predicts_dict: {"stick": [[x1, y1, x2, y2, scores1], [...]]}.
 threshhold: iou threshold
 Return:
 predicts_dict processed by non-maximum suppression
 """
 for object_name, bbox in predicts_dict.items():
 bbox_array = np.array(bbox, dtype=np.float)
 x1, y1, x2, y2, scores = bbox_array[:,0], bbox_array[:,1],
bbox_array[:,2], bbox_array[:,3], bbox_array[:,4]
 areas = (x2-x1+1) * (y2-y1+1)
 order = scores.argsort()[::-1]
 keep = []
 while order.size > 0:
 i = order[0]
 keep.append(i)
 xx1 = np.maximum(x1[i], x1[order[1:]])
 yy1 = np.maximum(y1[i], y1[order[1:]])
 xx2 = np.minimum(x2[i], x2[order[1:]])
 yy2 = np.minimum(y2[i], 

Predicting an object over an pretrained model is not working

2024-07-30 Thread marc nicole via Python-list
Hello all,

I want to predict an object by given as input an image and want to have my
model be able to predict the label. I have trained a model using tensorflow
based on annotated database where the target object to predict was added to
the pretrained model. the code I am using is the following where I set the
target object image as input and want to have the prediction output:








class MultiObjectDetection():

def __init__(self, classes_name):

self._classes_name = classes_name
self._num_classes = len(classes_name)

self._common_params = {'image_size': 448, 'num_classes':
self._num_classes,
'batch_size':1}
self._net_params = {'cell_size': 7, 'boxes_per_cell':2,
'weight_decay': 0.0005}
self._net = YoloTinyNet(self._common_params, self._net_params,
test=True)

def predict_object(self, image):
predicts = self._net.inference(image)
return predicts

def process_predicts(self, resized_img, predicts, thresh=0.2):
"""
process the predicts of object detection with one image input.

Args:
resized_img: resized source image.
predicts: output of the model.
thresh: thresh of bounding box confidence.
Return:
predicts_dict: {"stick": [[x1, y1, x2, y2, scores1], [...]]}.
"""
cls_num = self._num_classes
bbx_per_cell = self._net_params["boxes_per_cell"]
cell_size = self._net_params["cell_size"]
img_size = self._common_params["image_size"]
p_classes = predicts[0, :, :, 0:cls_num]
C = predicts[0, :, :, cls_num:cls_num+bbx_per_cell] # two
bounding boxes in one cell.
coordinate = predicts[0, :, :, cls_num+bbx_per_cell:] # all
bounding boxes position.

p_classes = np.reshape(p_classes, (cell_size, cell_size, 1, cls_num))
C = np.reshape(C, (cell_size, cell_size, bbx_per_cell, 1))

P = C * p_classes # confidencefor all classes of all bounding
boxes (cell_size, cell_size, bounding_box_num, class_num) = (7, 7, 2,
1).

predicts_dict = {}
for i in range(cell_size):
for j in range(cell_size):
temp_data = np.zeros_like(P, np.float32)
temp_data[i, j, :, :] = P[i, j, :, :]
position = np.argmax(temp_data) # refer to the class
num (with maximum confidence) for every bounding box.
index = np.unravel_index(position, P.shape)

if P[index] > thresh:
class_num = index[-1]
coordinate = np.reshape(coordinate, (cell_size,
cell_size, bbx_per_cell, 4)) # (cell_size, cell_size,
bbox_num_per_cell, coordinate)[xmin, ymin, xmax, ymax]
max_coordinate = coordinate[index[0], index[1], index[2], :]

xcenter = max_coordinate[0]
ycenter = max_coordinate[1]
w = max_coordinate[2]
h = max_coordinate[3]

xcenter = (index[1] + xcenter) * (1.0*img_size /cell_size)
ycenter = (index[0] + ycenter) * (1.0*img_size /cell_size)

w = w * img_size
h = h * img_size
xmin = 0 if (xcenter - w/2.0 < 0) else (xcenter - w/2.0)
ymin = 0 if (xcenter - w/2.0 < 0) else (ycenter - h/2.0)
xmax = resized_img.shape[0] if (xmin + w) >
resized_img.shape[0] else (xmin + w)
ymax = resized_img.shape[1] if (ymin + h) >
resized_img.shape[1] else (ymin + h)

class_name = self._classes_name[class_num]
predicts_dict.setdefault(class_name, [])
predicts_dict[class_name].append([int(xmin),
int(ymin), int(xmax), int(ymax), P[index]])

return predicts_dict

def non_max_suppress(self, predicts_dict, threshold=0.5):
"""
implement non-maximum supression on predict bounding boxes.
Args:
predicts_dict: {"stick": [[x1, y1, x2, y2, scores1], [...]]}.
threshhold: iou threshold
Return:
predicts_dict processed by non-maximum suppression
"""
for object_name, bbox in predicts_dict.items():
bbox_array = np.array(bbox, dtype=np.float)
x1, y1, x2, y2, scores = bbox_array[:,0], bbox_array[:,1],
bbox_array[:,2], bbox_array[:,3], bbox_array[:,4]
areas = (x2-x1+1) * (y2-y1+1)
order = scores.argsort()[::-1]
keep = []
while order.size > 0:
i = order[0]
keep.append(i)
xx1 = np.maximum(x1[i], x1[order[1:]])
yy1 = np.maximum(y1[i], y1[order[1:]])
xx2 = np.minimum(x2[i], x2[order[1:]])
yy2 = np.minimum(y2[i], y2[order[1:]])
inter = np.maximum(0.0, xx2-xx1+1) * np.maximum(0.0, yy2-yy1+1)
iou = 

Installation of Slixfeed with pip fails

2024-07-30 Thread Schimon Jehudah via Python-list
Greetings, to one and all!

My name is Schimon, and I am the developer of a news chat bot for the
XMPP network, called Slixfeed.

I have recently added support for OMEMO encryption, and a friend of
mine has reported that there is an issue installing it with pip.

I suppoes this is a fault of a package at PyPi, or a fault at my
pyproject.toml.

This is the link to the project:
https://git.xmpp-it.net/sch/Slixfeed#getting-started

Please advise,
Schimon
-- 
https://mail.python.org/mailman/listinfo/python-list


I need a free LAMP hosting and a iMac

2024-07-29 Thread Benjamin via Python-list
Hi,

For several months I have searched free web hosing in Google, but have not find 
a satisfying result now. Any body know some good LAMP free web hosting?

And, I have lost job since 2018, my macbook has only 2 intel core, I want to 
buy a new iMac for person programming, but I have only little money, any body 
donate me a iMac with ARM CPU?  or donate some money at
https://buymeacoffee.com/benjamin_yin 

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


Re: Issue with pip Installation on My Laptop

2024-07-27 Thread Mats Wichmann via Python-list

On 7/27/24 17:13, MRAB via Python-list wrote:

On 2024-07-27 21:58, Mats Wichmann via Python-list wrote:

On 7/26/24 16:28, Thomas Passin via Python-list wrote:

On 7/26/2024 7:25 AM, Lizna Shah via Python-list wrote:
OSError: [WinError 225] Operation did not complete successfully 
because the

file contains a virus or potentially unwanted software


That part of the error message tells you the story.  Windows thinks 
some file in the install has been corrupted with malware.





The Windows installer comes with pip, there's no need to do an extra
install to get it:

python -m pip --version


On Windows it's recommended that you use the Python Launcher 'py':

py -m pip --version


I agree! :-)  but since the OP had apparently done enough to get the 
command named "python" to work, was trying to not introduce one extra 
factor.



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


Re: Issue with pip Installation on My Laptop

2024-07-27 Thread MRAB via Python-list

On 2024-07-27 21:58, Mats Wichmann via Python-list wrote:

On 7/26/24 16:28, Thomas Passin via Python-list wrote:

On 7/26/2024 7:25 AM, Lizna Shah via Python-list wrote:
OSError: [WinError 225] Operation did not complete successfully 
because the

file contains a virus or potentially unwanted software


That part of the error message tells you the story.  Windows thinks some 
file in the install has been corrupted with malware.





The Windows installer comes with pip, there's no need to do an extra
install to get it:

python -m pip --version


On Windows it's recommended that you use the Python Launcher 'py':

py -m pip --version


If you can't find the pip *command*, that's a problem with yout PATH
settings.  The Python installer offers to add the location of Python
itself to PATH, and you've apparently taken it up on that offer, but
that's not the same directory that pip goes to.  Just use it as a module
and you should be fine.


===

The typical paths will be something like

C:\Users\you\AppData\Local\Programs\Python\Python310   # python executable
C:\Users\you\AppData\Local\Programs\Python\Python310\Scripts   # pip
"executable"


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


Re: Issue with pip Installation on My Laptop

2024-07-27 Thread Mats Wichmann via Python-list

On 7/26/24 16:28, Thomas Passin via Python-list wrote:

On 7/26/2024 7:25 AM, Lizna Shah via Python-list wrote:
OSError: [WinError 225] Operation did not complete successfully 
because the

file contains a virus or potentially unwanted software


That part of the error message tells you the story.  Windows thinks some 
file in the install has been corrupted with malware.





The Windows installer comes with pip, there's no need to do an extra 
install to get it:


python -m pip --version

If you can't find the pip *command*, that's a problem with yout PATH 
settings.  The Python installer offers to add the location of Python 
itself to PATH, and you've apparently taken it up on that offer, but 
that's not the same directory that pip goes to.  Just use it as a module 
and you should be fine.



===

The typical paths will be something like

C:\Users\you\AppData\Local\Programs\Python\Python310   # python executable
C:\Users\you\AppData\Local\Programs\Python\Python310\Scripts   # pip 
"executable"

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


Re: Issue with pip Installation on My Laptop

2024-07-26 Thread Thomas Passin via Python-list

On 7/26/2024 7:25 AM, Lizna Shah via Python-list wrote:

OSError: [WinError 225] Operation did not complete successfully because the
file contains a virus or potentially unwanted software


That part of the error message tells you the story.  Windows thinks some 
file in the install has been corrupted with malware.


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


Issue with pip Installation on My Laptop

2024-07-26 Thread Lizna Shah via Python-list
  Hello,

I am experiencing a problem with pip not being installed on my laptop and
would appreciate any assistance you can provide.

 Here are the details of my issue: -

Operating System: Windows
Python Version: Python 3.10.10
Steps I have already taken to try and resolve the issue:
1. Verified that Python is installed by running `python --version` (output:
[Python 3.10.10]).
2. Tried to install pip using the command `python -m ensurepip` and
received the following error:
Traceback (most recent call last):
  File "C:\Users\LIZNA
SHAH\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in
_run_module_as_main
return _run_code(code, main_globals, None,
  File "C:\Users\LIZNA
SHAH\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in
_run_code
exec(code, run_globals)
  File "C:\Users\LIZNA
SHAH\AppData\Local\Programs\Python\Python310\lib\ensurepip\__main__.py",
line 5, in 
sys.exit(ensurepip._main())
  File "C:\Users\LIZNA
SHAH\AppData\Local\Programs\Python\Python310\lib\ensurepip\__init__.py",
line 287, in _main
return _bootstrap(
  File "C:\Users\LIZNA
SHAH\AppData\Local\Programs\Python\Python310\lib\ensurepip\__init__.py",
line 203, in _bootstrap
return _run_pip([*args, *_PACKAGE_NAMES], additional_paths)
  File "C:\Users\LIZNA
SHAH\AppData\Local\Programs\Python\Python310\lib\ensurepip\__init__.py",
line 104, in _run_pip
return subprocess.run(cmd, check=True).returncode
  File "C:\Users\LIZNA
SHAH\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 503,
in run
with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\LIZNA
SHAH\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 971,
in init
self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\LIZNA
SHAH\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1440,
in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 225] Operation did not complete successfully because the
file contains a virus or potentially unwanted software

3. Attempted to use `get-pip.py` script from the official website, but
encountered: ['get-pip.py' is not recognized as an internal or external
command,
operable program or batch file.].

Additional information: - I was able to use pip successfully with previous
versions of Python on this laptop.

I would be grateful for any guidance or troubleshooting steps you could
suggest to resolve this issue. Thank you.

Best regards,
Lizna Shah
Nepal
-- 
https://mail.python.org/mailman/listinfo/python-list


[RELEASE] Python 3.13.0 beta 4 released.

2024-07-18 Thread Thomas Wouters via Python-list
Python 3.13.0b4, the final beta of Python 3.13, is now available:

https://www.python.org/downloads/release/python-3130b4/

*This is a beta preview of Python 3.13*

Python 3.13 is still in development. This release, 3.13.0b4, is the *final*
beta release preview of 3.13.

Beta release previews are intended to give the wider community the
opportunity to test new features and bug fixes and to prepare their
projects to support the new feature release.

We *strongly encourage* maintainers of third-party Python projects to *test
with 3.13* during the beta phase and report issues found to the Python bug
tracker  as soon as possible.
While the release is planned to be feature complete entering the beta
phase, it is possible that features may be modified or, in rare cases,
deleted up until the start of the release candidate phase (Tuesday
2024-07-30). Our goal is to have *no ABI changes* after this final beta
release, and as few code changes as possible after 3.13.0rc1, the first
release candidate. To achieve that, it will be *extremely important* to get
as much exposure for 3.13 as possible during the beta phase.

Please keep in mind that this is a preview release and its use is *not*
recommended for production environments.
Major
new features of the 3.13 series, compared to 3.12

Some of the new major new features and changes in Python 3.13 are:
New
features

   - A new and improved interactive interpreter
   
,
   based on PyPy ’s, featuring multi-line editing and
   color support, as well as colorized exception tracebacks
   
   .
   - An *experimental* free-threaded build mode
   ,
   which disables the Global Interpreter Lock, allowing threads to run more
   concurrently. The build mode is available as an experimental feature in the
   Windows and macOS installers as well.
   - A preliminary, *experimental* JIT
   ,
   providing the ground work for significant performance improvements.
   - The locals() builtin function (and its C equivalent) now has well-defined
   semantics when mutating the returned mapping
   
,
   which allows debuggers to operate more consistently.
   - The (cyclic) garbage collector is now incremental
   
,
   which should mean shorter pauses for collection in programs with a lot of
   objects.
   - A modified version of mimalloc 
   is now included, optional but enabled by default if supported by the
   platform, and required for the free-threaded build mode.
   - Docstrings now have their leading indentation stripped
   ,
   reducing memory use and the size of .pyc files. (Most tools handling
   docstrings already strip leading indentation.)
   - The dbm module  has a
   new dbm.sqlite3 backend
    that is used by
   default when creating new files.
   - The minimum supported macOS version was changed from 10.9 to *10.13
   (High Sierra)*. Older macOS versions will not be supported going forward.
   - WASI is now a Tier 2 supported platform
   . Emscripten is no longer
an officially
   supported platform
    (but
   Pyodide  continues to support Emscripten).


Typing

   - Support for type defaults in type parameters
   .
   - A new type narrowing annotation ,
   typing.TypeIs.
   - A new annotation for read-only items in TypeDicts
   .
   - A new annotation for marking deprecations in the type system
   .

Removals
and new deprecations

   - PEP 594 (Removing dead batteries from the standard library)
    scheduled removals of many
   deprecated modules: aifc, audioop, chunk, cgi, cgitb, crypt, imghdr,
   mailcap, msilib, nis, nntplib, ossaudiodev, pipes, sndhdr, spwd, sunau,
   telnetlib, uu, 

RE: Relatively prime integers in NumPy

2024-07-12 Thread AVI GROSS via Python-list
Dmitry,

 

Efficiency of several kinds is hotly debated and sometimes it depends a lot on 
what is done within loops.

 

Many suggest a mild speed up of some comprehensions over loops but the loops 
are not gone but somewhat hidden and perhaps some aspects are faster for having 
been written in C carefully and not interpreted.

 

Comprehensions (and there are other versions that generate dictionaries and 
tuples and sets) may also be sped up a bit for other reasons like your fairly 
expensive APPPEND that has to keep finding the end o f a growing list and is 
not done the same way in a comprehension.

 

If you do a search, you find many opinions including on using functional 
programming techniques such as map/reduce. There are also 

 

Your particular case is interesting because it just makes all combination of 
three variables. Some languages, like R, have functions that do this for you, 
like expand.grd. Python has many modules, like itertools that do things 
including combinations but perhaps not designed for your case. 

 

Here is a version of your scenario:

 

import itertools

a = range(3)

b = range(4)

c = range(5)

 

list(itertools.product(a,b,c))

 

The result comes as tuples but as you are moving the result into numpy, does it 
matter:

 

>>> list(itertools.product(a,b,c))

[(0, 0, 0), (0, 0, 1), (0, 0, 2), (0, 0, 3), (0, 0, 4), (0, 1, 0), (0, 1, 1), 
(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 0), (0, 2, 1), (0, 2, 2), (0, 2, 3), 
(0, 2, 4), (0, 3, 0), (0, 3, 1), (0, 3, 2), (0, 3, 3), (0, 3, 4), (1, 0, 0), 
(1, 0, 1), (1, 0, 2), (1, 0, 3), (1, 0, 4), (1, 1, 0), (1, 1, 1), (1, 1, 2), 
(1, 1, 3), (1, 1, 4), (1, 2, 0), (1, 2, 1), (1, 2, 2), (1, 2, 3), (1, 2, 4), 
(1, 3, 0), (1, 3, 1), (1, 3, 2), (1, 3, 3), (1, 3, 4), (2, 0, 0), (2, 0, 1), 
(2, 0, 2), (2, 0, 3), (2, 0, 4), (2, 1, 0), (2, 1, 1), (2, 1, 2), (2, 1, 3), 
(2, 1, 4), (2, 2, 0), (2, 2, 1), (2, 2, 2), (2, 2, 3), (2, 2, 4), (2, 3, 0), 
(2, 3, 1), (2, 3, 2), (2, 3, 3), (2, 3, 4)]

 

Or a atd easier to read pretty printed:

 

>>> import pprint

>>> pprint.pprint(list(itertools.product(a,b,c)))

[(0, 0, 0),

(0, 0, 1),

(0, 0, 2),

(0, 0, 3),

(0, 0, 4),

(0, 1, 0),

(0, 1, 1),

(0, 1, 2),

(0, 1, 3),

(0, 1, 4),

(0, 2, 0),

(0, 2, 1),

(0, 2, 2),

(0, 2, 3),

(0, 2, 4),

(0, 3, 0),

(0, 3, 1),

(0, 3, 2),

(0, 3, 3),

(0, 3, 4),

(1, 0, 0),

(1, 0, 1),

(1, 0, 2),

(1, 0, 3),

(1, 0, 4),

(1, 1, 0),

(1, 1, 1),

(1, 1, 2),

(1, 1, 3),

(1, 1, 4),

(1, 2, 0),

(1, 2, 1),

(1, 2, 2),

(1, 2, 3),

(1, 2, 4),

(1, 3, 0),

(1, 3, 1),

(1, 3, 2),

(1, 3, 3),

(1, 3, 4),

(2, 0, 0),

(2, 0, 1),

(2, 0, 2),

(2, 0, 3),

(2, 0, 4),

(2, 1, 0),

(2, 1, 1),

(2, 1, 2),

(2, 1, 3),

(2, 1, 4),

(2, 2, 0),

(2, 2, 1),

(2, 2, 2),

(2, 2, 3),

(2, 2, 4),

(2, 3, 0),

(2, 3, 1),

(2, 3, 2),

(2, 3, 3),

(2, 3, 4)]

 

I think that is close enough to what you want but is it faster? You can try a 
benchmarking method on alternatives.

 

 

 

 

From: Popov, Dmitry Yu  
Sent: Friday, July 12, 2024 11:10 PM
To: avi.e.gr...@gmail.com; 'Popov, Dmitry Yu via Python-list' 
; oscar.j.benja...@gmail.com
Subject: Re: Relatively prime integers in NumPy

 

Thank you very much. List comprehensions make code much more concise indeed. Do 
list comprehensions also improve the speed of calculations?

  _  

From: avi.e.gr...@gmail.com   
mailto:avi.e.gr...@gmail.com> >
Sent: Friday, July 12, 2024 6:57 PM
To: Popov, Dmitry Yu mailto:dpo...@anl.gov> >; 'Popov, Dmitry 
Yu via Python-list' mailto:python-list@python.org> >; 
oscar.j.benja...@gmail.com   
mailto:oscar.j.benja...@gmail.com> >
Subject: RE: Relatively prime integers in NumPy 

 

Dmitry, I clearly did not understand what you wanted earlier as you had not 
made clear that in your example, you already had progressed to some level where 
you had the data and were now doing a second step. So, I hesitate to say much 
until 

ZjQcmQRYFpfptBannerStart

This Message Is From an External Sender 

This message came from outside your organization. 

 

ZjQcmQRYFpfptBannerEnd

Dmitry,

 

I clearly did not understand what you wanted earlier as you had not made clear 
that in your example, you already had progressed to some level where you had 
the data and were now doing a second step. So, I hesitate to say much until 
either nobody else addressed the issue (as clearly some have) or you explain 
well enough.

 Ditr

I am guessing you have programming experience in other languages and are not as 
“pythonic” as some. The code you show may not be quite how others might do it. 
Some may write mch of your code as a single line of python using a list 
comprehension such as:

 

hkl_list = [ [h, k, l] for SOMETHING in RANGE  for SOMETHING2  in RANGE2 for 
SOMETHING3 in RANGE3] 

 

Where h, k. l come from the somethings.

 

Back to the real world.

 

 

From: Popov, Dmitry Yu mailto:dpo...@anl.gov> > 
Sent: Friday, July 12, 2024 1:13 PM
To: 

Re: Relatively prime integers in NumPy

2024-07-12 Thread Popov, Dmitry Yu via Python-list
Thank you very much. List comprehensions make code much more concise indeed. Do 
list comprehensions also improve the speed of calculations?

From: avi.e.gr...@gmail.com 
Sent: Friday, July 12, 2024 6:57 PM
To: Popov, Dmitry Yu ; 'Popov, Dmitry Yu via Python-list' 
; oscar.j.benja...@gmail.com 

Subject: RE: Relatively prime integers in NumPy

Dmitry, I clearly did not understand what you wanted earlier as you had not 
made clear that in your example, you already had progressed to some level where 
you had the data and were now doing a second step. So, I hesitate to say much 
until
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.

ZjQcmQRYFpfptBannerEnd

Dmitry,



I clearly did not understand what you wanted earlier as you had not made clear 
that in your example, you already had progressed to some level where you had 
the data and were now doing a second step. So, I hesitate to say much until 
either nobody else addressed the issue (as clearly some have) or you explain 
well enough.



I am guessing you have programming experience in other languages and are not as 
“pythonic” as some. The code you show may not be quite how others might do it. 
Some may write mch of your code as a single line of python using a list 
comprehension such as:



hkl_list = [ [h, k, l] for SOMETHING in RANGE  for SOMETHING2  in RANGE2 for 
SOMETHING3 in RANGE3]



Where h, k. l come from the somethings.



Back to the real world.





From: Popov, Dmitry Yu 
Sent: Friday, July 12, 2024 1:13 PM
To: avi.e.gr...@gmail.com; 'Popov, Dmitry Yu via Python-list' 
; oscar.j.benja...@gmail.com; Popov, Dmitry Yu 

Subject: Re: Relatively prime integers in NumPy



Thank you very much, Oscar.



Using the following code looks like a much better solution than my current 
Python code indeed.

np.gcd.reduce(np.transpose(a))

or

np.gcd.reduce(a,1)



The next question is how I can generate ndarray of h,k,l indices. This can be 
easily done from a Python list by using the following code.



import numpy as np

hkl_list=[]

for h in range(0, max_h):

  for k in range(0, max_k):

for l in range(0, max_l):

  hkl_local=[]

  hkl_local.append(h)

  hkl_local.append(k)

  hkl_local.append(l)

  hkl_list.append(hkl_local)

hkl=np.array(hkl_list, dtype=np.int64)

This code will generate a two-dimensional ndarray of h,k,l indices but is it 
possible to make a faster routine with NumPy?



Regards,

Dmitry









From: Python-list 
mailto:python-list-bounces+dpopov=anl@python.org>>
 on behalf of Popov, Dmitry Yu via Python-list 
mailto:python-list@python.org>>
Sent: Thursday, July 11, 2024 2:25 PM
To: avi.e.gr...@gmail.com 
mailto:avi.e.gr...@gmail.com>>; 'Popov, Dmitry Yu via 
Python-list' mailto:python-list@python.org>>
Subject: Re: Relatively prime integers in NumPy



Thank you for your interest. My explanation is too concise indeed, sorry. So 
far, I have used Python code with three enclosed 'for' loops for this purpose 
which is pretty time consuming. I'm trying to develop a NumPy based code to 
make this

ZjQcmQRYFpfptBannerStart

This Message Is From an External Sender

This message came from outside your organization.



ZjQcmQRYFpfptBannerEnd

Thank you for your interest. My explanation is too concise indeed, sorry. So 
far, I have used Python code with three enclosed 'for' loops for this purpose 
which is pretty time consuming. I'm trying to develop a NumPy based code to 
make this procedure faster. This routine is kind of 'heart' of the algorithm to 
index of X-ray Laue diffraction patterns. In our group we have to process huge 
amount of such patterns. They are collected at a synchrotron radiation 
facility. Faster indexation routine would help a lot.



This is the code I'm currently using. Any prompts how to implement it in NumPy 
would be highly appreciated.



for h in range(0, max_h):

  for k in range(0, max_k):

for l in range(0, max_l):

  chvec=1

  maxmult=2

  if h > 1: 

maxmult=h

  if k > 1:

maxmult=k

  if l > 1:

maxmult=l

  if h > 1:

if maxmult > h:

  maxmult=h

  if k > 1:

if maxmult > k:

  maxmult=k

  if l > 1:

if maxmult > l:

  maxmult=l

  maxmult=maxmult+1

  for innen in range(2, maxmult):

if h in range(0, (max_h+1), innen):

  if k in range(0, (max_k+1), innen):

  

RE: Relatively prime integers in NumPy

2024-07-12 Thread AVI GROSS via Python-list
Dmitry,

 

I clearly did not understand what you wanted earlier as you had not made clear 
that in your example, you already had progressed to some level where you had 
the data and were now doing a second step. So, I hesitate to say much until 
either nobody else addressed the issue (as clearly some have) or you explain 
well enough.

 

I am guessing you have programming experience in other languages and are not as 
“pythonic” as some. The code you show may not be quite how others might do it. 
Some may write mch of your code as a single line of python using a list 
comprehension such as:

 

hkl_list = [ [h, k, l] for SOMETHING in RANGE  for SOMETHING2  in RANGE2 for 
SOMETHING3 in RANGE3] 

 

Where h, k. l come from the somethings.

 

Back to the real world.

 

 

From: Popov, Dmitry Yu  
Sent: Friday, July 12, 2024 1:13 PM
To: avi.e.gr...@gmail.com; 'Popov, Dmitry Yu via Python-list' 
; oscar.j.benja...@gmail.com; Popov, Dmitry Yu 

Subject: Re: Relatively prime integers in NumPy

 

Thank you very much, Oscar. 

 

Using the following code looks like a much better solution than my current 
Python code indeed.

np.gcd.reduce(np.transpose(a)) 
or 
np.gcd.reduce(a,1)  
 
The next question is how I can generate ndarray of h,k,l indices. This can be 
easily done from a Python list by using the following code.
 
import numpy as np
hkl_list=[]
for h in range(0, max_h):
  for k in range(0, max_k):
for l in range(0, max_l):
  hkl_local=[]
  hkl_local.append(h)
  hkl_local.append(k)
  hkl_local.append(l)
  hkl_list.append(hkl_local)
hkl=np.array(hkl_list, dtype=np.int64)
This code will generate a two-dimensional ndarray of h,k,l indices but is it 
possible to make a faster routine with NumPy? 
 
Regards,
Dmitry
 
 
 
  _  


From: Python-list mailto:python-list-bounces+dpopov=anl@python.org> > on behalf of Popov, 
Dmitry Yu via Python-list mailto:python-list@python.org> >
Sent: Thursday, July 11, 2024 2:25 PM
To: avi.e.gr...@gmail.com   
mailto:avi.e.gr...@gmail.com> >; 'Popov, Dmitry Yu via 
Python-list' mailto:python-list@python.org> >
Subject: Re: Relatively prime integers in NumPy 

 

Thank you for your interest. My explanation is too concise indeed, sorry. So 
far, I have used Python code with three enclosed 'for' loops for this purpose 
which is pretty time consuming. I'm trying to develop a NumPy based code to 
make this 

ZjQcmQRYFpfptBannerStart

This Message Is From an External Sender 

This message came from outside your organization. 

 

ZjQcmQRYFpfptBannerEnd

Thank you for your interest. My explanation is too concise indeed, sorry. So 
far, I have used Python code with three enclosed 'for' loops for this purpose 
which is pretty time consuming. I'm trying to develop a NumPy based code to 
make this procedure faster. This routine is kind of 'heart' of the algorithm to 
index of X-ray Laue diffraction patterns. In our group we have to process huge 
amount of such patterns. They are collected at a synchrotron radiation 
facility. Faster indexation routine would help a lot.
 
This is the code I'm currently using. Any prompts how to implement it in NumPy 
would be highly appreciated.
 
for h in range(0, max_h):
  for k in range(0, max_k):
for l in range(0, max_l):
  chvec=1
  maxmult=2
  if h > 1: 
maxmult=h
  if k > 1:
maxmult=k
  if l > 1:
maxmult=l
  if h > 1:
if maxmult > h:
  maxmult=h
  if k > 1:
if maxmult > k:
  maxmult=k
  if l > 1:
if maxmult > l:
  maxmult=l
  maxmult=maxmult+1
  for innen in range(2, maxmult):
if h in range(0, (max_h+1), innen):
  if k in range(0, (max_k+1), innen):
if l in range(0, (max_l+1), innen):
  chvec=0
  if chvec==1:
# Only relatively prime integers h,k,l pass to this 
block of the code
 
 

From: avi.e.gr...@gmail.com   
mailto:avi.e.gr...@gmail.com> >
Sent: Thursday, July 11, 2024 1:22 PM
To: Popov, Dmitry Yu mailto:dpo...@anl.gov> >; 'Popov, Dmitry 
Yu via Python-list' mailto:python-list@python.org> >
Subject: RE: Relatively prime integers in NumPy
 
Дмитрий, You may think you explained what you wanted but I do not see what 
result you expect from your examples. Your request is a bit too esoteric to be 
a great candidate for being built into a module like numpy for general 

Re: Relatively prime integers in NumPy

2024-07-12 Thread Popov, Dmitry Yu via Python-list
Thank you very much, Oscar.

Using the following code looks like a much better solution than my current 
Python code indeed.

np.gcd.reduce(np.transpose(a))
or
np.gcd.reduce(a,1)

The next question is how I can generate ndarray of h,k,l indices. This can be 
easily done from a Python list by using the following code.

import numpy as np
hkl_list=[]
for h in range(0, max_h):
  for k in range(0, max_k):
for l in range(0, max_l):
  hkl_local=[]
  hkl_local.append(h)
  hkl_local.append(k)
  hkl_local.append(l)
  hkl_list.append(hkl_local)
hkl=np.array(hkl_list, dtype=np.int64)

This code will generate a two-dimensional ndarray of h,k,l indices but is it 
possible to make a faster routine with NumPy?

Regards,
Dmitry





From: Python-list  on behalf of 
Popov, Dmitry Yu via Python-list 
Sent: Thursday, July 11, 2024 2:25 PM
To: avi.e.gr...@gmail.com ; 'Popov, Dmitry Yu via 
Python-list' 
Subject: Re: Relatively prime integers in NumPy

Thank you for your interest. My explanation is too concise indeed, sorry. So 
far, I have used Python code with three enclosed 'for' loops for this purpose 
which is pretty time consuming. I'm trying to develop a NumPy based code to 
make this
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.

ZjQcmQRYFpfptBannerEnd

Thank you for your interest. My explanation is too concise indeed, sorry. So 
far, I have used Python code with three enclosed 'for' loops for this purpose 
which is pretty time consuming. I'm trying to develop a NumPy based code to 
make this procedure faster. This routine is kind of 'heart' of the algorithm to 
index of X-ray Laue diffraction patterns. In our group we have to process huge 
amount of such patterns. They are collected at a synchrotron radiation 
facility. Faster indexation routine would help a lot.

This is the code I'm currently using. Any prompts how to implement it in NumPy 
would be highly appreciated.

for h in range(0, max_h):
  for k in range(0, max_k):
for l in range(0, max_l):
  chvec=1
  maxmult=2
  if h > 1: 
maxmult=h
  if k > 1:
maxmult=k
  if l > 1:
maxmult=l
  if h > 1:
if maxmult > h:
  maxmult=h
  if k > 1:
if maxmult > k:
  maxmult=k
  if l > 1:
if maxmult > l:
  maxmult=l
  maxmult=maxmult+1
  for innen in range(2, maxmult):
if h in range(0, (max_h+1), innen):
  if k in range(0, (max_k+1), innen):
if l in range(0, (max_l+1), innen):
  chvec=0
  if chvec==1:
# Only relatively prime integers h,k,l pass to this 
block of the code



From: avi.e.gr...@gmail.com 
Sent: Thursday, July 11, 2024 1:22 PM
To: Popov, Dmitry Yu ; 'Popov, Dmitry Yu via Python-list' 

Subject: RE: Relatively prime integers in NumPy

Дмитрий, You may think you explained what you wanted but I do not see what 
result you expect from your examples. Your request is a bit too esoteric to be 
a great candidate for being built into a module like numpy for general purpose 
se but
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.

ZjQcmQRYFpfptBannerEnd

Дмитрий,

You may think you explained what you wanted but I do not see what result you
expect from your examples.

Your request is a bit too esoteric to be a great candidate for being built
into a module like numpy for general purpose se but I can imagine it could
be available in modules build on top of numpy.

Is there a reason you cannot solve this mostly outside numpy?

It looks like you could use numpy to select the numbers you want to compare,
then call one of many methods you can easily search for to see  how to use
python to make some list or other data structure for divisors of each number
involved and then use standard methods to compare the lists and exact common
divisors. If needed, you could then put the results back into your original
data structure using numpy albeit the number of matches can vary.

Maybe a better explanation is needed as I cannot see what your latter words
about -1 and 1 are about. Perhaps someone else knows.




-Original Message-
From: Python-list  On
Behalf Of Popov, Dmitry Yu via Python-list
Sent: Monday, July 8, 2024 3:10 PM
To: Popov, Dmitry Yu via Python-list 
Subject: Relatively prime integers in NumPy

Dear 

Re: Password Hash Validation (Posting On Python-List Prohibited)

2024-07-12 Thread Lawrence D'Oliveiro via Python-list
On Fri, 21 Jun 2024 06:32:58 - (UTC), I wrote:

> On Fri, 21 Jun 2024 03:40:55 - (UTC), I wrote:
> 
>> I think I will create my own wrapper using ctypes.
> 
> Done .

The repo now includes an example script that exercises the various 
functions of the module.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Relatively prime integers in NumPy

2024-07-12 Thread Popov, Dmitry Yu via Python-list
Thank you for your interest. My explanation is too concise indeed, sorry. So 
far, I have used Python code with three enclosed 'for' loops for this purpose 
which is pretty time consuming. I'm trying to develop a NumPy based code to 
make this procedure faster. This routine is kind of 'heart' of the algorithm to 
index of X-ray Laue diffraction patterns. In our group we have to process huge 
amount of such patterns. They are collected at a synchrotron radiation 
facility. Faster indexation routine would help a lot.

This is the code I'm currently using. Any prompts how to implement it in NumPy 
would be highly appreciated.

for h in range(0, max_h):
  for k in range(0, max_k):
for l in range(0, max_l):
  chvec=1
  maxmult=2
  if h > 1: 
maxmult=h
  if k > 1:
maxmult=k
  if l > 1:
maxmult=l
  if h > 1:
if maxmult > h:
  maxmult=h
  if k > 1:
if maxmult > k:
  maxmult=k
  if l > 1:
if maxmult > l:
  maxmult=l
  maxmult=maxmult+1
  for innen in range(2, maxmult):
if h in range(0, (max_h+1), innen):
  if k in range(0, (max_k+1), innen):
if l in range(0, (max_l+1), innen):
  chvec=0
  if chvec==1:
# Only relatively prime integers h,k,l pass to this 
block of the code



From: avi.e.gr...@gmail.com 
Sent: Thursday, July 11, 2024 1:22 PM
To: Popov, Dmitry Yu ; 'Popov, Dmitry Yu via Python-list' 

Subject: RE: Relatively prime integers in NumPy

Дмитрий, You may think you explained what you wanted but I do not see what 
result you expect from your examples. Your request is a bit too esoteric to be 
a great candidate for being built into a module like numpy for general purpose 
se but
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.

ZjQcmQRYFpfptBannerEnd

Дмитрий,

You may think you explained what you wanted but I do not see what result you
expect from your examples.

Your request is a bit too esoteric to be a great candidate for being built
into a module like numpy for general purpose se but I can imagine it could
be available in modules build on top of numpy.

Is there a reason you cannot solve this mostly outside numpy?

It looks like you could use numpy to select the numbers you want to compare,
then call one of many methods you can easily search for to see  how to use
python to make some list or other data structure for divisors of each number
involved and then use standard methods to compare the lists and exact common
divisors. If needed, you could then put the results back into your original
data structure using numpy albeit the number of matches can vary.

Maybe a better explanation is needed as I cannot see what your latter words
about -1 and 1 are about. Perhaps someone else knows.




-Original Message-
From: Python-list  On
Behalf Of Popov, Dmitry Yu via Python-list
Sent: Monday, July 8, 2024 3:10 PM
To: Popov, Dmitry Yu via Python-list 
Subject: Relatively prime integers in NumPy

Dear Sirs.

Does NumPy provide a simple mechanism to identify relatively prime integers,
i.e. integers which don't have a common factor other than +1 or -1? For
example, in case of this array:
[[1,5,8],
  [2,4,8],
  [3,3,9]]
I can imagine a function which would return array of common factors along
axis 0: [1,2,3]. Those triples of numbers along axis 1 with the factor of1
or -1 would be relatively prime integers.

Regards,
Dmitry Popov

Argonne, IL
USA

--
https://urldefense.us/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!G_uCfscf7eWS!ZGK1ZXYgmC6cpNa1xTXVTNklhunjYiinwaDe_xE3sJyVs4ZcVgUB_v2FKvDzDspx7IzFCZI7JpFsiV5iH58P$


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


Re: Best use of "open" context manager

2024-07-12 Thread Albert-Jan Roskam via Python-list
   Or like below, although pylint complains about this: "consider using
   with". Less indentation this way.
   f = None
   try:
   f = open(FILENAME)
   records = f.readlines()
   except Exception:
   sys.exit(1)
   finally:
   if f is not None:
   f.close()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Relatively prime integers in NumPy

2024-07-12 Thread Peter J. Holzer via Python-list
On 2024-07-08 19:09:45 +, Popov, Dmitry Yu via Python-list wrote:
> Does NumPy provide a simple mechanism to identify relatively prime
> integers, i.e. integers which don't have a common factor other than +1
> or -1?

Typing "numpy gcd" into my favourite search engine brings me to 
https://numpy.org/doc/stable/reference/generated/numpy.gcd.html

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Relatively prime integers in NumPy

2024-07-11 Thread AVI GROSS via Python-list
OK. That explains a bit more.

 

If I understand what you are looking for is a fast implementation and quite 
often in Pyhon it means using code written in another language such as C that 
is integrated carefully in a moule or two. Another tack is to replace many 
explicit loops with often much faster vectorized operations. Numpy provides 
advantages like the above if you use it as intended.

 

Of course there are other techniques in how code is refactored or the order of 
operations, or doing things in parallel.

 

Just as an example, your inner loop ear the top is operating one at a time or 
numbers between 0 and max_l and hen creates variables initialized and then 
possibly changed in chvec and maxmult. It uses various conditions to change 
those variables then goes on to do more things included in a fourth nested loop.

 

What would happen if, instead, you used two objects with the same names that 
were each a numpy array, or perhaps combined into a dataframe type object?

 

Using numpy (and perhaps pandas) you could have code that initialized one such 
array to hold the initial 1 or 2 as needed in an object whose length was 
max_l+1 and then the next operations, using numpy notation would be along the 
lines of replace the corresponding value depending on external variables you 
call h or k and so on. 

 

There would be several invisible loops, perhaps chained in some way, but 
probably running way faster than the explicit loop.

 

I am not going to write any specific code, but suggest you read some 
documentation on how to use numpy for some of the operations you want when 
operating on larger clusters of info. You can gain some speed even by changing 
a few parts. To refactor the entire thing would take more thought and if you 
come up with the idea  of operating on a multidimensional array, might take 
some care. 

 

But consider what would happen if you looked at your loops which are currently 
of a fixed size and created  a 3-D matrix with dimensions of max_h+1, max_k+1, 
and max_l+1 and simply initialized it with all possible initial values and then 
ran an algorithm to manipulate it, often asking numpy for various slices or 
whatever works for you as in axes.  This architecture may not work for ou but 
is an example of the kind of thinking it an take to make a problem use 
algorithms more efficiently.

 

I note the code did not actually help me understand what mathematical operation 
you want to perform. I assumed I might see some operations like division and t 
may be other parts of your code that implement what you want.

 

But if this is a common enough need, I suspect you may want to see if something 
similar enough is out there. Your code may be more complex and more like the 
sieve of Eratosthenes that attempts to test every possibility.

 

One algorithm I have seen simply takes the numbers you are evaluating and in a 
loop of the first N primes (or an open-ended generator) simply does an integer 
division by 2, as many times as it returns an integral result, then as many 
divisions by 3 then 5 and 7 and so on.  It aborts when it has been chopped down 
to size, or the prime being used is large enough (square root or so) ad at the 
end, you should have some sequence of divisors, or just  and the number if it 
is prime. Some such algorithm can be fairly fast and perhaps can even be done 
vectorized. 

 

One last comment is about memoization. If your data is of a nature where a 
relatively few numbers come up often, then you an use something, like perhaps a 
dictionary, to store the results of a computation like getting a list of prime 
factors for a specific number, or just recording whether it is prime or 
composite. Later calls to do calculations would always check if the result has 
already been saved and skip recalculating it.

 

Good Luck

 

 

From: Popov, Dmitry Yu  
Sent: Thursday, July 11, 2024 3:26 PM
To: avi.e.gr...@gmail.com; 'Popov, Dmitry Yu via Python-list' 

Subject: Re: Relatively prime integers in NumPy

 

Thank you for your interest. My explanation is too concise indeed, sorry. So 
far, I have used Python code with three enclosed 'for' loops for this purpose 
which is pretty time consuming. I'm trying to develop a NumPy based code to 
make this procedure faster. This routine is kind of 'heart' of the algorithm to 
index of X-ray Laue diffraction patterns. In our group we have to process huge 
amount of such patterns. They are collected at a synchrotron radiation 
facility. Faster indexation routine would help a lot. 

 

This is the code I'm currently using. Any prompts how to implement it in NumPy 
would be highly appreciated. 

 

for h in range(0, max_h):

  for k in range(0, max_k):

for l in range(0, max_l):

  chvec=1

  maxmult=2

  if h > 1: 

maxmult=h

  if k > 1:

maxmult=k

  if l > 

Re: Relatively prime integers in NumPy

2024-07-11 Thread Oscar Benjamin via Python-list
(posting on-list this time)

On Thu, 11 Jul 2024 at 15:18, Popov, Dmitry Yu via Python-list
 wrote:
>
> Dear Sirs.
>
> Does NumPy provide a simple mechanism to identify relatively prime integers, 
> i.e. integers which don't have a common factor other than +1 or -1? For 
> example, in case of this array:
> [[1,5,8],
>   [2,4,8],
>   [3,3,9]]
> I can imagine a function which would return array of common factors along 
> axis 0: [1,2,3]. Those triples of numbers along axis 1 with the factor of1 or 
> -1 would be relatively prime integers.

It sounds like you want the gcd (greatest common divisor) of each row.
The math module can do this:

In [1]: a = [[1,5,8],
   ...:   [2,4,8],
   ...:   [3,3,9]]

In [2]: import math

In [3]: [math.gcd(*row) for row in a]
Out[3]: [1, 2, 3]

NumPy can also do it apparently:

In [10]: np.gcd.reduce(np.transpose(a))
Out[10]: array([1, 2, 3])

https://en.wikipedia.org/wiki/Greatest_common_divisor

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


RE: Relatively prime integers in NumPy

2024-07-11 Thread AVI GROSS via Python-list
Дмитрий,

You may think you explained what you wanted but I do not see what result you
expect from your examples.

Your request is a bit too esoteric to be a great candidate for being built
into a module like numpy for general purpose se but I can imagine it could
be available in modules build on top of numpy.

Is there a reason you cannot solve this mostly outside numpy?

It looks like you could use numpy to select the numbers you want to compare,
then call one of many methods you can easily search for to see  how to use
python to make some list or other data structure for divisors of each number
involved and then use standard methods to compare the lists and exact common
divisors. If needed, you could then put the results back into your original
data structure using numpy albeit the number of matches can vary.

Maybe a better explanation is needed as I cannot see what your latter words
about -1 and 1 are about. Perhaps someone else knows.




-Original Message-
From: Python-list  On
Behalf Of Popov, Dmitry Yu via Python-list
Sent: Monday, July 8, 2024 3:10 PM
To: Popov, Dmitry Yu via Python-list 
Subject: Relatively prime integers in NumPy

Dear Sirs.

Does NumPy provide a simple mechanism to identify relatively prime integers,
i.e. integers which don't have a common factor other than +1 or -1? For
example, in case of this array:
[[1,5,8],
  [2,4,8],
  [3,3,9]]
I can imagine a function which would return array of common factors along
axis 0: [1,2,3]. Those triples of numbers along axis 1 with the factor of1
or -1 would be relatively prime integers.

Regards,
Dmitry Popov

Argonne, IL
USA

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

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


Re: python repl vi mode line editing not working.

2024-07-11 Thread Tobiah via Python-list

I see the literal 'escape' character + 'k', when it should
let me edit previous commands.

I did have to compile my own python because I'm using 2.7 on
this machine.



I figured it out.  I needed to apt install libreadline-dev.
--
https://mail.python.org/mailman/listinfo/python-list


Re: python repl vi mode line editing not working.

2024-07-11 Thread Tobiah via Python-list

   For this to work, the Python implementation should use the same
   readline library as your shell, I guess.


It works in python3, so I guess my problem is that I'm
compiling python (I think kubuntu dropped python2), but
I don't see any relevant options  in the configure help.





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


Problem using mysql library

2024-07-11 Thread Tobiah via Python-list

sinewave:toby ~(1)> python
Python 2.7.18 (default, Jul  8 2024, 12:49:12)
[GCC 13.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import MySQLdb

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.7/site-packages/MySQLdb/__init__.py", line 23, in 

(version_info, _mysql.version_info))
ImportError: this is MySQLdb version (1, 2, 5, 'final', 1), but _mysql is 
version (1, 4, 6, 'final', 0)


I Googled this a lot, and saw many people with the same problem,
but couldn't find an answer that helped.


Thanks!


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


python repl vi mode line editing not working.

2024-07-11 Thread Tobiah via Python-list

Kubuntu 24.04.


sinewave:toby ~(1)> cat .inputrc
set editing-mode vi
set keymap vi
sinewave:toby ~(1)> cat .editrc
bind -v
bind \\t rl_complete
sinewave:toby ~(1)> python
Python 2.7.18 (default, Jul  8 2024, 12:49:12)
[GCC 13.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
1  

1

2

2

^[k



I see the literal 'escape' character + 'k', when it should
let me edit previous commands.

I did have to compile my own python because I'm using 2.7 on
this machine.

Thanks for any help.


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


Relatively prime integers in NumPy

2024-07-11 Thread Popov, Dmitry Yu via Python-list
Dear Sirs.

Does NumPy provide a simple mechanism to identify relatively prime integers, 
i.e. integers which don't have a common factor other than +1 or -1? For 
example, in case of this array:
[[1,5,8],
  [2,4,8],
  [3,3,9]]
I can imagine a function which would return array of common factors along axis 
0: [1,2,3]. Those triples of numbers along axis 1 with the factor of1 or -1 
would be relatively prime integers.

Regards,
Dmitry Popov

Argonne, IL
USA

-- 
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: A new feature request - parser add_mutually_exclusive_group - add a default value

2024-07-09 Thread אורי via Python-list
Thank you.

Uri.
אורי
u...@speedy.net


On Tue, Jul 9, 2024 at 6:40 PM Barry Scott  wrote:

>
>
> On 9 Jul 2024, at 06:13, ⁨אורי via Python-list⁩ <⁨python-list@python.org⁩>
> wrote:
>
>  I tried to subscribe to Python-ideas
>
>
> These days ideas are discussed on https://discuss.python.org/
> It is rare to see an idea on the mailing list.
>
> Barry
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A new feature request - parser add_mutually_exclusive_group - add a default value

2024-07-09 Thread Barry Scott via Python-list


> On 9 Jul 2024, at 06:13, ⁨אורי via Python-list⁩ <⁨python-list@python.org⁩> 
> wrote:
> 
>  I tried to subscribe to Python-ideas

These days ideas are discussed on https://discuss.python.org/
It is rare to see an idea on the mailing list.

Barry


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


A new feature request - parser add_mutually_exclusive_group - add a default value

2024-07-08 Thread אורי via Python-list
Hi,

Please look at this Stack Overflow post:
https://stackoverflow.com/questions/78722378/parser-add-mutually-exclusive-group-how-can-i-set-a-default-value

1. Is there a way to add a default to parser add_mutually_exclusive_group
groups - a value that will be set by default? In this case I
want test-default-languages=True to be set as a default.

2. I tried to subscribe to Python-ideas python-id...@python.org, but I
can't login to
https://mail.python.org/mailman3/lists/python-ideas.python.org/. Although I
did login to https://mail.python.org/mailman/options/python-list . Do I
have to create a new account?

Thanks,
Uri.
אורי
u...@speedy.net
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best use of "open" context manager

2024-07-08 Thread Rob Cliffe via Python-list



On 06/07/2024 12:57, Oscar Benjamin via Python-list wrote:

On Sat, 6 Jul 2024 at 11:55, Rob Cliffe via Python-list
 wrote:

Consider this scenario (which I ran into in real life):
  I want to open a text file and do a lot of processing on the lines
of that file.
  If the file does not exist I want to take appropriate action, e.g.
print an error message and abort the program.
I might write it like this:

try:
  with open(FileName) as f:
  for ln in f:
  print("I do a lot of processing here")
  # Many lines of code here .
except FileNotFoundError:
  print(f"File {FileName} not found")
  sys.exit()

but this violates the principle that a "try" suite should be kept small,
so that only targeted exceptions are trapped,
not to mention that having "try" and "except" far apart decreases
readability.

This is catching a targeted exception (FileNotFoundError) so I think
it is fine. If the intention is just to call sys.exit() on error then
I wouldn't worry too much about having too much code in the try. Just
make sure that you do this in any other place where you open a file as
well.

One possible improvement is that you could catch the exception and use
its filename attribute:

except FileNotFoundError as e
  print(f"File {e.filename} not found")

That way if you did catch the wrong FileNotFoundError then at least
you print the correct filename.
Good point, Oscar - thank you.  (Even if you did omit the colon on the 
"except" line.  I've often thought we should have "Python without 
colons" as this is a mistake I frequently make.)


Alternatively:

except FileNotFoundError as e
  if e.filename != FileName:
   raise  # re-raise if not the intended exception
  print(f"File {e.filename} not found")

Indeed, that covers all basis.

For readability I would just move the many lines of code into a
separate function.
That may not always be convenient (e.g. if the many-lines-of-code needs 
to access a lot of local variables) but fair enough.

Thanks for your answer.
Rob Cliffe


The reason to avoid having too much code in the try mainly applies to
situations where you are going to do something other than call
sys.exit() and the exception is overly generic like ValueError or
TypeError. If the exception can easily be raised by a bug or something
other than the intended cause then it is bad to catch exceptions
around a larger block of code.

If it is expected that the caller of a function might have good reason
to catch the exception and handle it somehow then it is better to make
a dedicated exception class and raise that instead. When there is only
one place in the code that raises a particular exception type and only
one place that catches it then it is usually going to be clear that
you are catching the expected exception.

--
Oscar


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


Re: python for irc client

2024-07-08 Thread orzodk via Python-list
Daniel via Python-list  writes:

> One thing missing is a good textmode irc client that will connect to
> quassel core.
>
> I've seen efforts to make a plugin for weechat but, to date, I don't see much
> progress on that end.
>
> In your wisdom, would python be a good environment to accomplish this? I'd
> likely use extended ascii and colors. The point would be to minimize the
> memory footprint of the application.

One feature of weechat you may be interested in is it's relay mode:

https://weechat.org/files/doc/weechat/stable/weechat_user.en.html#relay

If you flipped this architecture around you should be able to run
weechat as your bouncer then connect quassel or any other client to
weechat with it's IRC relay mode. Weechat also has a list of remote
interfaces that can use this

https://weechat.org/about/interfaces/

OTOH if you prefer the setup you've got I've had 0 issues with the
Python plugins I've written for weechat. A Quassel/weechat proxy plugin
should be pretty straight forward and if you prefer a standalone bridge,
as others have suggested Python is great for that too!
-- 
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


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

2024-07-08 Thread Left Right via Python-list
If resource usage isn't an issue, then the _easy_ thing to do, that
would also be easily correct is to have a server doing all the
h/w-related reading and clients talking to that server. Use for the
server the technology you feel most confident with. Eg. you may use
Python's http package. I believe that the server from this package
runs in a single thread, and thus processes all requests
synchronously. So, you'll get synchronization for free.

Then, the rest of the scripts that need to talk to h/w will instead be
talking to this server.

Again, this isn't an _efficient_ solution... but, sometimes you don't
need one. And this one is easy to make, easy to debug, easy to expand.
But, if instead you were looking for a more efficient solution, then,
the general idea that allows the http server to work in this case
would still apply: have a single synchronization program that takes
requests asynchronously, and orders them. So, a basic TCP server would
also work as well as a UNIX socket. Your idea with holding a lock on a
file would also work (in fact, plenty of Linux utilities work that
way, eg. apt-get or yum).



If you don't want to change the existing script, then instead of
running them directly, you could run them through batch:
https://man7.org/linux/man-pages/man1/batch.1p.html this is a very
simply queuing program that's available for Linux. It will take care
of synchronization by putting the scripts you want to run in a queue
and executing them one at a time.

On Sun, Jul 7, 2024 at 11:12 PM Chris Green via Python-list
 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.
>
> 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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyGILState_Ensure() deadlocks, why?

2024-07-08 Thread Barry Scott via Python-list



> On 7 Jul 2024, at 23:21, Barry via Python-list  wrote:
> 
> 
> 
>> On 7 Jul 2024, at 22:09, Tomas Ukkonen via Python-list 
>>  wrote:
>> 
>>Py_Initialize();
> 
> You also need to tell python to init threading.

I'm in front of my dev machine now and checking up on threading.

There is no longer any extra init for threads required.

> I think you are missing more python setup code before you can use threads.
> Also i think you need to tell python that your thread wants to call into 
> python.
> But I an not near my dev system to research this for you.

You are right to use PyGILState_Ensure()

But as MRAB says the main thread is holding the GIL.

> 
> I have code to use python from C++ in my pysvn project.
> See the code starting a line 354 in 
> https://sourceforge.net/p/pysvn/code/HEAD/tree/trunk/pysvn/Extension/Source/pysvn.cpp
> That saves the thread state and restores it.

You still might find the classes I wrong to manage GIL acquire and release 
interesting.
I have the C++ type system enforcing the rules of acquire and release.
As well as RAII ensuring never to leave a block with the GIL in the wrong state.

Barry

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


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

2024-07-08 Thread Barry Scott via Python-list



> On 7 Jul 2024, at 23:47, MRAB via Python-list  wrote:
> 
> For clarity I'd recommend os.replace instead. This is because on Windows 
> os.rename it would complain if the target file already exists, but os.replace 
> has the same behaviour on both Linux and Windows.

Agreed.

In this case the OP is on an RPi.

Barry

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


Re: Best use of "open" context manager

2024-07-07 Thread Cameron Simpson via Python-list

On 07Jul2024 22:22, Rob Cliffe  wrote:
it's legal, but doesn't work (trying to access the file after "with f" 
raises the same

    ValueError: I/O operation on closed file.


Just to this: of course. The with closes the file. But my version runs 
the with after the try/except.

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


Re: Best use of "open" context manager

2024-07-07 Thread Cameron Simpson via Python-list

On 07Jul2024 22:22, Rob Cliffe  wrote:
Remember, the `open()` call returns a file object _which can be used 
as a context manager_. It is separate from the `with` itself.

Did you test this?
    f = open(FileName) as f:
is not legal syntax.


No. You're right, remove the "as f:".

it's legal, but doesn't work (trying to access the file after "with f" 
raises the same

    ValueError: I/O operation on closed file.


This astounds me. Code snippet to demo this?

Here's a test script which I've just run now:

FileName = 'foo.txt'
try:
  f = open(FileName)
except FileNotFoundError:
  print(f"File {FileName} not found")
  sys.exit()
with f:
  for line in f:
print("line:", line.rstrip())

Here's the foo.txt file:

here are
some lines of text

Here's the run:

% python3 p.py
line: here are
line: some lines of text
--
https://mail.python.org/mailman/listinfo/python-list


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

2024-07-07 Thread MRAB via Python-list

On 2024-07-07 23:27, Barry via Python-list wrote:




On 7 Jul 2024, at 22:13, Chris Green via Python-list  
wrote:

a simple file lock can then
be used to prevent simultaneous access (well, simultaneous access when
the writing process is writing).


There is a simple pattern to make this robust.

Write new values to a tmp file.
Close the tmp file.
Then use os.rename(tmpfile, productionfile).

This is guaranteed that any process that reads the file will only see all the 
old file contents or all the new file contents,  never a mix of both.

For clarity I'd recommend os.replace instead. This is because on Windows 
os.rename it would complain if the target file already exists, but 
os.replace has the same behaviour on both Linux and Windows.

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


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

2024-07-07 Thread Barry via Python-list



> On 7 Jul 2024, at 22:13, Chris Green via Python-list  
> wrote:
> 
> a simple file lock can then
> be used to prevent simultaneous access (well, simultaneous access when
> the writing process is writing).

There is a simple pattern to make this robust.

Write new values to a tmp file.
Close the tmp file.
Then use os.rename(tmpfile, productionfile).

This is guaranteed that any process that reads the file will only see all the 
old file contents or all the new file contents,  never a mix of both.

Barry


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


Re: Best use of "open" context manager

2024-07-07 Thread Rob Cliffe via Python-list



On 07/07/2024 02:08, Cameron Simpson wrote:

On 06Jul2024 11:49, Rob Cliffe  wrote:

try:
    f = open(FileName) as f:
    FileLines = f.readlines()
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()
# I forgot to put "f.close()" here -:)
for ln in File Lines:
        print("I do a lot of processing here")
        # Many lines of code here .


What about this:

    try:
        f = open(FileName) as f:
    except FileNotFoundError:
        print(f"File {FileName} not found")
        sys.exit()
    with f:
    ... process the lines here ...

Remember, the `open()` call returns a file object _which can be used 
as a context manager_. It is separate from the `with` itself.

Did you test this?
    f = open(FileName) as f:
is not legal syntax.
If you omit the "as f:"
it's legal, but doesn't work (trying to access the file after "with f" 
raises the same

    ValueError: I/O operation on closed file.
I'm using Python 3.11.5.

Best wishes
Rob Cliffe
--
https://mail.python.org/mailman/listinfo/python-list


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

2024-07-07 Thread Gordinator via Python-list

On 06/07/2024 12:32, Stefan Ram wrote:

   But why overengineer? If you feel comfortable with the file
   solution, go for it! The only drawback might be that it's a
   bit slower than other approaches.


I absolutely agree. Overengineering is generally a bad idea because 
you're using a complex solution to solve a simple problem, which leads 
to unexpected breakage.


The file solution is perfectly fine, and file locks are used by really 
important software (i.e package managers and such) because its 
simplicity makes it almost never fail.


So yeah, go for it!

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


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

2024-07-07 Thread Piergiorgio Sartor via Python-list

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.

bye,

pg


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?



--

piergiorgio

--
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: Best use of "open" context manager

2024-07-06 Thread Cameron Simpson via Python-list

On 06Jul2024 11:49, Rob Cliffe  wrote:

try:
    f = open(FileName) as f:
    FileLines = f.readlines()
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()
# I forgot to put "f.close()" here -:)
for ln in File Lines:
        print("I do a lot of processing here")
        # Many lines of code here .


What about this:

try:
    f = open(FileName) as f:
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()
with f:
... process the lines here ...

Remember, the `open()` call returns a file object _which can be used as 
a context manager_. It is separate from the `with` itself.

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


Re: Best use of "open" context manager

2024-07-06 Thread dn via Python-list

On 6/07/24 22:49, Rob Cliffe via Python-list wrote:

Consider this scenario (which I ran into in real life):
     I want to open a text file and do a lot of processing on the lines 
of that file.
     If the file does not exist I want to take appropriate action, e.g. 
print an error message and abort the program.

I might write it like this:

try:
     with open(FileName) as f:
         for ln in f:
             print("I do a lot of processing here")
             # Many lines of code here .
except FileNotFoundError:
     print(f"File {FileName} not found")
     sys.exit()

but this violates the principle that a "try" suite should be kept small, 
so that only targeted exceptions are trapped,


Yes!


not to mention that having "try" and "except" far apart decreases 
readability.


Uh-oh!

- and there's a bit of a hang-over for old-timers who had to take care 
of file-locking within the application - we try to minimise 'time' 
between opening a file and closing it (etc)!


As it seems the file is opened to read. Less relevant in this case, but 
habits and styles of coding matter...




Or I might write it like this:

try:
     f = open(FileName) as f:
     FileLines = f.readlines()
except FileNotFoundError:
     print(f"File {FileName} not found")
     sys.exit()
# I forgot to put "f.close()" here -:)
for ln in File Lines:
         print("I do a lot of processing here")
         # Many lines of code here .

but this loses the benefits of using "open" as a context manager,
and would also be unacceptable if the file was too large to read into 
memory.


So, now there are two concerns:
1 FileNotFoundError, and
2 gradual processing to avoid memory-full

- added to remembering to close the file.



Really I would like to write something like

try:
     with open(FileName) as f:
except FileNotFoundError:
     print(f"File {FileName} not found")
     sys.exit()
else: # or "finally:"
         for ln in f:
             print("I do a lot of processing here")
             # Many lines of code here .

but this of course does not work because by the time we get to "for ln 
in f:" the file has been closed so we get

ValueError: I/O operation on closed file

I could modify the last attempt to open the file twice, which would 
work, but seems like a kludge (subject to race condition, inefficient).


Is there a better / more Pythonic solution?


Idea 1: invert the exception handling and the context-manager by writing 
a custom context-manager class which handles FileNotFoundError 
internally. Thus, calling-code becomes:


with...
for...
processing

Idea 2: incorporate idea of encapsulating "processing" into a 
(well-named) function to shorten the number of lines-of-code inside the 
with-suite.


Idea 3: consider using a generator to 'produce' lines of data 
one-at-a-time. Remember that whilst context-managers and generators are 
distinct concepts within Python, they are quite similar in many ways. 
So, a custom generator could work like a context-manager or 'wrap' a 
context-manager per Idea 1.


Building a custom-class (Idea 1 or Idea 3) enables the components to be 
kept together, per the ideal. It keeps the try-except components close 
and easy to relate. It is Pythonic (in the OOP style).


--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Best use of "open" context manager

2024-07-06 Thread Richard Damon via Python-list

My thoughts is that if the "many lines of code" puts the except to far
from the try, then perhaps it would have made sense to factor out some
part there into a function.

Perhaps like:

try:
   with open(FileName) as f:
  for ln in f{
 process(ln)
except FileNotFoundError:
   print(f"File {FileName} not found:")
   sys.exit()

Now the "process" function has been factored out and can be well
documented as to what it is doing on each line, and this code can be
documented as running process on each line of the file.

On 7/6/24 6:49 AM, Rob Cliffe via Python-list wrote:

Consider this scenario (which I ran into in real life):
    I want to open a text file and do a lot of processing on the lines
of that file.
    If the file does not exist I want to take appropriate action, e.g.
print an error message and abort the program.
I might write it like this:

try:
    with open(FileName) as f:
        for ln in f:
            print("I do a lot of processing here")
            # Many lines of code here .
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()

but this violates the principle that a "try" suite should be kept
small, so that only targeted exceptions are trapped,
not to mention that having "try" and "except" far apart decreases
readability.

Or I might write it like this:

try:
    f = open(FileName) as f:
    FileLines = f.readlines()
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()
# I forgot to put "f.close()" here -:)
for ln in File Lines:
        print("I do a lot of processing here")
        # Many lines of code here .

but this loses the benefits of using "open" as a context manager,
and would also be unacceptable if the file was too large to read into
memory.

Really I would like to write something like

try:
    with open(FileName) as f:
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()
else: # or "finally:"
        for ln in f:
            print("I do a lot of processing here")
            # Many lines of code here .

but this of course does not work because by the time we get to "for ln
in f:" the file has been closed so we get
ValueError: I/O operation on closed file

I could modify the last attempt to open the file twice, which would
work, but seems like a kludge (subject to race condition, inefficient).

Is there a better / more Pythonic solution?

Best wishes
Rob Cliffe



--
Richard Damon

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


Re: Best use of "open" context manager

2024-07-06 Thread Thomas Passin via Python-list

On 7/6/2024 6:49 AM, Rob Cliffe via Python-list wrote:

Consider this scenario (which I ran into in real life):
     I want to open a text file and do a lot of processing on the lines 
of that file.
     If the file does not exist I want to take appropriate action, e.g. 
print an error message and abort the program.

I might write it like this:

try:
     with open(FileName) as f:
         for ln in f:
             print("I do a lot of processing here")
             # Many lines of code here .
except FileNotFoundError:
     print(f"File {FileName} not found")
     sys.exit()

but this violates the principle that a "try" suite should be kept small, 
so that only targeted exceptions are trapped,
not to mention that having "try" and "except" far apart decreases 
readability.


Or I might write it like this:

try:
     f = open(FileName) as f:
     FileLines = f.readlines()
except FileNotFoundError:
     print(f"File {FileName} not found")
     sys.exit()
# I forgot to put "f.close()" here -:)
for ln in File Lines:
         print("I do a lot of processing here")
         # Many lines of code here .

but this loses the benefits of using "open" as a context manager,
and would also be unacceptable if the file was too large to read into 
memory.


Really I would like to write something like

try:
     with open(FileName) as f:
except FileNotFoundError:
     print(f"File {FileName} not found")
     sys.exit()
else: # or "finally:"
         for ln in f:
             print("I do a lot of processing here")
             # Many lines of code here .

but this of course does not work because by the time we get to "for ln 
in f:" the file has been closed so we get

ValueError: I/O operation on closed file

I could modify the last attempt to open the file twice, which would 
work, but seems like a kludge (subject to race condition, inefficient).


Is there a better / more Pythonic solution?


I usually read the file into a sequence of lines and then leave the 
open() as soon as possible.  Something like this:


FILENAME = 'this_is_an_example.txt'
lines = None
if os.path.exists(FILENAME):
with open(FILENAME) as f:
lines = f.readlines()
# do something with lines

Of course, if you want to read a huge number of lines you will need to 
be more thoughtful about it.  Or make all the processing within the 
open() block be a function.  Then you just have one more line in the block.


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


Re: Best use of "open" context manager

2024-07-06 Thread Oscar Benjamin via Python-list
On Sat, 6 Jul 2024 at 11:55, Rob Cliffe via Python-list
 wrote:
>
> Consider this scenario (which I ran into in real life):
>  I want to open a text file and do a lot of processing on the lines
> of that file.
>  If the file does not exist I want to take appropriate action, e.g.
> print an error message and abort the program.
> I might write it like this:
>
> try:
>  with open(FileName) as f:
>  for ln in f:
>  print("I do a lot of processing here")
>  # Many lines of code here .
> except FileNotFoundError:
>  print(f"File {FileName} not found")
>  sys.exit()
>
> but this violates the principle that a "try" suite should be kept small,
> so that only targeted exceptions are trapped,
> not to mention that having "try" and "except" far apart decreases
> readability.

This is catching a targeted exception (FileNotFoundError) so I think
it is fine. If the intention is just to call sys.exit() on error then
I wouldn't worry too much about having too much code in the try. Just
make sure that you do this in any other place where you open a file as
well.

One possible improvement is that you could catch the exception and use
its filename attribute:

except FileNotFoundError as e
 print(f"File {e.filename} not found")

That way if you did catch the wrong FileNotFoundError then at least
you print the correct filename.

Alternatively:

except FileNotFoundError as e
 if e.filename != FileName:
  raise  # re-raise if not the intended exception
 print(f"File {e.filename} not found")

For readability I would just move the many lines of code into a
separate function.

The reason to avoid having too much code in the try mainly applies to
situations where you are going to do something other than call
sys.exit() and the exception is overly generic like ValueError or
TypeError. If the exception can easily be raised by a bug or something
other than the intended cause then it is bad to catch exceptions
around a larger block of code.

If it is expected that the caller of a function might have good reason
to catch the exception and handle it somehow then it is better to make
a dedicated exception class and raise that instead. When there is only
one place in the code that raises a particular exception type and only
one place that catches it then it is usually going to be clear that
you are catching the expected exception.

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


Re: Best use of "open" context manager

2024-07-06 Thread Alan Gauld via Python-list
On 06/07/2024 11:49, Rob Cliffe via Python-list wrote:

>      If the file does not exist I want to take appropriate action, e.g. 
> print an error message and abort the program.
> I might write it like this:
> 
> try:
>      with open(FileName) as f:
>          for ln in f:
>              print("I do a lot of processing here")
>              # Many lines of code here .
> except FileNotFoundError:
>      print(f"File {FileName} not found")
>      sys.exit()
> 
> but this violates the principle that a "try" suite should be kept small, 

The try is small, it only has a single statement inside.
The compound block inside that statement should have its
own try/ecxepts but the outer one really only applies to
the with statement.

I certainly prefer this option to any of the others presented.

> not to mention that having "try" and "except" far apart decreases 
> readability.

This is a valid concern although that's part of the reason
we use indentation. Compared to early BASIC and FORTRAN with massive
GOSUB type leaps (and often no indentation) it's very readable!

But its still preferable to having the multi-level indents below
or having to remember to close the file when finished (and
ensure that all possible paths do so.

> try:
>      f = open(FileName) as f:
>      FileLines = f.readlines()
> except FileNotFoundError:
>      print(f"File {FileName} not found")
>      sys.exit()
> # I forgot to put "f.close()" here -:)

Exactly! That's why using with is safer even if the
except is detached from the try.

You are also reading the entire file into memory which could
be an issue. And you are not catching any errors in the
read operations because the except only covers a missing
file.

> Really I would like to write something like
> 
> try:
>      with open(FileName) as f:
> except FileNotFoundError:
>      print(f"File {FileName} not found")
>      sys.exit()
> else: # or "finally:"
>          for ln in f:
>              print("I do a lot of processing here")
>              # Many lines of code here .

I find that much less readable because the file handling
block is a long way from the open file line and has extra
control statements to mentally negotiate.

The advantage of the original version is that you can
ignore errors and read the code easily. You only need
to find the except clause if you need to know how errors
will be dealt with. But if comprehending the core
functionality of the code you can just ignore all
the error handling blocks.

> Is there a better / more Pythonic solution?

All IMHO of course, but I think the current implementation
is the best of the options presented.

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


Re: Best use of "open" context manager

2024-07-06 Thread Dan Sommers via Python-list
On 2024-07-06 at 11:49:06 +0100,
Rob Cliffe via Python-list  wrote:

> Is there a better / more Pythonic solution?

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

At least this attempts to abstract the problem of iterating over a file
(or multiple files) into a library routine.  I've used it a little, but
I don't know the full depths of your use case and/or requirements.

HTH,
Dan
-- 
https://mail.python.org/mailman/listinfo/python-list


Best use of "open" context manager

2024-07-06 Thread Rob Cliffe via Python-list

Consider this scenario (which I ran into in real life):
    I want to open a text file and do a lot of processing on the lines 
of that file.
    If the file does not exist I want to take appropriate action, e.g. 
print an error message and abort the program.

I might write it like this:

try:
    with open(FileName) as f:
        for ln in f:
            print("I do a lot of processing here")
            # Many lines of code here .
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()

but this violates the principle that a "try" suite should be kept small, 
so that only targeted exceptions are trapped,
not to mention that having "try" and "except" far apart decreases 
readability.


Or I might write it like this:

try:
    f = open(FileName) as f:
    FileLines = f.readlines()
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()
# I forgot to put "f.close()" here -:)
for ln in File Lines:
        print("I do a lot of processing here")
        # Many lines of code here .

but this loses the benefits of using "open" as a context manager,
and would also be unacceptable if the file was too large to read into 
memory.


Really I would like to write something like

try:
    with open(FileName) as f:
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()
else: # or "finally:"
        for ln in f:
            print("I do a lot of processing here")
            # Many lines of code here .

but this of course does not work because by the time we get to "for ln 
in f:" the file has been closed so we get

ValueError: I/O operation on closed file

I could modify the last attempt to open the file twice, which would 
work, but seems like a kludge (subject to race condition, inefficient).


Is there a better / more Pythonic solution?

Best wishes
Rob Cliffe
--
https://mail.python.org/mailman/listinfo/python-list


Re: python for irc client

2024-07-04 Thread Daniel via Python-list
inhahe  writes:

> On Thu, Jul 4, 2024 at 5:14 AM Daniel via Python-list <
> python-list@python.org> wrote:
>
>> Hi guys -
>>
>> I have historical experience developing sofwtare for my own use. It has
>> been
>> quite a while since doing so and the advent of new languages has brought me
>> here. Python has built quite a reputation. It would be fun to pick up a
>> new language while I'm at it.
>>
>> I've been a consumer of IRC since the nineties and have been running an
>> instance of quassel core on an old laptop for the last decade. Over the
>> years, my use of xwindows has dramatically decreased and I spend 90% of my
>> computer time with multiple panes of tmux while I do my usual daily fun.
>> One
>> thing missing is a good textmode irc client that will connect to quassel
>> core.
>>
>> I've seen efforts to make a plugin for weechat but, to date, I don't see
>> much
>> progress on that end.
>>
>> In your wisdom, would python be a good environment to accomplish this? I'd
>> likely use extended ascii and colors. The point would be to minimize the
>> memory footprint of the application.
>>
>> I don't use standard desktop computers anymore - I'm writing this on my
>> beloved pi400 using emacs.
>>
>> Thanks
>>
>> Daniel
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>
>
> I think Python would be a great language to write an IRC client in, it's a
> rapid-development language, and also Python is particularly good for text
> manipulation and the IRC protocol is textual rather than binary. But, if
> your only purpose for using Python is to reduce the memory footprint, I'm
> not sure. I don't know specifically, but I'd guess Python has a higher
> memory footprint than, say, C, because it's a high-level language. For
> example, each variable has to be boxed, and also the interpreter has to be
> loaded..
>
> Regarding high ASCII, I don't know if that works in IRC, but either way,
> ASCII isn't really enough nowadays. You need to support Unicode;
> specifically, UTF-8.

Okay great. Since my original post, I settled on UTF8. I have to create
a list of requirements for v1.0 to limit scope creep and I can actually
get this done.

I may put it on github and solicit for assistance at some point.

Thanks for the response, both of them. I'll look at the other code and
see how I can fold it in. What I have to find out, still, is how the
core server manages the messages. I suspect the core does all the
sending and receiving and the client just sends the packets to core for
management. That's just a guess though.

I still have to review the liraries, this is a new idea hatched last
night so I have yet to investigate much.

My initial thought was C++ but this would be my first termianl-only
application in many years so I thought a different coding platform would
be effective.

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


Re: python for irc client

2024-07-04 Thread Left Right via Python-list
Hi.

Just FYI, I use Erc (in Emacs). I'm not a very advanced user, perhaps,
but I never felt like I miss anything. That's not to stop you from
making your own, but if you just need a decent text client for IRC,
then there's already at least one.

On Thu, Jul 4, 2024 at 11:30 AM inhahe via Python-list
 wrote:
>
> On Thu, Jul 4, 2024 at 5:22 AM inhahe  wrote:
>
> >
> >
> > On Thu, Jul 4, 2024 at 5:14 AM Daniel via Python-list <
> > python-list@python.org> wrote:
> >
> >>
> >> In your wisdom, would python be a good environment to accomplish this?
> >
> >
>
> > I think Python would be a great language to write an IRC client in, it's a
> > rapid-development language, and also Python is particularly good for text
> > manipulation and the IRC protocol is textual rather than binary.
> >
>
> Oh yeah, I forgot I was going to mention that Twisted has already done a
> lot of the dirty work for you if you make it in Python...they have twisted.
> words.protocols.irc, which implements the IRC protocol. (I don't know if
> it's up to date and supports ircv3, though.)
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python for irc client

2024-07-04 Thread inhahe via Python-list
On Thu, Jul 4, 2024 at 5:22 AM inhahe  wrote:

>
>
> On Thu, Jul 4, 2024 at 5:14 AM Daniel via Python-list <
> python-list@python.org> wrote:
>
>>
>> In your wisdom, would python be a good environment to accomplish this?
>
>

> I think Python would be a great language to write an IRC client in, it's a
> rapid-development language, and also Python is particularly good for text
> manipulation and the IRC protocol is textual rather than binary.
>

Oh yeah, I forgot I was going to mention that Twisted has already done a
lot of the dirty work for you if you make it in Python...they have twisted.
words.protocols.irc, which implements the IRC protocol. (I don't know if
it's up to date and supports ircv3, though.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python for irc client

2024-07-04 Thread inhahe via Python-list
On Thu, Jul 4, 2024 at 5:14 AM Daniel via Python-list <
python-list@python.org> wrote:

> Hi guys -
>
> I have historical experience developing sofwtare for my own use. It has
> been
> quite a while since doing so and the advent of new languages has brought me
> here. Python has built quite a reputation. It would be fun to pick up a
> new language while I'm at it.
>
> I've been a consumer of IRC since the nineties and have been running an
> instance of quassel core on an old laptop for the last decade. Over the
> years, my use of xwindows has dramatically decreased and I spend 90% of my
> computer time with multiple panes of tmux while I do my usual daily fun.
> One
> thing missing is a good textmode irc client that will connect to quassel
> core.
>
> I've seen efforts to make a plugin for weechat but, to date, I don't see
> much
> progress on that end.
>
> In your wisdom, would python be a good environment to accomplish this? I'd
> likely use extended ascii and colors. The point would be to minimize the
> memory footprint of the application.
>
> I don't use standard desktop computers anymore - I'm writing this on my
> beloved pi400 using emacs.
>
> Thanks
>
> Daniel
> --
> https://mail.python.org/mailman/listinfo/python-list


I think Python would be a great language to write an IRC client in, it's a
rapid-development language, and also Python is particularly good for text
manipulation and the IRC protocol is textual rather than binary. But, if
your only purpose for using Python is to reduce the memory footprint, I'm
not sure. I don't know specifically, but I'd guess Python has a higher
memory footprint than, say, C, because it's a high-level language. For
example, each variable has to be boxed, and also the interpreter has to be
loaded..

Regarding high ASCII, I don't know if that works in IRC, but either way,
ASCII isn't really enough nowadays. You need to support Unicode;
specifically, UTF-8.
-- 
https://mail.python.org/mailman/listinfo/python-list


python for irc client

2024-07-04 Thread Daniel via Python-list
Hi guys -

I have historical experience developing sofwtare for my own use. It has been
quite a while since doing so and the advent of new languages has brought me
here. Python has built quite a reputation. It would be fun to pick up a
new language while I'm at it.

I've been a consumer of IRC since the nineties and have been running an
instance of quassel core on an old laptop for the last decade. Over the
years, my use of xwindows has dramatically decreased and I spend 90% of my
computer time with multiple panes of tmux while I do my usual daily fun. One
thing missing is a good textmode irc client that will connect to quassel
core.

I've seen efforts to make a plugin for weechat but, to date, I don't see much
progress on that end.

In your wisdom, would python be a good environment to accomplish this? I'd
likely use extended ascii and colors. The point would be to minimize the
memory footprint of the application.

I don't use standard desktop computers anymore - I'm writing this on my
beloved pi400 using emacs.

Thanks

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


ANN: eGenix PyRun - One file Python Runtime 2.5.0

2024-07-01 Thread eGenix Team via Python-list

*ANNOUNCING*


   eGenix PyRun - One file Python Runtime

Version 2.5.0

Python runtime taking up just 4-6MB on disk

This announcement is also available on our web-site for online reading:
https://www.egenix.com/company/news/eGenix-PyRun-2.5.0-GA.html


*INTRODUCTION*

*eGenix PyRun*™  
is our open source, one file, no installation version of Python, making 
the distribution of a Python interpreter to run Python based scripts and 
applications to Unix based systems simple and efficient.


eGenix PyRun's executable only needs 4-6MB on disk, but still supports 
most Python applications and scripts.


Compared to a regular Python installation of typically 100MB on disk, 
eGenix PyRun is ideal for applications and scripts that need to be 
distributed to containers, VMs, clusters, client installations, 
customers or end-users.


It makes "installing" Python on a Unix based system as simple as copying 
a single file.


eGenix has been using eGenix PyRun as run-time for the Linux version of 
mxODBC Connect Server 
 product since 
2008 with great success and decided to make it available as a 
stand-alone open-source product.


We provide the source archive to build your own *eGenix PyRun on Github* 
, as well as a few binary 
distributions to get you started on Linux x86_64. In the future, we will 
set up automated builds for several other platforms.


Please see the product page for more details:

>>> eGenix PyRun - One file Python Runtime 





*NEWS*

This major release of eGenix PyRun 
 comes with the following 
enhancements:


 * Added support for *Python 3.8 - 3.11*
 * Removed support for Python 3.5-3.7
 * Modernized the directory setup and build
 * Changed the license to the *Apache2 license*
 * Extracted the code from our internal mono-repo to put on Github
 * *Relaunched the project on Github*

For a complete list of changes, please see the *eGenix PyRun Changelog 
*.



Enjoy,

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Jul 01 2024)

Python Projects, Coaching and Support ...https://www.egenix.com/
Python Product Development ...https://consulting.egenix.com/



::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48

D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   https://www.egenix.com/company/contact/
 https://www.malemburg.com/
--
https://mail.python.org/mailman/listinfo/python-list


Re: Difference method vs attribut = function

2024-06-30 Thread Dieter Maurer via Python-list
Ulrich Goebel wrote at 2024-6-28 18:08 +0200:
>Hi,
>
>a class can have methods, and it can have attributes, which can hold a 
>function. Both is well known, of course.
>
>My question: Is there any difference?

I think you should make the distinction "class versus instance attribute"
rather than "mether versus function".

If you look at the `__dict__` of an instance, you see only the
instance variables (the class's `__dict__` gives you the (most) attributes
of the class).

You can access (most) class attributes via an instance;
if a function is accessed in this way, it becomes (typically) a method.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference method vs attribut = function

2024-06-29 Thread Thomas Passin via Python-list

On 6/28/2024 12:08 PM, Ulrich Goebel via Python-list wrote:

Hi,

a class can have methods, and it can have attributes, which can hold a 
function. Both is well known, of course.

My question: Is there any difference?

The code snipped shows that both do what they should do. But __dict__ includes 
just the method, while dir detects the method and the attribute holding a 
function. My be that is the only difference?


class MyClass:
 def __init__(self):
 functionAttribute = None
 
 def method(self):

 print("I'm a method")

def function():
 print("I'm a function passed to an attribute")

mc = MyClass()
mc.functionAttribute = function

mc.method()
mc.functionAttribute()

print('Dict: ', mc.__dict__)# shows functionAttribute but not method
print('Dir:  ', dir(mc))# shows both functionAttribute and method


By the way: in my usecase I want to pass different functions to different 
instances of MyClass. It is in the context of a database app where I build 
Getters for database data and pass one Getter per instance.

Thanks for hints
Ulrich



https://docs.python.org/3/library/functions.html#dir -

object.__dict__¶
A dictionary or other mapping object used to store an object’s 
(writable) attributes.


dir(object)
...
With an argument, attempt to return a list of valid attributes for that 
object.


"functionAttribute" is a class method, not an instance method.  If you 
want an instance method:


class MyClass:
def __init__(self):
functionAttribute = None
self.instance_functionAttribute = None

def method(self):
print("I'm a method")

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


Re: Difference method vs attribut = function

2024-06-29 Thread Mats Wichmann via Python-list

On 6/28/24 10:08, Ulrich Goebel via Python-list wrote:


By the way: in my usecase I want to pass different functions to different 
instances of MyClass. It is in the context of a database app where I build 
Getters for database data and pass one Getter per instance.


If I understood what you're trying to accomplish, you could take a look 
here (possibly a bit complex for what you need).


https://refactoring.guru/design-patterns/strategy/python/example



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


Re: Difference method vs attribut = function

2024-06-29 Thread Peter J. Holzer via Python-list
On 2024-06-28 18:08:54 +0200, Ulrich Goebel via Python-list wrote:
> a class can have methods, and it can have attributes, which can hold a
> function. Both is well known, of course.
> 
> My question: Is there any difference?
> 
> The code snipped shows that both do what they should do. But __dict__
> includes just the method,

The other way around: It includes only the attributes, not the methods.

> while dir detects the method and the
> attribute holding a function. My be that is the only difference?
> 
> 
> class MyClass:
> def __init__(self):
> functionAttribute = None
> 
> def method(self):
> print("I'm a method")
> 
> def function():
> print("I'm a function passed to an attribute")

Here is the other main difference: The object is not passed implicitely
to the function. You have no way to access mc here.

You can create a method on the fly with types.MethodType:

import types
mc.functionAttribute = types.MethodType(function, mc)


> By the way: in my usecase I want to pass different functions to
> different instances of MyClass. It is in the context of a database app
> where I build Getters for database data and pass one Getter per
> instance.

Or in this case, since each function is specific to one instance, you
could just use a closure to capture the object. But that might be
confusing to any future maintainers (e.g. yourself in 6 months), if the
method doesn't actually behave like a method.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Difference method vs attribut = function

2024-06-29 Thread Ulrich Goebel via Python-list
Hi,

a class can have methods, and it can have attributes, which can hold a 
function. Both is well known, of course.

My question: Is there any difference?

The code snipped shows that both do what they should do. But __dict__ includes 
just the method, while dir detects the method and the attribute holding a 
function. My be that is the only difference?


class MyClass:
def __init__(self):
functionAttribute = None

def method(self):
print("I'm a method")

def function():
print("I'm a function passed to an attribute")

mc = MyClass()
mc.functionAttribute = function

mc.method()
mc.functionAttribute()

print('Dict: ', mc.__dict__)# shows functionAttribute but not method
print('Dir:  ', dir(mc))# shows both functionAttribute and method


By the way: in my usecase I want to pass different functions to different 
instances of MyClass. It is in the context of a database app where I build 
Getters for database data and pass one Getter per instance.

Thanks for hints
Ulrich


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


[RELEASE] Python 3.13.0 beta 3 released.

2024-06-27 Thread Thomas Wouters via Python-list
The *next to last* Python 3.13 beta version, beta 3, is now released:
https://www.python.org/downloads/release/python-3130b3/

*This is a beta preview of Python 3.13*

Python 3.13 is still in development. This release, 3.13.0b3, is the third
of four beta release previews of 3.13.

Beta release previews are intended to give the wider community the
opportunity to test new features and bug fixes and to prepare their
projects to support the new feature release.

We *strongly encourage* maintainers of third-party Python projects to *test
with 3.13* during the beta phase and report issues found to the Python bug
tracker  as soon as possible.
While the release is planned to be feature complete entering the beta
phase, it is possible that features may be modified or, in rare cases,
deleted up until the start of the release candidate phase (Tuesday
2024-07-30). Our goal is to have no ABI changes after beta 4 and as few
code changes as possible after 3.13.0rc1, the first release candidate. To
achieve that, it will be *extremely important* to get as much exposure for
3.13 as possible during the beta phase.

Please keep in mind that this is a preview release and its use is *not*
recommended for production environments.
Major
new features of the 3.13 series, compared to 3.12

Some of the new major new features and changes in Python 3.13 are:
New
features

   - A new and improved interactive interpreter
   
,
   based on PyPy ’s, featuring multi-line editing and
   color support, as well as colorized exception tracebacks
   
   .
   - An *experimental* free-threaded build mode
   ,
   which disables the Global Interpreter Lock, allowing threads to run more
   concurrently. The build mode is available as an experimental feature in the
   Windows and macOS installers as well.
   - A preliminary, *experimental* JIT
   ,
   providing the ground work for significant performance improvements.
   - The (cyclic) garbage collector is now incremental
   
,
   which should mean shorter pauses for collection in programs with a lot of
   objects.
   - A modified version of mimalloc 
   is now included, optional but enabled by default if supported by the
   platform, and required for the free-threaded build mode.
   - Docstrings now have their leading indentation stripped
   ,
   reducing memory use and the size of .pyc files. (Most tools handling
   docstrings already strip leading indentation.)
   - The dbm module  has a
   new dbm.sqlite3 backend
    that is used by
   default when creating new files.
   - The minimum supported macOS version was changed from 10.9 to *10.13
   (High Sierra)*. Older macOS versions will not be supported going forward.


Typing

   - Support for type defaults in type parameters
   .
   - A new type narrowing annotation ,
   typing.TypeIs.
   - A new annotation for read-only items in TypeDicts
   .

Removals
and new deprecations

   - PEP 594 (Removing dead batteries from the standard library)
    scheduled removals of many
   deprecated modules: aifc, audioop, chunk, cgi, cgitb, crypt, imghdr,
   mailcap, msilib, nis, nntplib, ossaudiodev, pipes, sndhdr, spwd, sunau,
   telnetlib, uu, xdrlib, lib2to3.
   - Many other removals
    of deprecated
   classes, functions and methods in various standard library modules.
   - C API removals 
   and deprecations .
   (Some removals present in alpha 1 were reverted in alpha 2, as the removals
   were deemed too disruptive at this time.)
   - New deprecations
   , most of
   which are scheduled for removal from Python 3.15 or 3.16.

(Hey, *fellow core developer,* if a feature 

Re: [Tutor] How to install tensorflow on Python 2.7 in Windows?

2024-06-26 Thread Mats Wichmann via Python-list

On 6/26/24 09:29, marc nicole wrote:

Browsing the available version of tensorflow for the dates before January
2021 (date when Python 2.7 stopped being supported) I can't find a
tensorflow version for Python 2.7 that works under Windows.

The reference site I use is https://pypi.org/project/tensorflow/

Anybody can point out a compatible .whl file with Python 2.7 and Windows?


The last version of tensorflow to support Python 2.7 was indeed 2.1, and 
I don't think there was *ever* an official Windows wheel for Python 2, 
but I'm not that expert to be completely sure. tensorflow support on 
Windows has never been good, and in a way they've given up, at least 
part of the fight: they no longer produce official releases for Windows 
with GPU support (although you may be able to get one from the vendor 
that produces the GPU hardware like Nvidia or Intel, or from a third 
party like Amazon Web Services). The official recommendation for WIndows 
used to be "build your own" (which nearly always failed), then for a few 
years they tried making Windows builds, now the new "best practice" 
recommendation is to install on WSL if you want to run on a Windows box 
(this *might* work for you, unless you're also on an ancient Windows 
that won't run WSL).  Or, try seeing if you can find a docker setup 
(which, again, will give you a Linux environment running tensorflow).


Note that like your other problem, getting numpy going, this is going to 
be an uphill battle trying to cobble things together to run on 2.7. 
This is really the problem when something like Python goes out of date / 
out of support: it's not that it magically stops working, it's that vast 
amounts of the ecosystem around it stop providing support for *their* 
bits on the old version, and the combinations become progressively 
harder to make work.



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


How to install tensorflow on Python 2.7 in Windows?

2024-06-26 Thread marc nicole via Python-list
Browsing the available version of tensorflow for the dates before January
2021 (date when Python 2.7 stopped being supported) I can't find a
tensorflow version for Python 2.7 that works under Windows.

The reference site I use is https://pypi.org/project/tensorflow/

Anybody can point out a compatible .whl file with Python 2.7 and Windows?
-- 
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-25 Thread Anton Shepelev via Python-list
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, and of course there is Gmane:

  

which actually subscribes users to mailing lists (on their
behalf).  Gmane's NNTP server is: news.gmane.io .

-- 
()  ascii ribbon campaign -- against html e-mail
/\  www.asciiribbon.org   -- against proprietary attachments
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anonymous email users

2024-06-25 Thread Anton Shepelev via Python-list
Sebastian Wells:

> The spammers won the spam wars, so even if you have
> someone's real e-mail address, that's no guarantee that
> you can contact them.

No so with me.  My e-mail address here is munged, but in a
very obvious way, and no, my mailbox is not overwhelmed with
spam.

I make a habit of reporting spam via:

  1.  https://www.spamcop.net/anonsignup.shtml
  2.  https://submit.spamhaus.org/submit/

They maintain blacklists of e-mail providers or notify them
of spam e-mails.  It helps.

-- 
()  ascii ribbon campaign -- against html e-mail
/\  www.asciiribbon.org   -- against proprietary attachments
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Anonymous email users

2024-06-24 Thread AVI GROSS via Python-list
This discussion has wandered far from my original mention that I found it
hard to reply to people using an invalid email address. I see no real
connection to python except insofar as at least one spam-filter mentioned is
written in python!

Just to add an observation, the people writing here have obviously had many
different experiences with their email addresses and whether yours is
hijacked in some way, and made less useful, can even just become down to
random luck. 

But SPAM filters can also be manipulated and cause you to lose mail. I think
some people have been reporting email from a source they do not favor, such
as for political reasons, that then ends up being junked for people who
would welcome the messages. And, I can well imagine how something like a
post about python programs can start being filtered out because some key
words commonly use end up being used a lot in some kind of SPAM and the
filter "learns" to filter those out. Imagine of "python" appeared in lots of
actual SPAM messages as the war moved on, such as in the metadata designed
to make it look legit.

Email addresses can go bad for many reasons. My wife had a nice simple
address like jane.sm...@gmail.com that was messed up probably by
well-meaning people when another Jane Smith had an email address like
smith.jane or janesmith123 and they or others typed in the more
straightforward ones. It seems we ended up getting odd email from many
continents such as e-tickets for airplanes, initial estimates or bills from
vendors for products in places we have never been for services rendered in
say Tennessee or South Africa (well, I've been in Tennessee, but) and
subscriptions to internet magazines or groups that sent lots of messages, or
conversations between lots of people (all To: or Cc:) that included her
email address wrongly and even when she replied to ask to be taken off, the
conversations continued for months as many kept hitting reply-all, ...)

And, obviously, with so many people using the address wrongly, SPAM
followed.

Of course, choosing a strange name designed not to be typed by accident, has
it's own disadvantages.

But for those who want me to CALL their unspecified phone number and tell
them the subject line and then maybe you will look for my message,
FUGGEDABOUTIT! I have a cousin who does a trick  with her phone service
where she never answers and I have to run some gauntlet to identify myself
and then wait for a call back. After a few times, I solved the problem and
simply never call her.

Admittedly, making it hard for an email address to be abused in a forum like
this is understandable. Making it very hard to reach you legitimately when
the message is that your house is burning or just that your appointment is
canceled, may not work as well as you think.

And, FYI, I check my junkmail regularly and I have a fairly high rate of
finding things, including posts on forums like this one, that are NOT in my
opinion junk as I ordered them and they are on topic and not easily visible
as having committed some kind of sin. And as I use many email services, I
still find a high rate of false negatives everywhere.

It would not surprise me if a phrase like "not SPAM" gets this message
dumped into /dev/null


-Original Message-
From: Python-list  On
Behalf Of Chris Angelico via Python-list
Sent: Monday, June 24, 2024 9:49 PM
To: python-list@python.org
Subject: Re: Anonymous email users

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

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 Grant Edwards via Python-list
On 2024-06-24, Barry Scott via Python-list  wrote:
>> On 23 Jun 2024, at 06:58, Sebastian Wells via Python-list 
>>  wrote:
>> 
>> The spammers won the spam wars, so even if you have someone's real
>> e-mail address, that's no guarantee that you can contact them. [...]
>
> My email address is well known and yes I get spam emails.

I've been puzzled by this for a long time. Many people talk about how
they get so much spam e-mail that there's little chance they'll notice
if I send them an e-mail.

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.

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?

--
Grant


-- 
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: Anonymous email users

2024-06-24 Thread dn via Python-list

On 25/06/24 05:17, Thomas Passin via Python-list wrote:

On 6/24/2024 5:51 AM, Barry Scott via Python-list wrote:



On 23 Jun 2024, at 06:58, Sebastian Wells via Python-list 
 wrote:


The spammers won the spam wars, so even if you have someone's real
e-mail address, that's no guarantee that you can contact them. You
certainly wouldn't be able to contact me at my real e-mail address,
unless you also had my phone number, so you could call me and tell
me that you sent me an e-mail, and what the subject line was so I
can find it. I don't even open my e-mail inbox unless there's a
specific message I'm expecting to find there right now.


My email address is well known and yes I get spam emails.

I use the wonderful python based spambayes software to detect spam and
file into a Junk folder. It works for 99.9% of the emails I get.


I use the Thunderbird mail client and I just use its built in spam 
detector.  I don't know how it works but it's pretty darn good.  Very 
few false positives or false negatives.  And it learns each time I 
classify a message as "Junk", in case it missed one.


I am subscribed to a lot of mailing lists. I just checked and I am 
getting ~3,200

emails a month of which less than 200 are spam.

A few years ago the spam count was greater than a 1,000 a month.

I have been using spambayes for a very long time, 20 years I guess at 
this

point and bayesian categorisation has stood the test of time for me.

For me the spammers have not won, I have the tech to keep ahead of them.


Aside from the attractions of the new, and the 'shiny', what 
email-antagonists didn't anticipate, was that as fast as they moved to 
non-email messaging, the spammers, advertisers, and malcontents would 
simply do the same. Thus, a variation on whack-a-mole, as folk move from 
platform to platform trying to stay-ahead and find an illusion of 
safety. Quite how one out-runs human-nature is an issue 
philosophised-over by the (Ancient) Greeks (and was no-doubt old even-then).


Paradoxically, applying for an account elsewhere usually involves 
providing an email address. Even backing-up a cell-phone (communication 
tool) to the cloud requires an email address(!!!)


Most of the non-email platforms are provided by organisations who have 
'other uses' for your personal-data (and not forgetting GMail and MSFT's 
email services).


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!


--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


RE: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects)

2024-06-24 Thread AVI GROSS via Python-list
Marc,

Several people have supplied feedback on whether your request is a good fit for 
here. Ultimately it is up to the owner/moderator. In particular, your request 
to the Tutor List may not fit the purpose and be a bit complex  and to the main 
Python List also outside some common usage whether it is about a specific 
module or product you are using, or asking about algorithms in a very general 
way.

You question has evolved to being about algorithms, more than about Python as a 
basic language or even commonly used modules.

So, I suggest you simplify your model and then maybe bring it in-line with the 
module(s) you showed us you were using. Some of what you ask sounds like it 
would be extremely commonly done in things like robotics, or even just machines 
with moving parts.

Consider the somewhat related concept often seen of how you get from one place 
to another in parts of Manhattan where most of the streets run either in one 
direction or the orthogonal direction. How do you get from say East 14th Street 
at 1st Avenue to West 28th Street and 11th Avenue? This is a slight imitation 
of how to move a robotic arm that can mainly either go one way or another but 
not both at once. And, in the real world, parts of Manhattan are more complex 
with streets ending or renaming or running more diagonally or huge voids like 
Central Park.

The number of solutions is huge for walking, and smaller for driving as some 
streets are one way. But assuming you avoid wasteful paths (except when roads 
are closed for endless purposes) and you do not take a path through Brooklyn, 
Queens and The Bronx and back to Manhattan as in the NY Marathon that also 
touches another borough, the solutions mainly look like this:

Go as far horizontally as you need and then as far vertically.
Or, do vertical, then horizontal.
Or lots of combined versions such as climbing stairs by doing a block or three 
one way then some in the other and repeat.

The above is referred to as Manhattan Distance, as compared to other measures 
like Euclidean distance.

So back to your robot arm, you can see a set of simple solutions where you make 
a sort of triangle with the direct Euclidean arm being a hypoteneuse and the  X 
and Y movements are the other two sides. You can then break up your problem as 
heading one way and pausing and turning the other way and stopping just short 
of the object you want. If there are no obstacles, you can do that in either 
order. Or, you could alternate in smaller amounts and get to the same 
destination. 

Grabbing it would be something else I will not address except to say that 
depending on what is grabbing and how it is shaped, you may need to aim not for 
the object, but the appropriate distance and direction so that when you stop 
moving, the "grasper" can close on it, again, avoiding existing obstacles. And 
note, speed is a consideration as many things need to be approached slowly and 
gently.

Next, consider what it would mean if you could have a combined motion based on 
both operations allowed at the same time. Consider a robot that is on wheels 
that can move horizontally while also having a "lift" component that lifts the 
part with the graspers vertically. Both could be programmed to run in tandem at 
appropriate speeds so the graspers are traveling along the hypotenuse I mention 
and are going the shortest path. This might be faster and more economical in 
other ways but can be more complex. And, it may be the robot does not have 
power or computing ability to do both at the same time. Your design is beyond 
vague.

Both of the approaches above make a plan and carry it out. But in the real 
world, many algorithms must adjust and work somewhat probabilistically. One 
algorithm for say catching a moving object, especially one that can change 
speed and direction a bit, like a running dog or a kite flying in the wind, is 
to locate where the object seems to be now, perhaps just a direction and a 
guess at distance, and maybe with some observation make a guess at where it 
might be at some time in the future that is approximately when you might move 
the robot near there. Then, use a technique like above (or completely 
different) that perhaps aims to get you something like halfway there. Monitor 
along the way to update your position and the newest destination position (if 
it is moving) and re-evaluate and adjust for the next round and maybe evaluate 
again as you approach halfway or so, again. Eventually, if you are close, slow 
down and gradually try to come to a stop where you can grab. If the object 
reacts to your attempting to go after it, it can be complex. And, you may 
overshoot and sort of circle back.

Now, expand the problem more if needed. What does the robot look like. How many 
places can it bend? For example, can it have something like two or more elbows, 
perhaps one allowing twisting of up to 30 degrees and one moving forward and 
backward and another allowing movement side to 

Re: Anonymous email users

2024-06-24 Thread Thomas Passin via Python-list

On 6/24/2024 5:51 AM, Barry Scott via Python-list wrote:




On 23 Jun 2024, at 06:58, Sebastian Wells via Python-list 
 wrote:

The spammers won the spam wars, so even if you have someone's real
e-mail address, that's no guarantee that you can contact them. You
certainly wouldn't be able to contact me at my real e-mail address,
unless you also had my phone number, so you could call me and tell
me that you sent me an e-mail, and what the subject line was so I
can find it. I don't even open my e-mail inbox unless there's a
specific message I'm expecting to find there right now.


My email address is well known and yes I get spam emails.

I use the wonderful python based spambayes software to detect spam and
file into a Junk folder. It works for 99.9% of the emails I get.


I use the Thunderbird mail client and I just use its built in spam 
detector.  I don't know how it works but it's pretty darn good.  Very 
few false positives or false negatives.  And it learns each time I 
classify a message as "Junk", in case it missed one.



I am subscribed to a lot of mailing lists. I just checked and I am getting 
~3,200
emails a month of which less than 200 are spam.

A few years ago the spam count was greater than a 1,000 a month.

I have been using spambayes for a very long time, 20 years I guess at this
point and bayesian categorisation has stood the test of time for me.

For me the spammers have not won, I have the tech to keep ahead of them.

Barry



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


Re: Anonymous email users

2024-06-24 Thread Barry Scott via Python-list



> On 23 Jun 2024, at 06:58, Sebastian Wells via Python-list 
>  wrote:
> 
> The spammers won the spam wars, so even if you have someone's real
> e-mail address, that's no guarantee that you can contact them. You
> certainly wouldn't be able to contact me at my real e-mail address,
> unless you also had my phone number, so you could call me and tell
> me that you sent me an e-mail, and what the subject line was so I
> can find it. I don't even open my e-mail inbox unless there's a
> specific message I'm expecting to find there right now.

My email address is well known and yes I get spam emails.

I use the wonderful python based spambayes software to detect spam and
file into a Junk folder. It works for 99.9% of the emails I get.

I am subscribed to a lot of mailing lists. I just checked and I am getting 
~3,200
emails a month of which less than 200 are spam.

A few years ago the spam count was greater than a 1,000 a month.

I have been using spambayes for a very long time, 20 years I guess at this
point and bayesian categorisation has stood the test of time for me.

For me the spammers have not won, I have the tech to keep ahead of them.

Barry

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


Tkinter and astral characters (was: Decoding bytes to text strings in Python 2)

2024-06-24 Thread Peter J. Holzer via Python-list
On 2024-06-24 01:14:22 +0100, 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.

I just tried modifying
https://docs.python.org/3/library/tkinter.html#a-hello-world-program
to display "Hello World \N{ROCKET}" instead (Python 3.10.12 as included
with Ubuntu 22.04). I don't get a warning or error, but the emoji isn't
displayed either.

I suspect that the default font doesn't include emojis and Tk isn't
smart enough to fall back to a different font (unlike xfce4-terminal
which shows the emoji just fine).

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects)

2024-06-24 Thread marc nicole via Python-list
What are the parameters to account for in this type of algorithm? are there
some checks to perform the arm moves ? for example angle moves or cartesian
moves based on some distance thresholds? Any idea about the
pseudo-algorithm is welcome.

Thanks.

Le dim. 23 juin 2024 à 10:33, Alan Gauld via Tutor  a
écrit :

> On 22/06/2024 13:41, marc nicole wrote:
>
> > So, given the x,y,z coordinates of a target object and the offset x,y,z
> of
> > arms of a robot, what is a good algorithm to perform to grab the object
> > between the hands (either from both sides or from below all using both
> > hands).
> >
> > Specifically, my problem is applied to a NAO robot environment where I
> > retrieve a target object coordinates using the following code:
>
> This is almost entirely outside the Python domain and all within
> your 3rd party environment. Do they have a user forum or mailing
> list? You will probably get better results asking there?
>
> Another possibility is that you are using a Python wrapper around
> a C (or other language) library and there might be FAQs, fora or
> lists supporting that. If so you should be able to translate
> their examples to your Python code?
>
> In terms of generic solutions the only thing I can suggest that
> might help is to research collision detection algorithms.
> Wikipedia is likely a good starting point.
>
> --
> 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
>
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-- 
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 MRAB via Python-list

On 2024-06-24 00:30, Chris Angelico via Python-list wrote:

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.


[snip]
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.

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


  1   2   3   4   5   6   7   8   9   10   >