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 <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 <https://github.com/python/cpython/issues> 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.
<https://discuss.python.org/t/python-3-13-0b4-now-available/58565#major-new-features-of-the-313-series-compared-to-312-1>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:
<https://discuss.python.org/t/python-3-13-0b4-now-available/58565#new-features-2>New
features

   - A new and improved interactive interpreter
   
<https://docs.python.org/3.13/whatsnew/3.13.html#a-better-interactive-interpreter>,
   based on PyPy <https://pypy.org>’s, featuring multi-line editing and
   color support, as well as colorized exception tracebacks
   <https://docs.python.org/3.13/whatsnew/3.13.html#improved-error-messages>
   .
   - An *experimental* free-threaded build mode
   <https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython>,
   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
   <https://docs.python.org/3.13/whatsnew/3.13.html#experimental-jit-compiler>,
   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
   
<https://docs.python.org/3.13/whatsnew/3.13.html#defined-mutation-semantics-for-locals>,
   which allows debuggers to operate more consistently.
   - The (cyclic) garbage collector is now incremental
   
<https://docs.python.org/3.13/whatsnew/3.13.html#incremental-garbage-collection>,
   which should mean shorter pauses for collection in programs with a lot of
   objects.
   - A modified version of mimalloc <https://github.com/microsoft/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
   <https://docs.python.org/3.13/whatsnew/3.13.html#other-language-changes>,
   reducing memory use and the size of .pyc files. (Most tools handling
   docstrings already strip leading indentation.)
   - The dbm module <https://docs.python.org/3.13/library/dbm.html> has a
   new dbm.sqlite3 backend
   <https://docs.python.org/3.13/whatsnew/3.13.html#dbm> 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
   <https://peps.python.org/pep-0011/#tier-2>. Emscripten is no longer
an officially
   supported platform
   <https://peps.python.org/pep-0011/#no-longer-supported-platforms> (but
   Pyodide <https://pyodide.org> continues to support Emscripten).

<https://discuss.python.org/t/python-3-13-0b4-now-available/58565#typing-3>
Typing

   - Support for type defaults in type parameters
   <https://peps.python.org/pep-0696/>.
   - A new type narrowing annotation <https://peps.python.org/pep-0742/>,
   typing.TypeIs.
   - A new annotation for read-only items in TypeDicts
   <https://peps.python.org/pep-0705/>.
   - A new annotation for marking deprecations in the type system
   <https://peps.python.org/pep-0702>.

<https://discuss.python.org/t/python-3-13-0b4-now-available/58565#removals-and-new-deprecations-4>Removals
and new deprecations

   - PEP 594 (Removing dead batteries from the standard library)
   <https://peps.python.org/pep-0594/> scheduled removals of many
   deprecated modul

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

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

  

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

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 pr

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 <https://gitlab.com/ldo/nixcrypt>.

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


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*™ <https://www.egenix.com/company/legal/trademarks.html> 
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 
<https://www.egenix.com/products/python/mxODBCConnect/> 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* 
<https://github.com/eGenix/egenix-pyrun>, 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 
<https://www.egenix.com/products/python/PyRun/>




*NEWS*

This major release of eGenix PyRun 
<https://www.egenix.com/products/python/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 
<https://www.egenix.com/products/python/PyRun/changelog.html>*.



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 <https://github.com/python/cpython/issues> 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.
<https://discuss.python.org/t/python-3-13-0-beta-3-now-available/56847#major-new-features-of-the-313-series-compared-to-312-1>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:
<https://discuss.python.org/t/python-3-13-0-beta-3-now-available/56847#new-features-2>New
features

   - A new and improved interactive interpreter
   
<https://docs.python.org/3.13/whatsnew/3.13.html#a-better-interactive-interpreter>,
   based on PyPy <https://pypy.org>’s, featuring multi-line editing and
   color support, as well as colorized exception tracebacks
   <https://docs.python.org/3.13/whatsnew/3.13.html#improved-error-messages>
   .
   - An *experimental* free-threaded build mode
   <https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython>,
   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
   <https://docs.python.org/3.13/whatsnew/3.13.html#experimental-jit-compiler>,
   providing the ground work for significant performance improvements.
   - The (cyclic) garbage collector is now incremental
   
<https://docs.python.org/3.13/whatsnew/3.13.html#incremental-garbage-collection>,
   which should mean shorter pauses for collection in programs with a lot of
   objects.
   - A modified version of mimalloc <https://github.com/microsoft/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
   <https://docs.python.org/3.13/whatsnew/3.13.html#other-language-changes>,
   reducing memory use and the size of .pyc files. (Most tools handling
   docstrings already strip leading indentation.)
   - The dbm module <https://docs.python.org/3.13/library/dbm.html> has a
   new dbm.sqlite3 backend
   <https://docs.python.org/3.13/whatsnew/3.13.html#dbm> 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.

<https://discuss.python.org/t/python-3-13-0-beta-3-now-available/56847#typing-3>
Typing

   - Support for type defaults in type parameters
   <https://peps.python.org/pep-0696/>.
   - A new type narrowing annotation <https://peps.python.org/pep-0742/>,
   typing.TypeIs.
   - A new annotation for read-only items in TypeDicts
   <https://peps.python.org/pep-0705/>.

<https://discuss.python.org/t/python-3-13-0-beta-3-now-available/56847#removals-and-new-deprecations-4>Removals
and new deprecations

   - PEP 594 (Removing dead batteries from the standard library)
   <https://peps.python.org/pep-0594/> 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
   <https://docs.python.org/3.13/whatsnew/3.13.html#removed> of deprecated
   classes, functions and methods in various standard library modules.
   - C API removals <https://docs.python.org/3.13/whatsnew/3.13.html#id10>
   and deprecations <https://docs.python.org/3.13/whatsnew/3.13.html#id9>.
   (Some removals present in alpha 1 were reverted in alpha 2, as the removals
   were deemed too disruptive at this time.)
   - New deprecations
   <https://docs.python.org/3.13/whatsnew/3

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:

  <https://gmane.io/>

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 

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 al

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


Re: Decoding bytes to text strings in Python 2

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

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

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

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

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

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

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

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

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


Re: Anonymous email users

2024-06-23 Thread Sebastian Wells via Python-list
On Fri, 14 Jun 2024 18:00:37 -0400, avi.e.gross wrote:

> I notice that in some recent discussions, we have users who cannot be
> replied to directly as their email addresses are not valid ones, and I
> believe on purpose. Examples in the thread I was going to reply to are:
>  
>  <mailto:henha...@devnull.tb> henha...@devnull.tb
>  
>  <mailto:no.email@nospam.invalid> no.email@nospam.invalid
>  
>  <mailto:candycanearter07@candycanearter07.nomail.afraid>
> candycanearter07@candycanearter07.nomail.afraid (user  is
> generated from /dev/urandom)
>  
> I know some here suggest that we only reply to the wider community and
> they have a point. But I think there is a role for having some
> conversations offline and especially when they are not likely to be
> wanted, or even tolerated, by many in the community.
>  
> Using such fake or invalid emails makes it hard to answer the person
> directly or perhaps politely ask them for more info on their request or
> discuss unrelated common interests. Worse, when I reply, unless I use
> reply-all, my mailer sends to them futilely. When I do the reply-all, I
> have to edit out their name or get a rejection.
>  

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.

With e-mail addresses being phone-validated, it's not easy to create
a new one either. And even if I did, you can't even trust e-mail 
providers not to give your address out to spammers.

The only function e-mail addresses serve now is to positively identify
the sender of a Usenet posting so he can be targeted for harassment,
lawsuits, or worse.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread Rayner Lucas via Python-list
In article , r...@zedat.fu-
berlin.de says...
> 
>   I didn't really do a super thorough deep dive on this,
>   but I'm just giving the initial impression without 
>   actually being familiar with Tkinter under Python 2,
>   so I might be wrong!
> 
>   The Text widget typically expects text in Tcl encoding,
>   which is usually UTF-8. 
> 
>   This is independent of the result returned by sys.get-
>   defaultencoding()! 
> 
>   If a UTF-8 string is inserted directly as a bytes object,
>   its code points will be displayed correctly by the Text 
>   widget as long as they are in the BMP (Basic Multilingual
>   Plane), as you already found out yourself.

Many thanks, you've helped me greatly in understanding what's happening. 
When I tried running my example code on a different system (Python 
2.7.18 on Linux, with Tcl/Tk 8.5), I got the error:

_tkinter.TclError: character U+1f40d is above the range (U+-U+) 
allowed by Tcl

So, as your reply suggests, the problem is ultimately a limitation of 
Tcl/Tk itself. Perhaps I should have spent more time studying the docs 
for that instead of puzzling over the details of character encodings in 
Python! I'm not sure why it doesn't give the same error on Windows, but 
at least now I know where the root of the issue is.

I am now much better informed about how to migrate the code I'm working 
on, so I am very grateful for your help.

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


Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread Rayner Lucas via Python-list
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. I'm still not sure why it doesn't give an error on Windows and 
instead either works (when UTF-8 encoding is specified) or converts the 
out-of-range characters to ones it can display (when the encoding isn't 
specified). But now I know what the root of the problem is, I can deal 
with it appropriately (and my curiosity is at least partly satisfied).

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

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


How to go about a simple object grabbing in python (given coordinates of arms and objects)

2024-06-23 Thread marc nicole via Python-list
Hello to all of this magnificent community!

I have this problem I had already spent a few days on and still can't
figure out a proper solution.

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:

tracker_service= session.service("ALTracker")
xyz_pos = tracker_service.getTargetPosition(motion.FRAME_TORSO)


src:
http://doc.aldebaran.com/2-8/naoqi/motion/control-cartesian.html#motion-cartesian-effectors


Then I get to move the right arm towards nearby the object using the
following code:

effector = "RArm"

frame = motion.FRAME_TORSO
effector_offset =
almath.Transform(self.motion.getTransform(effector, frame, False))
effector_init_3d_position = almath.position3DFromTransform(
effector_offset)

target_3d_position = almath.Position3D(target_position)
move_3d = target_3d_position - effector_init_3d_position
moveTransform = almath.Transform.fromPosition(move_3d.x,
move_3d.y, move_3d.z)
target_transformer_list = list(moveTransform.toVector())
times = [2.0]
axis_mask_list = motion.AXIS_MASK_VEL
self.motion.transformInterpolations(effector, frame,
target_transformer_list, axis_mask_list, times).

src: 
http://doc.aldebaran.com/1-14/dev/python/examples/almath/index.html?highlight=offset
This question is specific to NAO environment but in general how to go
about this task? what is a most common algorithm used in this case? Do
I have to also get the side of the object in order to know where
exactly the arms should be placed?
-- 
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-22 Thread marc nicole via Python-list
My code is just an attempt at the task, it is not exact as what relates to
the coordinates (e.g., doesn't account for the size of the object. I would
like to have a idea on the general approach to such problems (even a pseudo
code would do)

"Get the hands rapidly enough in the vicinity and then do some fine
coordinated motions to capture the object and then presumably move it."
seems to be a good approach indeed,
The grabbing with both hands code should be more precise.

Thanks for the help anyways!

Le sam. 22 juin 2024 à 23:04, ThreeBlindQuarks 
a écrit :

> Marc,
>
> Could you specify what is wrong with what you are doing? you show us code
> that uses an environment you point to that is largely outside of basic
> Python.
>
> There is no one way to get from point A to point B and various constraints
> you have not mentioned can apply. How many joints does the assemblage have
> and what are the limits and costs associated with each. Cam there be
> barriers along a route, including to the side where they may brush part of
> your equipment. Are other things moving (independently even) that may end
> up blocking.
>
> You seem to need both "hands" and presumably at the same time. So
> solutions can take that into account. You need to define what is meant by
> contacting the object to move and you don't want to approach it and hit
> with some speed.
>
> So, the problem may be in parts. Get the hands rapidly enough in the
> vicinity and then do some fine coordinated motions to capture the object
> and then presumably move it.
>
> If you could point to what code is not doing what is expected, someone who
> knows the details or is willing to learn, might help, If you want an
> overall algorithm, there may be some people could share but they may not
> easily translate into the package of sorts you are using.
>
> But the web site you point us to may well already contain examples of
> doing some aspects that you might learn from.
>
> For me, this is too detailed to focus on as I struggle to figure out how
> to move my hands to different parts of my keyboard while looking ...
>
> And that may be one variant of an algorithm where instead of trying to
> move all the way, you move art-way and LOOK where you are, then repeat.
>
>
> Sent with Proton Mail secure email.
>
> On Saturday, June 22nd, 2024 at 8:41 AM, marc nicole 
> wrote:
>
> > Hello to all of this magnificent community!
> >
> > I have this problem I had already spent a few days on and still can't
> > figure out a proper solution.
> >
> > 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:
> >
> > tracker_service= session.service("ALTracker")
> > xyz_pos = tracker_service.getTargetPosition(motion.FRAME_TORSO)
> >
> >
> > src:
> >
> http://doc.aldebaran.com/2-8/naoqi/motion/control-cartesian.html#motion-cartesian-effectors
> >
> >
> > Then I get to move the right arm towards nearby the object using the
> > following code:
> >
> > effector = "RArm"
> >
> > frame = motion.FRAME_TORSO
> > effector_offset =
> > almath.Transform(self.motion.getTransform(effector, frame, False))
> > effector_init_3d_position = almath.position3DFromTransform(
> > effector_offset)
> >
> > target_3d_position = almath.Position3D(target_position)
> > move_3d = target_3d_position - effector_init_3d_position
> > moveTransform = almath.Transform.fromPosition(move_3d.x,
> > move_3d.y, move_3d.z)
> > target_transformer_list = list(moveTransform.toVector())
> > times = [2.0]
> > axis_mask_list = motion.AXIS_MASK_VEL
> > self.motion.transformInterpolations(effector, frame,
> > target_transformer_list, axis_mask_list, times).
> >
> > src:
> http://doc.aldebaran.com/1-14/dev/python/examples/almath/index.html?highlight=offset
> > This question is specific to NAO environment but in general how to go
> > about this task? what is a most common algorithm used in this case? Do
> > I have to also get the side of the object in order to know where
> > exactly the arms should be placed?
> > ___
> > 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-21 Thread Chris Angelico via Python-list
On Sat, 22 Jun 2024 at 03:28, Rayner Lucas via Python-list
 wrote:
> I'm curious about something I've encountered while updating a very old
> Tk app (originally written in Python 1, but I've ported it to Python 2
> as a first step towards getting it running on modern systems).
>
> I am using Python 2.7.18 on a Windows 10 system. If there's any other
> relevant information I should provide please let me know.

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

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

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


Decoding bytes to text strings in Python 2

2024-06-21 Thread Rayner Lucas via Python-list


I'm curious about something I've encountered while updating a very old 
Tk app (originally written in Python 1, but I've ported it to Python 2 
as a first step towards getting it running on modern systems). The app 
downloads emails from a POP server and displays them. At the moment, the 
code is completely unaware of character encodings (which is something I 
plan to fix), and I have found that I don't understand what Python is 
doing when no character encoding is specified.

To demonstrate, I have written this short example program that displays 
a variety of UTF-8 characters to check whether they are decoded 
properly:

 Example Code 
import Tkinter as tk

window = tk.Tk()

mytext = """
  \xc3\xa9 LATIN SMALL LETTER E WITH ACUTE
  \xc5\x99 LATIN SMALL LETTER R WITH CARON
  \xc4\xb1 LATIN SMALL LETTER DOTLESS I
  \xef\xac\x84 LATIN SMALL LIGATURE FFL
  \xe2\x84\x9a DOUBLE-STRUCK CAPITAL Q
  \xc2\xbd VULGAR FRACTION ONE HALF
  \xe2\x82\xac EURO SIGN
  \xc2\xa5 YEN SIGN
  \xd0\x96 CYRILLIC CAPITAL LETTER ZHE
  \xea\xb8\x80 HANGUL SYLLABLE GEUL
  \xe0\xa4\x93 DEVANAGARI LETTER O
  \xe5\xad\x97 CJK UNIFIED IDEOGRAPH-5B57
  \xe2\x99\xa9 QUARTER NOTE
  \xf0\x9f\x90\x8d SNAKE
  \xf0\x9f\x92\x96 SPARKLING HEART
"""

mytext = mytext.decode(encoding="utf-8")
greeting = tk.Label(text=mytext)
greeting.pack()

window.mainloop()
 End Example Code 

This works exactly as expected, with all the characters displaying 
correctly.

However, if I comment out the line 'mytext = mytext.decode
(encoding="utf-8")', the program still displays *almost* everything 
correctly. All of the characters appear correctly apart from the two 
four-byte emoji characters at the end, which instead display as four 
characters. For example, the "SNAKE" character actually displays as:
U+00F0 LATIN SMALL LETTER ETH
U+FF9F HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK
U+FF90 HALFWIDTH KATAKANA LETTER MI
U+FF8D HALFWIDTH KATAKANA LETTER HE

What's Python 2 doing here? sys.getdefaultencoding() returns 'ascii', 
but it's clearly not attempting to display the bytes as ASCII (or 
cp1252, or ISO-8859-1). How is it deciding on some sort of almost-but-
not-quite UTF-8 decoding?

I am using Python 2.7.18 on a Windows 10 system. If there's any other 
relevant information I should provide please let me know.

Many thanks,
Rayner
-- 
https://mail.python.org/mailman/listinfo/python-list


glibc strverscmp called from python

2024-06-20 Thread vallor via Python-list
So there's been discussion in comp.lang.c and comp.unix.shell
about doing a "versionsort(3)" type sort on a list
of parameters.  glibc offers strverscmp(3) for this type
of sort, and here I am posting a q python program to expose
that to its sort routine for commentary and future reference.

Caveat:  I know just enough python to be dangerous -- wrote
this using ChatGPT.  It is a learning experience, comments
very much appreciated.

 - -%<- -

#!/usr/bin/python3

import ctypes
from ctypes import c_char_p, c_int
import os
import sys

# Load the C standard library (libc)
libc = ctypes.CDLL("libc.so.6")

# Define the prototype of strverscmp
# int strverscmp (const char *s1, const char *s2)
libc.strverscmp.argtypes = [c_char_p, c_char_p]
libc.strverscmp.restype = c_int

# Define a comparison function for Python sorting
def version_compare(x, y):
return libc.strverscmp(x.encode('utf-8'), y.encode('utf-8'))

# Define a key function for sorting
def version_key(s):
class K:
def __init__(self, s):
self.s = s
def __lt__(self, other):
return version_compare(self.s, other.s) < 0
def __gt__(self, other):
return version_compare(self.s, other.s) > 0
def __eq__(self, other):
return version_compare(self.s, other.s) == 0
def __le__(self, other):
return version_compare(self.s, other.s) <= 0
def __ge__(self, other):
return version_compare(self.s, other.s) >= 0
def __ne__(self, other):
return version_compare(self.s, other.s) != 0
return K(s)

# Function to escape special characters
def shell_escape(s):
return s.replace(" ", "\\ ").replace("\n", "\\n").replace("\t", "\\t")

# Parse command-line arguments
args = sys.argv[1:]

# Sort the list using the version key
sorted_args = sorted(args, key=version_key)

# Print each sorted, escaped value on a new line
for arg in sorted_args:
print(shell_escape(arg))

 - -%<- -

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


Re: Timezone in HH:MM Format

2024-06-18 Thread Ivan "Rambius" Ivanov via Python-list
Thank you all for your responses!

On Tue, Jun 18, 2024 at 9:54 PM Jon Ribbens via Python-list
 wrote:
>
> datetime.now(ZoneInfo("America/New_York")).isoformat()

Both .isoformat() and "%:z" work.


-- 
Tangra Mega Rock: http://www.radiotangra.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Timezone in HH:MM Format

2024-06-18 Thread Jon Ribbens via Python-list
On 2024-06-18, Ivan "Rambius" Ivanov  wrote:
> Hello,
>
> How can I convert a date, usually datetime.now(), into a format where
> the timezone is in hours:minutes format. I was able to get that format
> in shell:
>
> $ date +%Y-%m-%dT%H:%M:%S%:z
> 2024-06-18T19:24:09-04:00
>
> The closest I got in python is
>
> from datetime import datetime
> from zoneinfo import ZoneInfo
>
> s = datetime.strftime(datetime.now(ZoneInfo("America/New_York")),
> "%Y-%m-%dT%H:%M:%S%z")
> print(s)
>
> This prints the same as the shell command above except the last column:
> 2024-06-18T19:28:56-0400
>
> Any help will be appreciated.

datetime.now(ZoneInfo("America/New_York")).isoformat()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Timezone in HH:MM Format

2024-06-18 Thread MRAB via Python-list

On 2024-06-19 00:32, Ivan "Rambius" Ivanov via Python-list wrote:

Hello,

How can I convert a date, usually datetime.now(), into a format where
the timezone is in hours:minutes format. I was able to get that format
in shell:

$ date +%Y-%m-%dT%H:%M:%S%:z
2024-06-18T19:24:09-04:00

The closest I got in python is

from datetime import datetime
from zoneinfo import ZoneInfo

s = datetime.strftime(datetime.now(ZoneInfo("America/New_York")),
"%Y-%m-%dT%H:%M:%S%z")
print(s)

This prints the same as the shell command above except the last column:
2024-06-18T19:28:56-0400

Starting from Python 3.12, you can use "%:z" in the format string. For 
earlier versions of Python, you need to do some string slicing.

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


Timezone in HH:MM Format

2024-06-18 Thread Ivan "Rambius" Ivanov via Python-list
Hello,

How can I convert a date, usually datetime.now(), into a format where
the timezone is in hours:minutes format. I was able to get that format
in shell:

$ date +%Y-%m-%dT%H:%M:%S%:z
2024-06-18T19:24:09-04:00

The closest I got in python is

from datetime import datetime
from zoneinfo import ZoneInfo

s = datetime.strftime(datetime.now(ZoneInfo("America/New_York")),
"%Y-%m-%dT%H:%M:%S%z")
print(s)

This prints the same as the shell command above except the last column:
2024-06-18T19:28:56-0400

Any help will be appreciated.

Regards
Ivan

-- 
Tangra Mega Rock: http://www.radiotangra.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: in Python: (101 102 103 201 202 203 301 302 303 401 402 403 )

2024-06-18 Thread Peter J. Holzer via Python-list
On 2024-06-14 06:10:06 -, candycanearter07 via Python-list wrote:
> Phil Carmody  wrote at 12:01 this Thursday (GMT):
> > I'd say you can't beat the verbosity, or lack thereof of just plain 
> > zsh/bash:
> >   $ echo {1,2,3,4}0{1,2,3}
> >   101 102 103 201 202 203 301 302 303 401 402 403
> 
> 
> I /think/ you can replace it with {1...4} and {1...3}? I know there is
> some syntax for "range of numbers" but I can't remember it exactly.

Only two dots, not three:

% echo {1..4}0{1..3}
101 102 103 201 202 203 301 302 303 401 402 403

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

2024-06-18 Thread Grant Edwards via Python-list
On 2024-06-18, Mats Wichmann via Python-list  wrote:
> On 6/17/24 17:51, dn via Python-list wrote:
>
>> +1
>> 
>> The "public" part is not to embarrass posters, but recognition that 
>> there are likely other people 'out there' (or arriving in-future if they 
>> care to read the archives) experiencing a similar problem. (hence need 
>> for descriptive Subject lines - isn't the most difficult task in 
>> programming 'choosing names'?)
>
> well, one of two, along with cache invalidation and off-by-one errors 
> (according to the wags).
>
> I do agree with this, but mailman (2) archives aren't particularly 
> useful for searching, as they're organized in monthly chunks and you 
> have to keep clicking around - this list doesn't have a search engine as 
> it's not converted to be one of the mailman 3 lists.

Gmane used to have a usable search feature (along with a decent
threaded web UI to read the arhives), but that got lost during the
great gmane server/domain upheaval of 2016 (or whenever that was). I
still miss it.

--
Grant

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


Re: Anonymous email users

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

On 6/17/24 17:51, dn via Python-list wrote:


+1

The "public" part is not to embarrass posters, but recognition that 
there are likely other people 'out there' (or arriving in-future if they 
care to read the archives) experiencing a similar problem. (hence need 
for descriptive Subject lines - isn't the most difficult task in 
programming 'choosing names'?)


well, one of two, along with cache invalidation and off-by-one errors 
(according to the wags).


I do agree with this, but mailman (2) archives aren't particularly 
useful for searching, as they're organized in monthly chunks and you 
have to keep clicking around - this list doesn't have a search engine as 
it's not converted to be one of the mailman 3 lists.


There are supposed to be some search engine incantations to make this 
better. I find this one works, though I can never actually remember it 
and have to go hunting again each time... picking a random-ish subject 
line from this list in the past:


site:mail.python.org inurl:Python-list multiplication

I don't know that we publicise such methods (there are probably others).

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


Re: win32clipboard writing to clipboard on Windows 11

2024-06-18 Thread Eryk Sun via Python-list
On Tue, Jun 18, 2024 at 2:19 AM Eryk Sun  wrote:
>
>
> def set_clipboard_text(text):
> hMem = global_alloc_text(text)
> try:
> win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT,
> hMem)
> # Now the system owns the global memory.
> except:
> kernel32.GlobalFree(hMem)

Oops, that suppresses the exception. Fixed:

def set_clipboard_text(text):
hMem = global_alloc_from_text(text)
try:
win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT,
hMem)
# Now the system owns the global memory.
except:
kernel32.GlobalFree(hMem)
raise
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: win32clipboard writing to clipboard on Windows 11

2024-06-18 Thread Eryk Sun via Python-list
On Mon, Jun 17, 2024 at 8:36 PM MRAB via Python-list
 wrote:
> On 2024-06-17 20:27, Rob Cliffe via Python-list wrote:
>
> > SetClipboardData(CF_UNICODETEXT, "0")
> > CloseClipboard()

win32clipboard.SetClipboardData() first tries to covert the second
argument as an integer handle to global memory, which gets passed to
WinAPI SetClipboardData(). The integer conversion is basically via
int(). With int("0"), it's passing a NULL handle value, which
instructs the window manager to query the data from the window that
was associated via OpenClipboard(), if any. Since no memory handle is
passed in this case, SetClipboardData() returns NULL.
win32clipboard.SetClipboardData() misinterprets this as failure and
raises an exception for whatever random error code is currently set in
the thread's last error value. On the other hand, for a numeric text
string with a nonzero value, such as "123",
win32clipboard.SetClipboardData() will raise an exception for the
error code ERROR_INVALID_HANDLE (6), unless the integer value happens
to be a valid global memory handle value.

I recommend just using win32clipboard.SetClipboardText(). Otherwise I
don't see an easy workaround given the peculiar design of
win32clipboard.SetClipboardData(). You'd have to manually allocate a
block of global memory, copy the numeric text string into it, and pass
the global memory handle to win32clipboard.SetClipboardData(). For
example:

import ctypes
import win32clipboard
from ctypes import wintypes

kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)

GMEM_MOVEABLE = 0x0002

kernel32.GlobalAlloc.restype = wintypes.HGLOBAL
kernel32.GlobalFree.argtypes = (wintypes.HGLOBAL,)
kernel32.GlobalLock.restype = wintypes.LPVOID
kernel32.GlobalLock.argtypes = (wintypes.HGLOBAL,)
kernel32.GlobalUnlock.argtypes = (wintypes.HGLOBAL,)

def global_alloc_text(text):
array_t = ctypes.c_wchar * (len(text) + 1)
hMem = kernel32.GlobalAlloc(GMEM_MOVEABLE, ctypes.sizeof(array_t))
if not hMem:
raise ctypes.WinError(ctypes.get_last_error())
pMem = kernel32.GlobalLock(hMem)
try:
try:
array_t.from_address(pMem).value = text
finally:
kernel32.GlobalUnlock(hMem)
except:
kernel32.GlobalFree(hMem)
raise
return hMem

def set_clipboard_text(text):
hMem = global_alloc_text(text)
try:
win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT,
hMem)
# Now the system owns the global memory.
except:
kernel32.GlobalFree(hMem)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: win32clipboard writing to clipboard on Windows 11

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

On 6/17/2024 9:30 PM, MRAB via Python-list wrote:

On 2024-06-17 20:27, Rob Cliffe via Python-list wrote:

Recently I acquired a new laptop running WIndows 11; my previous one
uses WIndows 10.  I encountered a strange problem:
I am using the win32clipboard backage (part of pywin32), and when I use
SetClipboardData() to write text which consists ***entirely of digits***
to the clipboard, I either get an error (not always the same error
message) or a program crash.  The problem does not appear if I use
SetClipboardText() instead.  The problem does not occur on my old
machine (where I used the feature extensively).

Sample program:

from win32clipboard import *
OpenClipboard()
SetClipboardData(CF_UNICODETEXT, "A")
SetClipboardData(CF_UNICODETEXT, "A0")
SetClipboardData(CF_UNICODETEXT, "0A")
SetClipboardText("0", CF_UNICODETEXT)
print("OK so far")
SetClipboardData(CF_UNICODETEXT, "0")
CloseClipboard()

Sample output:

OK so far
Traceback (most recent call last):
    File "C:\TEST*.PY", line 8, in 
      SetClipboardData(CF_UNICODETEXT, "0")
pywintypes.error: (0, 'SetClipboardData', 'No error message is 
available')


Can anyone shed light on this?
Best wishes
Rob Cliffe


I tried it on Windows 10 and got this:

 >>> from win32clipboard import *
 >>> OpenClipboard()
 >>> SetClipboardData(CF_UNICODETEXT, "A")
1830508101640
 >>> CloseClipboard()
 >>> OpenClipboard()
 >>> SetClipboardData(CF_UNICODETEXT, "0")
Traceback (most recent call last):
   File "", line 1, in 
pywintypes.error: (6, 'SetClipboardData', 'The handle is invalid.')
 >>> CloseClipboard()

It looks like it's something to memory ownership:

https://stackoverflow.com/questions/1264137/how-to-copy-string-to-clipboard-in-c

If you're putting text on the clipboard, why not just use 
SetClipboardText()? That's what I do.


If you can make a change, and you only need to work with text on the 
clipboard, you could change to use pyperclip.  It also works on Linux, 
if you might care about that in the future.  It's available as a pip 
install. It's easier to use than the win32 approach.

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


Re: win32clipboard writing to clipboard on Windows 11

2024-06-17 Thread MRAB via Python-list

On 2024-06-17 20:27, Rob Cliffe via Python-list wrote:

Recently I acquired a new laptop running WIndows 11; my previous one
uses WIndows 10.  I encountered a strange problem:
I am using the win32clipboard backage (part of pywin32), and when I use
SetClipboardData() to write text which consists ***entirely of digits***
to the clipboard, I either get an error (not always the same error
message) or a program crash.  The problem does not appear if I use
SetClipboardText() instead.  The problem does not occur on my old
machine (where I used the feature extensively).

Sample program:

from win32clipboard import *
OpenClipboard()
SetClipboardData(CF_UNICODETEXT, "A")
SetClipboardData(CF_UNICODETEXT, "A0")
SetClipboardData(CF_UNICODETEXT, "0A")
SetClipboardText("0", CF_UNICODETEXT)
print("OK so far")
SetClipboardData(CF_UNICODETEXT, "0")
CloseClipboard()

Sample output:

OK so far
Traceback (most recent call last):
    File "C:\TEST*.PY", line 8, in 
      SetClipboardData(CF_UNICODETEXT, "0")
pywintypes.error: (0, 'SetClipboardData', 'No error message is available')

Can anyone shed light on this?
Best wishes
Rob Cliffe


I tried it on Windows 10 and got this:

>>> from win32clipboard import *
>>> OpenClipboard()
>>> SetClipboardData(CF_UNICODETEXT, "A")
1830508101640
>>> CloseClipboard()
>>> OpenClipboard()
>>> SetClipboardData(CF_UNICODETEXT, "0")
Traceback (most recent call last):
  File "", line 1, in 
pywintypes.error: (6, 'SetClipboardData', 'The handle is invalid.')
>>> CloseClipboard()

It looks like it's something to memory ownership:

https://stackoverflow.com/questions/1264137/how-to-copy-string-to-clipboard-in-c

If you're putting text on the clipboard, why not just use 
SetClipboardText()? That's what I do.

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


Re: Anonymous email users

2024-06-17 Thread dn via Python-list

On 18/06/24 05:29, Roel Schroeven via Python-list wrote:

AVI GROSS via Python-list schreef op 17/06/2024 om 17:03:
I simply am thinking that people who do not allow me to easily reply 
to them

directly, should be ignored by me and not get my cooperation that way.
FWIW, personally I (mostly) don't see the point of replying to people 
personally. To me a public mailing list is much like any public forum, 
where my expectation is that conversations happen in public. To me it 
always feels weird when I get a personal reply when I make a public post 
in a mailing list. I mostly ignore those, unless there's really 
something in it that's best kept out of the public. Sometimes people 
write long mails with wandering thoughts only loosely related to the 
topic at hand directly to me instead of to the whole list. My take is: 
if it's not on-topic enough for the list, it's not on-topic enough for 
me either. Not that it bothers me *that* much; I just ignore those. It's 
very well possible that's just me, and that other people have different 
expectations.


+1

The "public" part is not to embarrass posters, but recognition that 
there are likely other people 'out there' (or arriving in-future if they 
care to read the archives) experiencing a similar problem. (hence need 
for descriptive Subject lines - isn't the most difficult task in 
programming 'choosing names'?)


Yes, like @Avi, I have been known to contact folk directly. However, 
such for personal purposes - as distinct from the list, and possibly 
subjects OT for the list.


When contacted by others off-list, I play it by ear - ignore, personal, 
or post response on-list. (some lists/email-clients do seem to prefer 
personal replies, even when incoming message is from a list - so easy 
accident.)


The Delete-key is your friend!

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


  1   2   3   4   5   6   7   8   9   10   >