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


RE: Anonymous email users

2024-06-17 Thread AVI GROSS via Python-list


It seems clear we have people on mailing lists that see it as a purely
public forum, and that is fine for them.

I have found plenty of times I choose not to continue in public and waste
time for people as in this reply on a topic I raised and now will move away
from.

I have in the past, for example, offered to help people and participate in
aspects of their project that do not need to be viewed here, such as helping
them find out how to adjust their graphical output to better fit their
needs. Or, if someone mentions me negatively, I prefer not always replying
in public to perhaps see if I misunderstood something or was misunderstood. 

I have lots of people I "met" in places like this that I keep in touch with
privately and see that as a plus. For those who just want a business-like
experience, no problem. For those who choose levels of anonymity or don't
like being contacted, again, fine for them.

The reality is that I have found people who show up in forums looking almost
legit but actually are not at all who they appear or claim to be even when
they have valid email addresses like mrsp...@gmail.com or even use names of
real people you can search for on the internet but who are not actually the
ones they may even claim.

My message was not to say what people could not do, but to point out they
may be missing out on what some see as collateral opportunities. The people
I have helped privately would not have received it had they only
participated through the group and I would not have received some chances to
learn if I could not ask questions in private that clearly did not fit the
purpose of the group.

So, I am outa this conversation IN PUBLIC. LOL!

-Original Message-
From: Python-list  On
Behalf Of Grant Edwards via Python-list
Sent: Monday, June 17, 2024 5:08 PM
To: python-list@python.org
Subject: Re: Anonymous email users

On 2024-06-17, Roel Schroeven via Python-list 
wrote:

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

My sentiments exactly. I generally don't even read replies that get
mailed to me. They almost always seem to be copies of replies that
were also posted to the mailing list (which I read using an NNTP
client pointed at news.gmane.io).

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

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


Re: Anonymous email users

2024-06-17 Thread Grant Edwards via Python-list
On 2024-06-17, Roel Schroeven via Python-list  wrote:

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

My sentiments exactly. I generally don't even read replies that get
mailed to me. They almost always seem to be copies of replies that
were also posted to the mailing list (which I read using an NNTP
client pointed at news.gmane.io).

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


win32clipboard writing to clipboard on Windows 11

2024-06-17 Thread Rob Cliffe via Python-list
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
--
https://mail.python.org/mailman/listinfo/python-list


Re: Anonymous email users

2024-06-17 Thread Roel Schroeven via Python-list

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.


But I don't go hiding my email address, that's a whole different kettle.

--
"Let everything happen to you
Beauty and terror
Just keep going
No feeling is final"
-- Rainer Maria Rilke

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


RE: Anonymous email users

2024-06-17 Thread AVI GROSS via Python-list
Thanks, Marco, for explaining.

I, personally, have no interest in finding out who people are in this case.
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.

I do understand reasons people use fake ID but note others have put their
email address in their signature, perhaps slightly disguised as in:

Myname=ereweon.com

Or 

myn...@unspecified.tb s/unspecified.tb/yahoo.com/

It may be the gateway or other records can find them if they are nasty, but
for now, it is just an observation that it seems the discussions with people
in the email list are more useful to me.

-Original Message-
From: Python-list  On
Behalf Of Marco Moock via Python-list
Sent: Saturday, June 15, 2024 2:03 AM
To: python-list@python.org
Subject: Re: Anonymous email users

On 15.06.2024 um 10:30 Uhr dn wrote:

> These mailing-lists all run under the Python Code of Conduct.
> 
> This also effects a conundrum. Firstly, that someone abusing others
> (for example) shall be held responsible. Secondly, that in order to
> hold someone responsible, he/she/... must be identifiable.

The mailing list has a Usenet gateway

Those users use the Usenet to post.
Check the Injection-Info header for the address of the news server
operator. He can identify the account that posted it.

-- 
kind regards
Marco

Send spam to 1718440236mu...@cartoonies.org

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

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


Re: Anonymous email users

2024-06-17 Thread Marco Moock via Python-list
On 15.06.2024 um 10:30 Uhr dn wrote:

> These mailing-lists all run under the Python Code of Conduct.
> 
> This also effects a conundrum. Firstly, that someone abusing others
> (for example) shall be held responsible. Secondly, that in order to
> hold someone responsible, he/she/... must be identifiable.

The mailing list has a Usenet gateway

Those users use the Usenet to post.
Check the Injection-Info header for the address of the news server
operator. He can identify the account that posted it.

-- 
kind regards
Marco

Send spam to 1718440236mu...@cartoonies.org

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


Re: Suggested python feature: allowing except in context maneger

2024-06-17 Thread j via Python-list


On 2024-06-13 23:49, Cameron Simpson via Python-list wrote:
On 13Jun2024 19:44, dieter.mau...@online.de  
wrote:

Why not use:
```
try:
 with open()...
   ...
except FileNotFoundError:
 ...
```


This is exactly what the OP was expressing dissatisfaction with.

I'm -1 on the idea myself - not every combination of things needs 
additional syntactic support, and doing stuff like merging an `except` 
with a `wtih` is bound to introduce some weird corner case, 
complicating its semantics.


I agree. If python allowed statement lambdas you could write what you 
want above within the language (albeit a bit clumsily). It's very handy.


jan



Cheers,
Cameron Simpson 

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


Re: Suggested python feature: allowing except in context maneger

2024-06-16 Thread Albert-Jan Roskam via Python-list
 The example exception is not what bothers me. The syntax change is
 nowhere near as useful as `with` and context managers. They provide an
 excellent idiom for resource usage and release.

 Your suggestion complicates the `with` statement and brings only a tiny
 indentation reduction over the `with`-inside-`try` idiom. It brings no
 semantic changes or new features.

   
   I also don't see the added value. If you desperately want to get rid of an
   indentation level, you could use an except
   hook. https://docs.python.org/3/library/sys.html#sys.excepthook
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggested python feature: allowing except in context maneger

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

On 14Jun2024 09:07, Yair Eshel  wrote:

Cameron, I'm not really sure I got your point. I've used the "file not
found" exception as an example for a behavior typical on context managers.
This could be a failure to connect to DB, or threads. It also applies to
any kind of possible exception, whether cased by the context manager itself
or the lines inside it. Long story short, this syntax change is as useful
as context managers are


The example exception is not what bothers me. The syntax change is 
nowhere near as useful as `with` and context managers. They provide an 
excellent idiom for resource usage and release.


Your suggestion complicates the `with` statement and brings only a tiny 
indentation reduction over the `with`-inside-`try` idiom. It brings no 
semantic changes or new features.


That is why I'm -1: the benefit is triviailly small to my eye.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Anonymous email users

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

On 14Jun2024 18:00, avi.e.gr...@gmail.com  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:

 henha...@devnull.tb

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


I often reply-all (meaning to the list and to the author). And edit the 
headers (frankly, often just to discard anything @gmail.com which has 
very stupid spam poolicies).  If I miss an @invalid.com or whatever, 
then whoops.


If I want to reply directly (eg for some kind of feedback rather than a 
list type reply) and they've got a bogus address, well then I don't.  
Supposedly my reply would be of benefit for them or I shouldn't be doing 
it, so their loss. But equally, if they don't want personal off-list 
contact, they've expressed their preference. I should respect that.


Plenty of people have reasons to post anonymously, even to a list like 
this one. Just assume they've got their reasons and move on.

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


Re: Anonymous email users

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

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

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


Re: Anonymous email users

2024-06-14 Thread dn via Python-list

On 15/06/24 10:00, AVI GROSS via Python-list 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:

...

It's an interesting conundrum. There are good reasons and nefarious, for 
such behavior.


Some have questioned my behavior in similar regard - asking why I use 
initials (also used IRL). It is because my first name "David" is/was 
very popular. At a meeting this week there were three of us. Thus, 
"David", "Dave", and "dn" was necessary to distinguish between us.



These mailing-lists all run under the Python Code of Conduct.

This also effects a conundrum. Firstly, that someone abusing others (for 
example) shall be held responsible. Secondly, that in order to hold 
someone responsible, he/she/... must be identifiable.



Personal opinion: if someone is asked a 
question/clarification/sample-code, particularly as a response to their 
own OP, and does not answer; this is at the least rude, and thus 
disrespectful, or at worst grounds for not bothering with them again - 
hardly a 'community' attitude!


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


Anonymous email users

2024-06-14 Thread AVI GROSS via Python-list
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:
 
  henha...@devnull.tb
 
  no.email@nospam.invalid
 
 
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.
 
I understand some are concerned over getting email of the junk variety by
any who scan members of forums like this. I can see making a throwaway email
address for such purposes that can be replaced when it gets inundated. But
emails that don't work are a bit irksome to me albeit I assume perfectly
legit for many purposes.
 
The thread I posted in recently is an example where I spent a little time,
just for fun, and wrote a fairly short piece of code (almost a one-liner)
that I might have sent to the OP and not bothered others here with. I
suspect few here understand why there was a request to generate a limited
subset of three-digit numbers. I did suggest an outline of a way it could be
done, perhaps a bit wastefully but compactly. But there is no way to share
that with people who choose not to receive private email except to post
something like this here:
 
import re
[i for i in range(999) if re.match("^[1-4]0[1-3]$",str(i))]
 
*   The internet is a wild place and when it is anonymous, even wilder.
 
-- 
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-14 Thread candycanearter07 via Python-list
Phil Carmody  wrote at 12:01 this Thursday (GMT):
> Paul Rubin  writes:
>> HenHanna  writes:
>>> is there another (simple) way to write this?
>>
>> Yes, but please consider doing these easy exercises yourself instead of
>> fobbing them onto other people.
>
> Hen's probably just an experimental GPT. You, with your limited
> resources, can never train it.
>
> 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
>
> Phil


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.
-- 
user  is generated from /dev/urandom
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggested python feature: allowing except in context maneger

2024-06-14 Thread Yair Eshel via Python-list
Cameron, I'm not really sure I got your point. I've used the "file not
found" exception as an example for a behavior typical on context managers.
This could be a failure to connect to DB, or threads. It also applies to
any kind of possible exception, whether cased by the context manager itself
or the lines inside it. Long story short, this syntax change is as useful
as context managers are

On Fri, 14 Jun 2024, 01:49 Cameron Simpson,  wrote:

> On 13Jun2024 19:44, dieter.mau...@online.de 
> wrote:
> >Why not use:
> >```
> >try:
> >  with open()...
> >...
> >except FileNotFoundError:
> >  ...
> >```
>
> This is exactly what the OP was expressing dissatisfaction with.
>
> I'm -1 on the idea myself - not every combination of things needs
> additional syntactic support, and doing stuff like merging an `except`
> with a `wtih` is bound to introduce some weird corner case, complicating
> its semantics.
>
> Cheers,
> Cameron Simpson 
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggested python feature: allowing except in context maneger

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

On 13Jun2024 19:44, dieter.mau...@online.de  wrote:

Why not use:
```
try:
 with open()...
   ...
except FileNotFoundError:
 ...
```


This is exactly what the OP was expressing dissatisfaction with.

I'm -1 on the idea myself - not every combination of things needs 
additional syntactic support, and doing stuff like merging an `except` 
with a `wtih` is bound to introduce some weird corner case, complicating 
its semantics.


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


Suggested python feature: allowing except in context maneger

2024-06-13 Thread Dieter Maurer via Python-list
Yair Eshel wrote at 2024-6-13 13:01 +0300:
> ...
>I would like to suggest an alternative syntax, that will, in a sense, apply
>the best of both worlds:
>
>import logging
>with open('sample_data/README.md') as f:
>  print (len(f.read()))
>except FileNotFoundError:
>  logging.error("File not")

Are you aware that in the case of a `FileNotFoundError`
no context manager is created (the context manager is the `f`
in your code).

Why not use:
try:
  with open()...
...
except FileNotFoundError:
  ...


I do not think that your use case requires a `with` extension.



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


Re: Couldn't install numpy on Python 2.7

2024-06-13 Thread Ethan Furman via Python-list

Hey, everyone!

I believe the original question has been answered, and tempers seem to be flaring in sub-threads, so let's call this 
thread done and move on to other interesting topics.


Thank you for your support!

--
~Ethan~
Moderator
--
https://mail.python.org/mailman/listinfo/python-list


Re: Suggested python feature: allowing except in context maneger

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



> On 13 Jun 2024, at 11:01, Yair Eshel via Python-list  
> wrote:
> 
> I read this is a good place to give some suggestions for features in
> python.

Best place these days is to raise an idea on https://discuss.python.org/

Beware that this idea has come up in the past and was rejected.

Barry

-- 
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-13 Thread Phil Carmody via Python-list
Paul Rubin  writes:
> HenHanna  writes:
>> is there another (simple) way to write this?
>
> Yes, but please consider doing these easy exercises yourself instead of
> fobbing them onto other people.

Hen's probably just an experimental GPT. You, with your limited
resources, can never train it.

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

Phil
-- 
We are no longer hunters and nomads. No longer awed and frightened, as we have
gained some understanding of the world in which we live. As such, we can cast
aside childish remnants from the dawn of our civilization.
-- NotSanguine on SoylentNews, after Eugen Weber in /The Western Tradition/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Couldn't install numpy on Python 2.7

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

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

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


Suggested python feature: allowing except in context maneger

2024-06-13 Thread Yair Eshel via Python-list
Hello. I read this is a good place to give some suggestions for features in
python. If not, please let me know.

This is an example of a code I normally use in my everyday work:
import logging
try:
  with open('sample_data/READM.md') as f:
print (len(f.read()))
except FileNotFoundError:
  logging.error("File not found")


As you can see I have 2 levels of indentation, which can add some pain to
the work with the context manager. This code without context manager, can
be replaced by this code:

import logging
try:
  f = open('sample_data/READM.md') as f:
  print (len(f.read()))
except FileNotFoundError:
  logging.error("File not found")
finally:
  f.close()

And while this offers less indentations, it skips the usage of the very
handy context manager.

I would like to suggest an alternative syntax, that will, in a sense, apply
the best of both worlds:

import logging
with open('sample_data/README.md') as f:
  print (len(f.read()))
except FileNotFoundError:
  logging.error("File not")

As "with" applies the behavior of the "try / finally" it feels like a
natural part of this syntax. This could provide a cleaner code.
If this idea is accepted, there are several things that need to be
discussed, like what to do with "else" or "finally" statement following a
context manager. I'm not sure about the proper way to handle this.

With hopes for an even more readable future
Yair
-- 
בברכה,
יאיר אשל כהנסקי
מתכנת וטכנאי מילים
https://www.inspect-element.net/YouAreHere/#/start
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Couldn't install numpy on Python 2.7

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

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

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

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

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

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

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


RE: Couldn't install numpy on Python 2.7

2024-06-12 Thread AVI GROSS via Python-list
Chris,

You seem to have perceived an insult that I remain unaware of.

I have no special knowledge, like you do, of plans made for changes to the
pthon language and implementation.

I was asking a hypothetical question about what some users would do if
python came out with a newer major version. I have seen people often wait
until some software that tries to get updated too frequently makes multiple
updates and then finally give in and skip the intermediates.

I wondered if something like a version 4.0 might get people still using
version 2 might finally come around and also if some version 3 users would
not be thrilled with something not stable enough.

I have no favorite ideas here and can see a balance between adding features
or fixing flaws and on the other side, not discomfiting many and especially
when in many cases, the original people who wrote software are no longer
there nor budgets to pay for changes.

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

Either way, I am taking any further discussion along these lines offline and
will not continue here.

-Original Message-
From: Python-list  On
Behalf Of Chris Angelico via Python-list
Sent: Wednesday, June 12, 2024 7:23 PM
To: python-list@python.org
Subject: Re: Couldn't install numpy on Python 2.7

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

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

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

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

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


Re: Couldn't install numpy on Python 2.7

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

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

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

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


RE: Couldn't install numpy on Python 2.7

2024-06-12 Thread AVI GROSS via Python-list
Chris,

I don't want to get off message and debate whether my "jokes" are jokes, let
alone funny. Obviously, they often aren't.

What I meant by joking here does seem relevant. As the years pass, there can
come a time when it is suggested that a language (any language including
python) is no longer useful to many in the community as it has not kept up
with changes in the industry or whatever. Suggestions are made for changes
and additions that that not be backward compatible. They can be somewhat
minor things like new keywords that have not been reserved and where
programs that exist might be scanned for use of that keyword, and you simply
replace those names with was_keyword or something and the programs will
generally  run.  But there can be major changes too and there can be a
choice to just create a new language that has some similarities to python 3
(or PERL version whatever) or just name it the same but a version higher
much like has happened.

My point was that version 4 COULD HAPPEN one day and I meant INCOMPATIBLE
version not 4. Obviously we can make a version 4 that is not incompatible
too.

I have experience in other languages where disconnects happen at various
levels. Some functions in a collection such as a package are removed perhaps
to replace them with a more abstract version that does much more. Do you
remove the old one immediately or do you make a new name for the new one and
perhaps in some way mark the old one for deprecation with a pointer to the
new one to be used as soon as reasonable? I have seen many approaches. I
have seen entire packages yanked. I have seen parts that used to be in the
distribution as if built-in and then taken out and vice versa.

The point is you do not need a 4.0 to be incompatible. The incompatibility,
or need to change, can happen anytime when you are importing things like
numpy which is released whenever they want to and is not part of the python
distribution. Also, as we have seen at times, other modules you may have
imported, in some languages, can mask names you are using in your program
that you may not even be aware are there. Much can go wrong with software
and keeping current can also give you problems when something released may
have inadvertent changes or bugs.

So much of our code is voluntary and as noted earlier, some python
variants/distributions simply may not have anyone interested in keeping them
up to date. You as a user, take your chances.


-Original Message-
From: Python-list  On
Behalf Of Chris Angelico via Python-list
Sent: Wednesday, June 12, 2024 5:52 PM
To: python-list@python.org
Subject: Re: Couldn't install numpy on Python 2.7

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

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

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

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

Maybe your jokes just aren't funny.

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

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


Re: Couldn't install numpy on Python 2.7

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

It is almost certainly better to download the wheel (.whl) file rather
than the sdist (.tar.gz) file. Building NumPy from source needs not
just compilers etc but also you first need to build/install a BLAS
library.

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


Re: Couldn't install numpy on Python 2.7

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

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

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

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

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Greg Ewing via Python-list

On 13/06/24 4:31 am, avi.e.gr...@gmail.com wrote:

It seems Microsoft is having a problem where something lik 2/3 of Windows
users have not upgraded from Windows 10 after many years


At least Python 3 is a clear improvement over Python 2 in many ways.
Whereas the only thing Microsoft seems to have done with Windows in
recent times is change it in ways that nobody wants, so there is
understandable resistance to upgrading even if it's possible.

On 13/06/24 10:09 am, Chris Angelico wrote:
> So if anyone
> actually does need to use pip with Python 2.7, they probably need to
> set up a local server

You should also be able to download a .tar.gz from PyPI and use pip
to install that. Although you'll have to track down the dependencies
yourself in that case.

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Oscar Benjamin via Python-list
On Wed, 12 Jun 2024 at 23:11, Chris Angelico via Python-list
 wrote:
>
> On Thu, 13 Jun 2024 at 07:57, Oscar Benjamin via Python-list
>  wrote:
> > They are seeing a warning that explicitly says "You can upgrade to a
> > newer version of Python to solve this". I don't know whether that SSL
> > warning is directly connected to pip not finding any versions of numpy
> > but with the available information so far that seems like the first
> > thing to consider.
>
> I think it is; AIUI, with an ancient SSL library, pip is unable to
> download packages safely from the current pypi server. So if anyone
> actually does need to use pip with Python 2.7, they probably need to
> set up a local server, using older encryption protocols (which should
> therefore NOT be made accessible to the internet). Since pip can't
> contact the upstream pypi, there's no available numpy for it to
> install.

I don't know much about SSL and related networking things especially
on Windows. I would be surprised if pip on old Python can't install
from current PyPI though. I imagine that something strange has
happened like a new version of pip running on an old version of Python
or old Python on new OS (or old PyCharm...).

There is no problem using Python 2.7 with pip and PyPI on this Linux
machine but I guess it has a newer SSL library provided by the OS:

$ pip install numpy
DEPRECATION: Python 2.7 reached the end of its life on January 1st,
2020. Please upgrade your Python as Python 2.7 is no longer
maintained. pip 21.0 will drop support for Python 2.7 in January 2021.
More details about Python 2 support in pip can be found at
https://pip.pypa.io/en/latest/development/release-process/#python-2-support
pip 21.0 will remove support for this functionality.
Collecting numpy
  Downloading numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl (17.0 MB)
 || 17.0 MB 14.3 MB/s
Installing collected packages: numpy
Successfully installed numpy-1.16.6

If it is actually the case that pip on Python 2.7 (on Windows) cannot
download from PyPI then an easier option rather than creating a local
server would just be to download the numpy wheels from PyPI using a
browser:

  https://pypi.org/project/numpy/1.15.4/#files

Then you can do

   pip install .\numpy-1.15.4-cp27-none-win_amd64.whl

Using a newer version of Python is still my primary suggestion though.

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


Re: Couldn't install numpy on Python 2.7

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

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

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Oscar Benjamin via Python-list
On Wed, 12 Jun 2024 at 22:38, AVI GROSS via Python-list
 wrote:
>
> The discussion though was about a specific OP asking if they can fix their
> problem. One solution being suggested is to fix a deeper problem and simply
> make their code work with a recent version of python 3.

The OP has not replied with any explanation as to why they are using
Python 2.7 and has not said whether they have any existing code that
only works with Python 2.7. It is unclear at this point whether there
is any reason that they shouldn't just install a newer version of
Python.

They are seeing a warning that explicitly says "You can upgrade to a
newer version of Python to solve this". I don't know whether that SSL
warning is directly connected to pip not finding any versions of numpy
but with the available information so far that seems like the first
thing to consider.

It is entirely reasonable to start by suggesting to use a newer
version of Python until some reason is given for not doing that.

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


Re: Couldn't install numpy on Python 2.7

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

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

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

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

Maybe your jokes just aren't funny.

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


RE: Couldn't install numpy on Python 2.7

2024-06-12 Thread AVI GROSS via Python-list
Chris,

Since you misunderstood, my statement was that making an incompatible set of
changes to create Python 3 in the first place was a decision made by some
and perhaps not one that thrilled others who already had an embedded base of
programs or ones in the pipeline that would need much work to become
comparable.

And, of course, users of a program who continued to use python 2, also have
to find a way to ...

But if the goal was to deprecate python 2 and in some sense phase it out, it
is perhaps not working well for some. Frankly, issuing so many updates like
2.7 and including backporting of new features has helped make it possible to
delay any upgrade.

And, yes, I was KIDDING about python 4. I am simply suggesting that there
may well be a time that another shift happens that may require another
effort to get people on board a new and perhaps incompatible setup. I have
seen things like that happen in multiple phases including phases where the
new tools are not an upgrade, but brand new. An example might be if
accompany decided to switch to another existing language because they want
better error detection and faster execution or new features that may take
forever to arrive in what they are using or that supply various services by
humans to help them.

The discussion though was about a specific OP asking if they can fix their
problem. One solution being suggested is to fix a deeper problem and simply
make their code work with a recent version of python 3. But another solution
could be to step backward to a version of python 2 that still has numpy
support, or as was suggested, find out what other modules they are using are
interfering with the program being satisfied with the last version of numpy
being used and perhaps find a way to get ...

In the long run, though, continuing with python 2 will likely cause ever
more such headaches if you want the latest and greatest of things like
numpy.


-Original Message-
From: Python-list  On
Behalf Of Chris Angelico via Python-list
Sent: Wednesday, June 12, 2024 2:00 PM
To: python-list@python.org
Subject: Re: Couldn't install numpy on Python 2.7

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

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

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

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

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

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

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

> When is Python 4 coming?

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

Please don't FUD.

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

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


Re: Couldn't install numpy on Python 2.7

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

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

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

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

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

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

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


Re: Couldn't install numpy on Python 2.7

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

On 6/12/2024 1:59 PM, Chris Angelico via Python-list wrote:

On Thu, 13 Jun 2024 at 03:41, AVI GROSS via Python-list
 wrote:


Change is hard even when it may be necessary.

The argument often is about whether some things are necessary or not.

Python made a decision but clearly not a unanimous one.


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

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


I support a Tomcat project that has some java code and most of the code 
is for Jython 2.7.  Jython 2.7 is approximately on a par with Python 
2.7.  Any Python-only code from the standard library will probably run, 
but of course any C extensions cannot.  The nice thing about using 
Jython in a java environment is that it can call any java object, and 
java code can call Jython objects and their methods.


The project cannot move to a Python-3 compatible version because Jython 
3.xx doesn't exist and may never exist.  The saving grace is that my 
project doesn't have to use packages like numpy, scipy, and so forth. 
Also, the project is very mature and almost certainly won't need to 
create functionality such packages would enable.  It would be nice to be 
able to use some newer parts of the standard library, but there it is. 
Jython does support "from __future__ import" and I make use of that for 
the print function and the like.



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


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


I have a 2012-vintage laptop that in modern terms has a very small 
supply of RAM and a very slow hard drive. When my newer Windows 10 
computer was going to be out of service for a while, I put a Linux 
distro on an external SSD and copied things I needed to work on to it, 
including my Thunderbird email profile directory.


Thunderbird and everything else worked perfectly for me during that 
week.  True, there were a few Windows-only programs I missed, but I used 
other similar programs even if I didn't like them as much.  It's amazing 
how little resources Linux installs need, even with a GUI.  Of course, 
4GB RAM is limiting whether you are on Linux or Windows - you can't 
avoid shuffling all those GUI bits around - but with a little care it 
worked great.  And with the external SSD the laptop was a lot snappier 
than it ever was when it was new.



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


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


When is Python 4 coming?


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

Please don't FUD.

ChrisA


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


Re: Couldn't install numpy on Python 2.7

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

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

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

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

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

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

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

> When is Python 4 coming?

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

Please don't FUD.

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


RE: Couldn't install numpy on Python 2.7

2024-06-12 Thread AVI GROSS via Python-list
Change is hard even when it may be necessary.

The argument often is about whether some things are necessary or not.

Python made a decision but clearly not a unanimous one.

My current PC was not upgradable because of the new hardware requirement
Microsoft decided was needed for Windows 11. I bought a new one a while back
and turned it on in another room and then set it aside because replacing the
current one in the current position will be a pain, especially with getting
all my wires and so on, and since I do not want to use a full copy of my
data including many obsolete things, that will be another pain to get what I
need, if I can remember. Complicating issues also include licenses for
things in fixed amounts and the likelihood of messing up the
hardware/software I have that records shows from cable to my hard disk,
possibly needing to buy a new one.

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

I have wondered if instead of doing what Microsoft wants, if maybe switching
to Linux of some kinds makes as much sense. I suspect some may simply
upgrade to an Apple product.

And think of all the PC's that may effectively be discarded as they may not
even be usable if donated.

We live in a rapidly developing age and hence one with regularly and
irregularly scheduled rounds of obsolescence.

When is Python 4 coming?

-Original Message-
From: Python-list  On
Behalf Of MRAB via Python-list
Sent: Wednesday, June 12, 2024 12:56 PM
To: python-list@python.org
Subject: Re: Couldn't install numpy on Python 2.7

On 2024-06-12 17:31, AVI GROSS via Python-list wrote:
> I am sure there is inertia to move from an older product and some people
> need a reason like this where the old becomes untenable.
> 
> It seems Microsoft is having a problem where something lik 2/3 of Windows
> users have not upgraded from Windows 10 after many years and have set a
> deadline in a year or so for stopping updates. In that case, hardware was
a
> concern for some as Windows 11 did not work on their machines. With
> upgrading python, the main concern is having to get someone to examine old
> code and try to make it compatible.
> 
In the case of Windows, my PC is over 10 years old yet performs 
perfectly well for my needs. It can't run Windows 11. Therefore, I'm in 
the process of migrating to Linux, and I still have over a year to 
achieve that before support ends.

> But anyone doing new code in Python 2 in recent years should ...
> 
Indeed...

> -Original Message-
> From: Python-list 
On
> Behalf Of Gordinator via Python-list
> Sent: Wednesday, June 12, 2024 10:19 AM
> To: python-list@python.org
> Subject: Re: Couldn't install numpy on Python 2.7
> 
> On 12/06/2024 12:30, marc nicole wrote:
>> I am trying to install numpy library on Python 2.7.15 in PyCharm but the
>> error message I get is:
>> 
>> ERROR: Could not find a version that satisfies the requirement numpy
(from
>>> versions: none)
>>> ERROR: No matching distribution found for numpy
>>> c:\python27\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py:164:
>>> InsecurePlatformWarning: A true SSLContext object is not available. This
>>> prevents urllib3 fro
>>> m configuring SSL appropriately and may cause certain SSL connections to
>>> fail. You can upgrade to a newer version of Python to solve this. For
> more
>>> information, see
>>>
https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
>>>InsecurePlatformWarning,
>> 
>> 
>> Any clues?
> 
> Why are you using Python 2? Come on, it's been 16 years. Ya gotta move
> on at some point.

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

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread MRAB via Python-list

On 2024-06-12 17:31, AVI GROSS via Python-list wrote:

I am sure there is inertia to move from an older product and some people
need a reason like this where the old becomes untenable.

It seems Microsoft is having a problem where something lik 2/3 of Windows
users have not upgraded from Windows 10 after many years and have set a
deadline in a year or so for stopping updates. In that case, hardware was a
concern for some as Windows 11 did not work on their machines. With
upgrading python, the main concern is having to get someone to examine old
code and try to make it compatible.

In the case of Windows, my PC is over 10 years old yet performs 
perfectly well for my needs. It can't run Windows 11. Therefore, I'm in 
the process of migrating to Linux, and I still have over a year to 
achieve that before support ends.



But anyone doing new code in Python 2 in recent years should ...


Indeed...


-Original Message-
From: Python-list  On
Behalf Of Gordinator via Python-list
Sent: Wednesday, June 12, 2024 10:19 AM
To: python-list@python.org
Subject: Re: Couldn't install numpy on Python 2.7

On 12/06/2024 12:30, marc nicole wrote:

I am trying to install numpy library on Python 2.7.15 in PyCharm but the
error message I get is:

ERROR: Could not find a version that satisfies the requirement numpy (from

versions: none)
ERROR: No matching distribution found for numpy
c:\python27\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py:164:
InsecurePlatformWarning: A true SSLContext object is not available. This
prevents urllib3 fro
m configuring SSL appropriately and may cause certain SSL connections to
fail. You can upgrade to a newer version of Python to solve this. For

more

information, see
https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
   InsecurePlatformWarning,



Any clues?


Why are you using Python 2? Come on, it's been 16 years. Ya gotta move
on at some point.


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


RE: Couldn't install numpy on Python 2.7

2024-06-12 Thread AVI GROSS via Python-list
I am sure there is inertia to move from an older product and some people
need a reason like this where the old becomes untenable.

It seems Microsoft is having a problem where something lik 2/3 of Windows
users have not upgraded from Windows 10 after many years and have set a
deadline in a year or so for stopping updates. In that case, hardware was a
concern for some as Windows 11 did not work on their machines. With
upgrading python, the main concern is having to get someone to examine old
code and try to make it compatible. 

But anyone doing new code in Python 2 in recent years should ...

-Original Message-
From: Python-list  On
Behalf Of Gordinator via Python-list
Sent: Wednesday, June 12, 2024 10:19 AM
To: python-list@python.org
Subject: Re: Couldn't install numpy on Python 2.7

On 12/06/2024 12:30, marc nicole wrote:
> I am trying to install numpy library on Python 2.7.15 in PyCharm but the
> error message I get is:
> 
> ERROR: Could not find a version that satisfies the requirement numpy (from
>> versions: none)
>> ERROR: No matching distribution found for numpy
>> c:\python27\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py:164:
>> InsecurePlatformWarning: A true SSLContext object is not available. This
>> prevents urllib3 fro
>> m configuring SSL appropriately and may cause certain SSL connections to
>> fail. You can upgrade to a newer version of Python to solve this. For
more
>> information, see
>> https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
>>InsecurePlatformWarning,
> 
> 
> Any clues?

Why are you using Python 2? Come on, it's been 16 years. Ya gotta move 
on at some point.
-- 
https://mail.python.org/mailman/listinfo/python-list

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Gordinator via Python-list

On 12/06/2024 12:30, marc nicole wrote:

I am trying to install numpy library on Python 2.7.15 in PyCharm but the
error message I get is:

ERROR: Could not find a version that satisfies the requirement numpy (from

versions: none)
ERROR: No matching distribution found for numpy
c:\python27\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py:164:
InsecurePlatformWarning: A true SSLContext object is not available. This
prevents urllib3 fro
m configuring SSL appropriately and may cause certain SSL connections to
fail. You can upgrade to a newer version of Python to solve this. For more
information, see
https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
   InsecurePlatformWarning,



Any clues?


Why are you using Python 2? Come on, it's been 16 years. Ya gotta move 
on at some point.

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


Re: Couldn't install numpy on Python 2.7

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

The answer is right there in the error message.

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


Couldn't install numpy on Python 2.7

2024-06-12 Thread marc nicole via Python-list
I am trying to install numpy library on Python 2.7.15 in PyCharm but the
error message I get is:

ERROR: Could not find a version that satisfies the requirement numpy (from
> versions: none)
> ERROR: No matching distribution found for numpy
> c:\python27\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py:164:
> InsecurePlatformWarning: A true SSLContext object is not available. This
> prevents urllib3 fro
> m configuring SSL appropriately and may cause certain SSL connections to
> fail. You can upgrade to a newer version of Python to solve this. For more
> information, see
> https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
>   InsecurePlatformWarning,


Any clues?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

2024-06-11 Thread HenHanna via Python-list

On 6/10/2024 6:29 AM, Rob Cliffe wrote:

import itertools

def chunk1(seq):
     return [ ch * len(list(grp)) for (ch, grp) in itertools.groupby(s) ]

def chunk2(seq):
     return [ (ch, len(list(grp))) for (ch, grp) in itertools.groupby(s) ]

s='aaabbaa'
print(chunk1(s))
print(chunk2(s))
###
Program output:
['aaa', 'bb', '', 'aa']
[('a', 3), ('b', 2), ('c', 4), ('a', 2)]

Rob Cliffe




thank you...   OMG... For 10 minutes... i was SO mystified by
the question...
How can this code work??? ,  when it's
  > def chunk1(seq):
 and it's  [s]   within the def-body ?

it seemed as if the Compiler was doing a DWIM (Do what i mean)  trick.




On 09/06/2024 22:20, HenHanna via Python-list wrote:


Chunk, ChunkC -- nice simple way(s) to write these in Python?


(Chunk  '(a a   b    a a a   b b))
    ==> ((a a) (b)  (a a a) (b b))


(Chunk  '(a a a a   b   c c   a a   d   e e e e))
    ==> ((a a a a) (b) (c c) (a a) (d) (e e e e))


(Chunk  '(2 2   foo   bar bar   j j j   k   baz baz))
    ==> ((2 2) (foo) (bar bar) (j j j) (k) (baz baz))

_

(ChunkC  '(a a   b b b))
 ==> ((a 2)  (b 3))

(ChunkC  '(a a   b  a a a   b b))
 ==> ((a 2)  (b 1)  (a 3)   (b 2))




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


RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

2024-06-11 Thread AVI GROSS via Python-list
Rob,

That is a fairly straightforward and elegant solution if using an added mode 
called itertools.

I went a different way by creating my own focused iterator and calling it, when 
needed, to produce one or the other of the results requested in the functions 
named chunk() and chunkc(). But note my version operates to produce lists no 
matter what the input was. It produces lists nestled within lists. Presumably 
it could be adjusted to check if the input was a tuple and then return a 
grouping of tuples within a tuple.

The code, just for fun, is below and probably could be more elegant! LOL!

### CODE START

# Iterator version to be called as needed or all at once as with ChunkC
def ChunkIterator(seq):
  # Purpose is to evaluate a list and return a list
  # of lists with each one containing the longest run
  # of each item.
  
  # Handle an empty list
  if len(seq) == 0: return container
  
  # Initialize the first item in a copy.
  # The first item is now in a initialized list.
  gathered = [last := seq[0]]
  
  # Loop over the remaining items and yield as needed.
  for item in seq[1:]:
if len(gathered) == 0: gathered = [item]
elif item == last: gathered.append(item)
else: # not equal means yield result and start anew for next group
  yield(gathered)
  gathered = [last := item]
  
  # After loop completes, any remaining data is returned as the function 
terminates. 
  if len(gathered) > 0: yield(gathered)

# Accesory function that runs the iterator to completion into a list.  
def Chunk(seq): return list(ChunkIterator(seq))

# Function that simplifies the Chunks as an item and a number of instances.
def ChunkC(seq):
  return [[group[0], len(group)] for  group in ChunkIterator(seq)]
### CODE END

### EXAMPLES
>>> tuple(Chunk([1, 2, 2, 'c', 'c', 'c', 'singleton']))
([1], [2, 2], ['c', 'c', 'c'], ['singleton'])
>>> chunk([1, 2, 2, 'c', 'c', 'c', 'singleton'])
[[1], [2, 2], ['c', 'c', 'c'], ['singleton']]
>>> chunkC([1, 2, 2, 'c', 'c', 'c', 'singleton'])
[[1, 1], [2, 2], ['c', 3], ['singleton', 1]]

# COMMENTS
The current version has flaws I have not bothered correcting. Just for a demo.


-Original Message-
From: Python-list  On 
Behalf Of Rob Cliffe via Python-list
Sent: Monday, June 10, 2024 9:29 AM
To: python-list@python.org
Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

import itertools

def chunk1(seq):
 return [ ch * len(list(grp)) for (ch, grp) in itertools.groupby(s) ]

def chunk2(seq):
 return [ (ch, len(list(grp))) for (ch, grp) in itertools.groupby(s) ]

s='aaabbaa'
print(chunk1(s))
print(chunk2(s))
###
Program output:
['aaa', 'bb', '', 'aa']
[('a', 3), ('b', 2), ('c', 4), ('a', 2)]

Rob Cliffe

On 09/06/2024 22:20, HenHanna via Python-list wrote:
>
> Chunk, ChunkC -- nice simple way(s) to write these in Python?
>
>
> (Chunk  '(a a   ba a a   b b))
> ==> ((a a) (b)  (a a a) (b b))
>
>
> (Chunk  '(a a a a   b   c c   a a   d   e e e e))
> ==> ((a a a a) (b) (c c) (a a) (d) (e e e e))
>
>
> (Chunk  '(2 2   foo   bar bar   j j j   k   baz baz))
> ==> ((2 2) (foo) (bar bar) (j j j) (k) (baz baz))
>
> _
>
> (ChunkC  '(a a   b b b))
>  ==> ((a 2)  (b 3))
>
> (ChunkC  '(a a   b  a a a   b b))
>  ==> ((a 2)  (b 1)  (a 3)   (b 2))

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

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


Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

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

import itertools

def chunk1(seq):
    return [ ch * len(list(grp)) for (ch, grp) in itertools.groupby(s) ]

def chunk2(seq):
    return [ (ch, len(list(grp))) for (ch, grp) in itertools.groupby(s) ]

s='aaabbaa'
print(chunk1(s))
print(chunk2(s))
###
Program output:
['aaa', 'bb', '', 'aa']
[('a', 3), ('b', 2), ('c', 4), ('a', 2)]

Rob Cliffe

On 09/06/2024 22:20, HenHanna via Python-list wrote:


Chunk, ChunkC -- nice simple way(s) to write these in Python?


(Chunk  '(a a   b    a a a   b b))
    ==> ((a a) (b)  (a a a) (b b))


(Chunk  '(a a a a   b   c c   a a   d   e e e e))
    ==> ((a a a a) (b) (c c) (a a) (d) (e e e e))


(Chunk  '(2 2   foo   bar bar   j j j   k   baz baz))
    ==> ((2 2) (foo) (bar bar) (j j j) (k) (baz baz))

_

(ChunkC  '(a a   b b b))
 ==> ((a 2)  (b 3))

(ChunkC  '(a a   b  a a a   b b))
 ==> ((a 2)  (b 1)  (a 3)   (b 2))


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


RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

2024-06-10 Thread AVI GROSS via Python-list
> i was just curiuos about simple, clever way to write it in Python

It depends on what you mean by "clever".

For some, it was like a suggestion on using something already available such
as itertools.groupby, perhaps even better if it is actually compiled in from
a language like C and perhaps more efficient.

For some who like to Scheme, only a recursive solution may be  considered
clever!

For some who have absorbed ideas in languages like python,  perhaps they
would implement it the way I described as an iterator that is efficient in
the sense that it delivers things just in time and quits if not iterated
further. An example might be if you asked to get groups of consecutive
digits in the calculated indefinite value of a number like pi or e or looked
at how many digits in a row were the same for prime numbers but wanted to
quit after the first billion.

Some may like some kind of functional programming method. Some want short
code and some want efficiency and some even like something written in a
subtle way so others have trouble understanding it, as in the obfuscated C
contests.

What you do need to consider is what exactly are your requirements. Your
examples are trivial so maybe we need to think about what it means to gather
together what is supplied in one container, into a container containing
other grouped containers.

First, what python containers should be handled? Yes, you probably mean a
list but if handed a tuple, should it return the same, or always return a
list for the top level and perhaps even deeper levels? There are many
containers in python including (ordered) dictionaries where the keys may be
unique, but you may want to see if the contents have some order, numpy
arrays, and so on.

And, are all the contents required to be atomic? What does it mean for items
in a row to be equal? If I have a sublist, should I unlist to make it flat
first, or should it be an error, or should each such sublist be compared for
full equality or even relative equality so that (a (b c) (c b) d) actually
accepts (b c) and (c b) as the same for the purpose? For that matter, is 1.0
matched to 1 or even "1" or perhaps an object that has that value in some
way such as when comparing arbitrary objects?

There can be many such questions and some elegant methods get less elegant
if they need to handle too much. You need to explain what to do when a bad
unintended case is found, such as perhaps an empty list or ...

To just do what your examples ask, again, seems easy enough. It is the usual
code if not done too elegantly. Write a function that accepts a list (or
tries to coerce what it gets into a copy as a list. It returns an empty list
if it has nothing, otherwise pops off the first item and then loops on the
rest. When items match the current first item, extend a sublist and when
they don't, yield what you have and start a new sublist. After the loop,
anything remaining is returned.

Simple enough?

Note to get your result properly, since it is an iterator, you need to
either be calling it iteratively, or do something like:

Result = list(chunk(something))

To force it to run to completion.



-Original Message-
From: Python-list  On
Behalf Of HenHanna via Python-list
Sent: Sunday, June 9, 2024 10:37 PM
To: python-list@python.org
Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

On 6/9/2024 7:05 PM, avi.e.gr...@gmail.com wrote:
> I remembered that HenHanna had been hard to deal with in the past and when
> my reply to him/her/them bounced as a bad/fake address it came back to me
> that I am better off not participating in this latest attempt to get us to
> perform then probably shoot whatever we say down.
> 
> A considerate person would ask questions more clearly and perhaps explain
> what language they are showing us code from and so on.
> 
> Life is too short to waste.
> 
> -Original Message-
> From: Python-list 
On
> Behalf Of HenHanna via Python-list
> Sent: Sunday, June 9, 2024 5:20 PM
> To: python-list@python.org
> Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
> 
> Chunk, ChunkC -- nice simple way(s) to write these in Python?
> 
> 
> (Chunk  '(a a   ba a a   b b))
>   ==> ((a a) (b)  (a a a) (b b))
> 
> 
> (Chunk  '(a a a a   b   c c   a a   d   e e e e))
>   ==> ((a a a a) (b) (c c) (a a) (d) (e e e e))
> 
> 
> (Chunk  '(2 2   foo   bar bar   j j j   k   baz baz))
>   ==> ((2 2) (foo) (bar bar) (j j j) (k) (baz baz))
> 
> _
> 
> (ChunkC  '(a a   b b b))
>==> ((a 2)  (b 3))
> 
> (ChunkC  '(a a   b  a a a   b b))
>==> ((a 2)  (b 1)  (a 3)   (b 2))



i was just curiuos about simple, clever way to write it in Python


in Scheme (Gauche)

(use srfi-1)  ;; span

(define (gp x)
   (if (null? x) '()
 (let-values (((F L) (span (cut equal? (car x) <>) x)))
   (cons F (gp L)

(print (gp   '(ab ba a a   b b b b)))
(print (gp   '(c c c   a   d d d d   a   e e e e e)))


Re: IDLE: clearing the screen

2024-06-10 Thread Michael F. Stemper via Python-list

On 08/06/2024 14.18, Rob Cliffe wrote:

OK, here is the advanced version:
import os
class _cls(object):
     def __repr__(self):
         os.system('cls')
         return ''
cls = _cls()

Now when you type
cls
it clears the screen.  The only flaw is that there is a blank line at the very top of the screen, 
and the ">>>" prompt appears on the SECOND line.
(This blank line is because the IDLE prints the blank value returned by "return 
''" and adds a newline to it, as it does when printing the value of any expression.)


Why have it return anything at all?

--
Michael F. Stemper
Indians scattered on dawn's highway bleeding;
Ghosts crowd the young child's fragile eggshell mind.

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


Re: IDLE: clearing the screen

2024-06-10 Thread Michael F. Stemper via Python-list

On 10/06/2024 09.32, Stefan Ram wrote:

"Michael F. Stemper"  wrote or quoted:

On 08/06/2024 14.18, Rob Cliffe wrote:

OK, here is the advanced version:
import os
class _cls(object):
      def __repr__(self):
          os.system('cls')
          return ''
cls = _cls()

...

Why have it return anything at all?


   Because __repr__ needs to return a str.


Got it. Thanks for clarifying.

--
Michael F. Stemper
87.3% of all statistics are made up by the person giving them.

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


Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

2024-06-10 Thread HenHanna via Python-list

On 6/9/2024 7:05 PM, avi.e.gr...@gmail.com wrote:

I remembered that HenHanna had been hard to deal with in the past and when
my reply to him/her/them bounced as a bad/fake address it came back to me
that I am better off not participating in this latest attempt to get us to
perform then probably shoot whatever we say down.

A considerate person would ask questions more clearly and perhaps explain
what language they are showing us code from and so on.

Life is too short to waste.

-Original Message-
From: Python-list  On
Behalf Of HenHanna via Python-list
Sent: Sunday, June 9, 2024 5:20 PM
To: python-list@python.org
Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

Chunk, ChunkC -- nice simple way(s) to write these in Python?


(Chunk  '(a a   ba a a   b b))
  ==> ((a a) (b)  (a a a) (b b))


(Chunk  '(a a a a   b   c c   a a   d   e e e e))
  ==> ((a a a a) (b) (c c) (a a) (d) (e e e e))


(Chunk  '(2 2   foo   bar bar   j j j   k   baz baz))
  ==> ((2 2) (foo) (bar bar) (j j j) (k) (baz baz))

_

(ChunkC  '(a a   b b b))
   ==> ((a 2)  (b 3))

(ChunkC  '(a a   b  a a a   b b))
   ==> ((a 2)  (b 1)  (a 3)   (b 2))




i was just curiuos about simple, clever way to write it in Python


in Scheme (Gauche)

(use srfi-1)  ;; span

(define (gp x)
  (if (null? x) '()
(let-values (((F L) (span (cut equal? (car x) <>) x)))
  (cons F (gp L)

(print (gp   '(ab ba a a   b b b b)))
(print (gp   '(c c c   a   d d d d   a   e e e e e)))

(define (gpC x)  (map (lambda (x) (list (car x) (length x))) (gp x)))

(print (gpC '(ab ba a a   b b b b)))
(print (gpC '(c c c   a   d d d d   a   e e e e e)))
--
https://mail.python.org/mailman/listinfo/python-list


Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

2024-06-10 Thread HenHanna via Python-list

On 6/9/2024 3:50 PM, MRAB wrote:

On 2024-06-09 22:20, HenHanna via Python-list wrote:


Chunk, ChunkC -- nice simple way(s) to write these in Python?


(Chunk  '(a a   b    a a a   b b))
  ==> ((a a) (b)  (a a a) (b b))


(Chunk  '(a a a a   b   c c   a a   d   e e e e))
  ==> ((a a a a) (b) (c c) (a a) (d) (e e e e))


(Chunk  '(2 2   foo   bar bar   j j j   k   baz baz))
  ==> ((2 2) (foo) (bar bar) (j j j) (k) (baz baz))

_

(ChunkC  '(a a   b b b))
   ==> ((a 2)  (b 3))

(ChunkC  '(a a   b  a a a   b b))
   ==> ((a 2)  (b 1)  (a 3)   (b 2))


You can make use of itertools.groupby.




Thanks!   i'll try it.


Scheme (Gauche)

(use srfi-1)   ; span

(define (gp x)
  (if (null? x) '()
(let-values (((F L) (span (cut equal? (car x) <>) x)))
  (cons F (gp L)

(print (gp   '(ab ba a a   b b b b)))
(print (gp   '(c c c   a   d d d d   a   e e e e e)))

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


RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

2024-06-09 Thread AVI GROSS via Python-list
I remembered that HenHanna had been hard to deal with in the past and when
my reply to him/her/them bounced as a bad/fake address it came back to me
that I am better off not participating in this latest attempt to get us to
perform then probably shoot whatever we say down.

A considerate person would ask questions more clearly and perhaps explain
what language they are showing us code from and so on.

Life is too short to waste.

-Original Message-
From: Python-list  On
Behalf Of HenHanna via Python-list
Sent: Sunday, June 9, 2024 5:20 PM
To: python-list@python.org
Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))


Chunk, ChunkC -- nice simple way(s) to write these in Python?


(Chunk  '(a a   ba a a   b b))
 ==> ((a a) (b)  (a a a) (b b))


(Chunk  '(a a a a   b   c c   a a   d   e e e e))
 ==> ((a a a a) (b) (c c) (a a) (d) (e e e e))


(Chunk  '(2 2   foo   bar bar   j j j   k   baz baz))
 ==> ((2 2) (foo) (bar bar) (j j j) (k) (baz baz))

_

(ChunkC  '(a a   b b b))
  ==> ((a 2)  (b 3))

(ChunkC  '(a a   b  a a a   b b))
  ==> ((a 2)  (b 1)  (a 3)   (b 2))
-- 
https://mail.python.org/mailman/listinfo/python-list

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


RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

2024-06-09 Thread AVI GROSS via Python-list
HH,

Before bothering, it might be helpful if you spelled out a bit more in the
way of requirements that would satisfy you and perhaps show your attempts.

Your examples suggest it would be fairly simple to create an iterator, for
example, that would yield as it examined one item at a time until it ran out
or the next item was not the same. It could then either return a tuple it
had collected so far since the last yield, or for what you call chunkC,
return a tuple containing one copy of the item and a count of how many.

But if you want something else, such as a list all at once, that too would
be trivial, perhaps leveraging the above.

-Original Message-
From: Python-list  On
Behalf Of HenHanna via Python-list
Sent: Sunday, June 9, 2024 5:20 PM
To: python-list@python.org
Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))


Chunk, ChunkC -- nice simple way(s) to write these in Python?


(Chunk  '(a a   ba a a   b b))
 ==> ((a a) (b)  (a a a) (b b))


(Chunk  '(a a a a   b   c c   a a   d   e e e e))
 ==> ((a a a a) (b) (c c) (a a) (d) (e e e e))


(Chunk  '(2 2   foo   bar bar   j j j   k   baz baz))
 ==> ((2 2) (foo) (bar bar) (j j j) (k) (baz baz))

_

(ChunkC  '(a a   b b b))
  ==> ((a 2)  (b 3))

(ChunkC  '(a a   b  a a a   b b))
  ==> ((a 2)  (b 1)  (a 3)   (b 2))
-- 
https://mail.python.org/mailman/listinfo/python-list

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


Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

2024-06-09 Thread MRAB via Python-list

On 2024-06-09 22:20, HenHanna via Python-list wrote:


Chunk, ChunkC -- nice simple way(s) to write these in Python?


(Chunk  '(a a   ba a a   b b))
  ==> ((a a) (b)  (a a a) (b b))


(Chunk  '(a a a a   b   c c   a a   d   e e e e))
  ==> ((a a a a) (b) (c c) (a a) (d) (e e e e))


(Chunk  '(2 2   foo   bar bar   j j j   k   baz baz))
  ==> ((2 2) (foo) (bar bar) (j j j) (k) (baz baz))

_

(ChunkC  '(a a   b b b))
   ==> ((a 2)  (b 3))

(ChunkC  '(a a   b  a a a   b b))
   ==> ((a 2)  (b 1)  (a 3)   (b 2))


You can make use of itertools.groupby.

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


in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

2024-06-09 Thread HenHanna via Python-list



Chunk, ChunkC -- nice simple way(s) to write these in Python?


(Chunk  '(a a   ba a a   b b))
==> ((a a) (b)  (a a a) (b b))


(Chunk  '(a a a a   b   c c   a a   d   e e e e))
==> ((a a a a) (b) (c c) (a a) (d) (e e e e))


(Chunk  '(2 2   foo   bar bar   j j j   k   baz baz))
==> ((2 2) (foo) (bar bar) (j j j) (k) (baz baz))

_

(ChunkC  '(a a   b b b))
 ==> ((a 2)  (b 3))

(ChunkC  '(a a   b  a a a   b b))
 ==> ((a 2)  (b 1)  (a 3)   (b 2))
--
https://mail.python.org/mailman/listinfo/python-list


Re: IDLE: clearing the screen

2024-06-09 Thread Alan Gauld via Python-list
On 08/06/2024 20:18, Rob Cliffe via Python-list wrote:
> OK, here is the advanced version:
> import os
> class _cls(object):
>      def __repr__(self):
>          os.system('cls')
>          return ''
> cls = _cls()
> 
> Now when you type
> cls
> it clears the screen.  

For me on a Mac it clears the terminal screen that I used
to launch IDLE and prints a single blank line on the IDLE
shell. (And I have to use "clear" instead of "cls" of course.

A quick Google suggests that printing Ctrl-L (formfeed?) might
be a platform agnostic solution. But that didn't work for me
in IDLE either. I think this is one where the best bet is to go
into the IDLE code and add a Shell submenu to clear screen!
Apparently it's been on the workstack at idle-dev for a long
time but is considered low priority...

-- 
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: From JoyceUlysses.txt -- words occurring exactly once

2024-06-08 Thread Grant Edwards via Python-list
On 2024-06-08, Larry Martell via Python-list  wrote:

> The original question struck me as homework or an interview question for a
> junior position. But having no clear requirements or specifications is good
> training for the real world where that is often the case. When you question
> that, you are told to just do something, and then you’re told it’s not what
> is wanted. That frustrates people but it’s often part of the process.
> People need to see something to help them know what they really want.

Too true.  You can spend all sorts of time getting people to pin down
and sign off on the initial requirements, but it all goes right out
the window when they get the first prototype.

  "This isn't what we want, we want it to do ."

  "It does what you specified."

  "But, this isn't what we want."

  ...

If you're on salary, it's all part of the job. If you're a contractor,
you either figure it in to the bid or charge for change orders.



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


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

2024-06-08 Thread AVI GROSS via Python-list
I agree with Larry that the OP was asking something that might be fair to use 
in an interview process where perhaps an exact answer is not as important as 
showing how the person thinks about a process. The original question can be 
incomplete or vague. Do they give up? Do they ask careful questions that might 
elicit missing parts? Do they examine alternatives and then pick a reasonable 
one and document exactly which possible version(s) their presented code should 
solve?

In this case, as mentioned, one approach is to isolate the determination of 
what a word means from the rest of the problem.

In effect, the code can be:

- read in all lines of text.
- words = function_name(text)
- optionally, manipulate the words such as making them all the same case, 
removing some characters, throwing some way.
- count the words in words remaining using some method such as a dictionary.
- output reports as requested.

You could then design any number of functions you can slide into place and the 
remaining code may continue working without changes.

It may not matter if you can specify the specific definition of text if you 
show the general solution, and maybe instantiate some fairly simple way of 
making words.

Note, the above logic applies not to just python but most programming 
environments. If someone interviewed me for a job in say, Rust, which I am just 
now learning out of curiosity, I might not know how to program some parts of a 
problem like this, let alone make use of the idioms of that language right 
away. But if they want someone who can rapidly learn the local ways and adapt, 
then the best they can do is try to see if you think like a programmer and can 
think abstractly and be able to do lots of work even while waiting for more 
info from someone on what they want for a specific part.

Or, in a case like this problem, I wonder if they would want to hear a 
suggestion that this may more easily be done in languages that support 
something like the dictionary or hash or associative array concept or that have 
available modules/packages/crates/etc. that provide such functionality.

-Original Message-
From: Python-list  On 
Behalf Of Larry Martell via Python-list
Sent: Saturday, June 8, 2024 11:54 AM
To: Mats Wichmann 
Cc: python-list@python.org
Subject: Re: From JoyceUlysses.txt -- words occurring exactly once

On Sat, Jun 8, 2024 at 10:39 AM Mats Wichmann via Python-list <
python-list@python.org> wrote:

> On 6/5/24 05:10, Thomas Passin via Python-list wrote:
>
> > Of course, we see this lack of clarity all the time in questions to the
> > list.  I often wonder how these askers can possibly come up with
> > acceptable code if they don't realize they don't truly know what it's
> > supposed to do.
>
> Fortunately, having to explain to someone else why something is giving
> you trouble can help shed light on the fact the problem statement isn't
> clear, or isn't clearly understood. Sometimes (sadly, many times it
> doesn't).


The original question struck me as homework or an interview question for a
junior position. But having no clear requirements or specifications is good
training for the real world where that is often the case. When you question
that, you are told to just do something, and then you’re told it’s not what
is wanted. That frustrates people but it’s often part of the process.
People need to see something to help them know what they really want.

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

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


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

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

On 6/8/2024 2:46 PM, avi.e.gr...@gmail.com wrote:

Agreed, Thomas.

As someone who has spent lots of time writing code OR requirements of various 
levels or having to deal with the bugs afterwards, there can be a huge 
disconnect between the people trying to decide what to do and the people having 
to do it. It is not necessarily easy to come back later and ask for changes 
that wewre not anticipated in the design or implementation.


And typical contract vehicles aren't often flexible to allow for this 
kind of thing. I've always tried to persuade my management to allow 
built-in phases where re-evaluation can take place based on what's been 
learned. To have a hope of that working, though, there needs to be a lot 
of trust between client and development folks.  Can be hard to come by.



I recently wrote a program where the original specifications seemed reasonable. 
In one part, I was asked to make a graph with some random number (or all) of 
the data shown as a series of connected line segments showing values for the 
same entity at different measurement periods and then superimpose the mean for 
all the original data, not just the subsample shown. This needed to be done on 
multiple subsamples of the original/calculated data so I made it into a 
function.

One of the datasets contained a column that was either A or B and the function 
was called multiple times to show what a random sample of A+B, just A and just 
B graphed like along with the mean of the specific data it was drawn from. But 
then, I got an innocuously simple request.

Could we graph A+B and overlay not only the means for A+B as was now done, but 
also the mean for A and the mean for B. Ideally, this would mean three bolder 
jaged lines superimposed above the plot and seemed simple enough.

But was it? To graph the means in the first place, I made a more complex data 
structure needed so when graphed, it aligned well with what was below it. But 
that was hard coded in my function, but in one implementation, I now needed it 
three times. Extracting it into a new function was not trivial as it depended 
initially on other things within the body of the function. But, it was doable 
and might have been done that way had I known such a need might arise. It often 
is like that when there seems no need to write a function for just one use. The 
main function now needed to be modified to allow optionally adding one or two 
more datasets and if available, call the new function on each and add layers to 
the graph with the additional means (dashed and dotted) if they are called 
while otherwise, the function worked as before.


I feel your pain. In the generalized X-Y graphing program I've evolved 
over several generations, I have graphing methods that can plot points 
and curves, optionally overlaying them.  Any function that wants to plot 
something has to generate a dataset object of the type that the plotter 
knows how to plot.  No exceptions. Nothing else ever plots to the 
screen.  It's simple and works very well ... but I only designed it to 
have axis labels and the title of the plot. They are all three 
interactive, editable by the user.  That's good, but for anything else 
it's hack time.  Witness lines, legends, point labels, etc., etc. don't 
have a natural home.



But did I do it right? Well, if next time I am asked to have the data extended to 
have more measurements in more columns at more times, I might have to rewrite quite 
a bit of the code. My localized change allowed one or two additional means to be 
plotted. Adding an arbitrary number takes a different approach and, frankly, there 
are limits on how many kinds of 'line" segments can be used to differentiate 
among them.


This is the kind of situation where it needs to be implemented three 
times before it gets good.  One always thinks that the second time 
around will work well because all the lessons were learned the first 
time around.  But no, it's not the second but the third implementation 
that can start to be really good.



Enough of the example except to make a point. In some projects, it is not 
enough to tell a programmer what you want NOW. You may get what you want fairly 
quickly but if you have ideas of possible extensions or future upgrades, it 
would be wiser to make clear some of the goals so the programmer creates an 
implementation that can be more easily adjusted to do more. Such code can take 
longer and be more complex so it may not pay off immediately.

But, having said that, plenty of software may benefit from looking at what is 
happening and adjusting on the fly. Clearly my client cannot know what feedback 
they may get when showing an actual result to others who then suggest changes 
or enhancements. The results may not be anticipated so well in advance and 
especially not when the client has no idea what is doable and so on.

A related example was a request for how to modify a sort of Venn Diagram  chart 
to change the font size. Why? 

Re: IDLE: clearing the screen

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

OK, here is the advanced version:
import os
class _cls(object):
    def __repr__(self):
        os.system('cls')
        return ''
cls = _cls()

Now when you type
cls
it clears the screen.  The only flaw is that there is a blank line at 
the very top of the screen, and the ">>>" prompt appears on the SECOND 
line.
(This blank line is because the IDLE prints the blank value returned by 
"return ''" and adds a newline to it, as it does when printing the value 
of any expression.)


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


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

2024-06-08 Thread AVI GROSS via Python-list
Agreed, Thomas. 

As someone who has spent lots of time writing code OR requirements of various 
levels or having to deal with the bugs afterwards, there can be a huge 
disconnect between the people trying to decide what to do and the people having 
to do it. It is not necessarily easy to come back later and ask for changes 
that wewre not anticipated in the design or implementation.

I recently wrote a program where the original specifications seemed reasonable. 
In one part, I was asked to make a graph with some random number (or all) of 
the data shown as a series of connected line segments showing values for the 
same entity at different measurement periods and then superimpose the mean for 
all the original data, not just the subsample shown. This needed to be done on 
multiple subsamples of the original/calculated data so I made it into a 
function. 

One of the datasets contained a column that was either A or B and the function 
was called multiple times to show what a random sample of A+B, just A and just 
B graphed like along with the mean of the specific data it was drawn from. But 
then, I got an innocuously simple request.

Could we graph A+B and overlay not only the means for A+B as was now done, but 
also the mean for A and the mean for B. Ideally, this would mean three bolder 
jaged lines superimposed above the plot and seemed simple enough.

But was it? To graph the means in the first place, I made a more complex data 
structure needed so when graphed, it aligned well with what was below it. But 
that was hard coded in my function, but in one implementation, I now needed it 
three times. Extracting it into a new function was not trivial as it depended 
initially on other things within the body of the function. But, it was doable 
and might have been done that way had I known such a need might arise. It often 
is like that when there seems no need to write a function for just one use. The 
main function now needed to be modified to allow optionally adding one or two 
more datasets and if available, call the new function on each and add layers to 
the graph with the additional means (dashed and dotted) if they are called 
while otherwise, the function worked as before.

But did I do it right? Well, if next time I am asked to have the data extended 
to have more measurements in more columns at more times, I might have to 
rewrite quite a bit of the code. My localized change allowed one or two 
additional means to be plotted. Adding an arbitrary number takes a different 
approach and, frankly, there are limits on how many kinds of 'line" segments 
can be used to differentiate among them.

Enough of the example except to make a point. In some projects, it is not 
enough to tell a programmer what you want NOW. You may get what you want fairly 
quickly but if you have ideas of possible extensions or future upgrades, it 
would be wiser to make clear some of the goals so the programmer creates an 
implementation that can be more easily adjusted to do more. Such code can take 
longer and be more complex so it may not pay off immediately.

But, having said that, plenty of software may benefit from looking at what is 
happening and adjusting on the fly. Clearly my client cannot know what feedback 
they may get when showing an actual result to others who then suggest changes 
or enhancements. The results may not be anticipated so well in advance and 
especially not when the client has no idea what is doable and so on. 

A related example was a request for how to modify a sort of Venn Diagram  chart 
to change the font size. Why? Because some of the labels were long and the 
relative sizes of the pie slices were not known till an analysis of the data 
produced the appropriate numbers and ratios. This was a case where the 
documentation of the function used by them did not suggest how to do many 
things as it called a function that called others to quite some depth. A few 
simple experiments and some guesses and exploration showed me ways to pass 
arguments along that were not documented but that were passed properly down the 
chain and I could now change the text size and quite a few other things. But I 
asked myself if this was really the right solution the client needed. I then 
made a guess on how I could get the long text wrapped into multiple lines that 
fit into the sections of the Venn Diagram without shrinking the text at all, or 
as much. The client had not considered that as an option, but it was better for 
their display than required. But until people see such output, unless they have 
lots of experience, it cannot be expected they can tell you up-front what they 
want.

One danger of languages like Python is that often people get the code you 
supply and modify it themselves or reuse it on some project they consider 
similar. That can be a good thing but often a mess as you wrote the code to do 
things in a specific way for a specific purpose ...


-Original Message-
From: 

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

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

On 6/8/2024 11:54 AM, Larry Martell via Python-list wrote:

On Sat, Jun 8, 2024 at 10:39 AM Mats Wichmann via Python-list <
python-list@python.org> wrote:


On 6/5/24 05:10, Thomas Passin via Python-list wrote:


Of course, we see this lack of clarity all the time in questions to the
list.  I often wonder how these askers can possibly come up with
acceptable code if they don't realize they don't truly know what it's
supposed to do.


Fortunately, having to explain to someone else why something is giving
you trouble can help shed light on the fact the problem statement isn't
clear, or isn't clearly understood. Sometimes (sadly, many times it
doesn't).



The original question struck me as homework or an interview question for a
junior position. But having no clear requirements or specifications is good
training for the real world where that is often the case. When you question
that, you are told to just do something, and then you’re told it’s not what
is wanted. That frustrates people but it’s often part of the process.
People need to see something to help them know what they really want.


At the extremes, there are two kinds of approaches you are alluding to. 
One is what I learned to call "rock management": "Bring me a rock ... 
no, that's not the right one, bring me another ... no that's not what 
I'm looking for, bring me another...".  If this is your situation, so, 
so sorry!


At the other end, there is a mutual evolution of the requirements 
because you and your client could not have known what they should be 
until you have spent effort and time feeling your way along.  With the 
right client and management, this kind of project can be a joy to work 
on.  I've been lucky enough to have worked on several projects of this kind.


In truth, there always are requirements.  Often (usually?) they are not 
thought out, not consistent, not articulated clearly, and not 
communicated well. They may live only in the mind of one person.


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


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

2024-06-08 Thread Larry Martell via Python-list
On Sat, Jun 8, 2024 at 10:39 AM Mats Wichmann via Python-list <
python-list@python.org> wrote:

> On 6/5/24 05:10, Thomas Passin via Python-list wrote:
>
> > Of course, we see this lack of clarity all the time in questions to the
> > list.  I often wonder how these askers can possibly come up with
> > acceptable code if they don't realize they don't truly know what it's
> > supposed to do.
>
> Fortunately, having to explain to someone else why something is giving
> you trouble can help shed light on the fact the problem statement isn't
> clear, or isn't clearly understood. Sometimes (sadly, many times it
> doesn't).


The original question struck me as homework or an interview question for a
junior position. But having no clear requirements or specifications is good
training for the real world where that is often the case. When you question
that, you are told to just do something, and then you’re told it’s not what
is wanted. That frustrates people but it’s often part of the process.
People need to see something to help them know what they really want.

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


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

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

On 6/5/24 05:10, Thomas Passin via Python-list wrote:

Of course, we see this lack of clarity all the time in questions to the 
list.  I often wonder how these askers can possibly come up with 
acceptable code if they don't realize they don't truly know what it's 
supposed to do.


Fortunately, having to explain to someone else why something is giving 
you trouble can help shed light on the fact the problem statement isn't 
clear, or isn't clearly understood. Sometimes (sadly, many times it 
doesn't).


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


[RELEASE] Python 3.12.4 released

2024-06-06 Thread Thomas Wouters via Python-list
Last minute bugs in test environments notwithstanding, 3.12.4 is now
available!
 https://www.python.org/downloads/release/python-3124/

This
is the third maintenance release of Python 3.12

Python 3.12 is the newest major release of the Python programming language,
and it contains many new features and optimizations. 3.12.4 is the latest
maintenance release, containing more than 250 bugfixes, build improvements
and documentation changes since 3.12.3.
Major
new features of the 3.12 series, compared to 3.11
New
features

   - More flexible f-string parsing
   
,
   allowing many things previously disallowed (PEP 701
   ).
   - Support for the buffer protocol
   

   in Python code (PEP 688 ).
   - A new debugging/profiling API
   

   (PEP 669 ).
   - Support for isolated subinterpreters
   

   with separate Global Interpreter Locks (PEP 684
   ).
   - Even more improved error messages
   .
   More exceptions potentially caused by typos now make suggestions to the
   user.
   - Support for the Linux perf profiler
    to report
   Python function names in traces.
   - Many large and small performance improvements
    (like PEP
   709  and support for the BOLT binary
   optimizer), delivering an estimated 5% overall performance improvement.

Type
annotations

   - New type annotation syntax
   

   for generic classes (PEP 695 ).
   - New override decorator
   

   for methods (PEP 698 ).


Deprecations

   - The deprecated wstr and wstr_length members of the C implementation of
   unicode objects were removed, per PEP 623
   .
   - In the unittest module, a number of long deprecated methods and
   classes were removed. (They had been deprecated since Python 3.1 or 3.2).
   - The deprecated smtpd and distutils modules have been removed (see PEP
   594  and PEP 632
   . The setuptools package continues to
   provide the distutils module.
   - A number of other old, broken and deprecated functions, classes and
   methods  have
   been removed.
   - Invalid backslash escape sequences in strings now warn with
   SyntaxWarning instead of DeprecationWarning, making them more visible.
   (They will become syntax errors in the future.)
   - The internal representation of integers has changed in preparation for
   performance enhancements. (This should not affect most users as it is an
   internal detail, but it may cause problems for Cython-generated code.)

For more details on the changes to Python 3.12, see What’s new in Python
3.12 .
More
resources

   - Online Documentation .
   - PEP 693 , the Python 3.12
   Release Schedule.
   - Report bugs via GitHub Issues
   .
   - Help fund Python directly
    or via GitHub Sponsors
   , and support the Python community
   .

Enjoy
the new releases

Thanks to all of the many volunteers who help make Python Development and
these releases possible! Please consider supporting our 

[RELEASE] Python 3.13.0 beta 2 released.

2024-06-06 Thread Thomas Wouters via Python-list
After a little bit of a delay (I blame the flat tire on my rental car),
3.13.0b2 is released:
 https://www.python.org/downloads/release/python-3130b2/


This
is a beta preview of Python 3.13

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

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

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

*Two particularly noteworthy changes in beta 2 involve the macOS installer
we provide:*

   - The minimum supported macOS version was changed from 10.9 to *10.13
   (High Sierra)*. Older macOS versions will not be supported going forward.
   - The macOS installer package now includes an optional additional build
   of Python 3.13 with the experimental free-threading feature enabled. The
   free-threaded version, python3.13t, is separate from and co-exists with the
   traditional GIL-only installation. The free-threaded build is not installed
   by default; use the Customize option of the installer as explained in the
   installer readme. Since this is an experimental feature, there may be
   late-breaking issues found; see the free-threaded macOS build issue
    on GitHub for the most
   recent status.

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

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

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

Typing

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

Removals
and new deprecations

   - PEP 594 (Removing dead batteries from the standard library)
    scheduled removals of many
   deprecated modules: aifc, audioop, chunk, cgi, cgitb, crypt, imghdr,
   mailcap, 

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

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

On 6/5/2024 12:33 AM, dn via Python-list wrote:

On 31/05/24 14:26, HenHanna via Python-list wrote:

On 5/30/2024 2:18 PM, dn wrote:

On 31/05/24 08:03, HenHanna via Python-list wrote:


Given a text file of a novel (JoyceUlysses.txt) ...

could someone give me a pretty fast (and simple) Python program 
that'd give me a list of all words occurring exactly once?


   -- Also, a list of words occurring once, twice or 3 
times




re: hyphenated words    (you can treat it anyway you like)

    but ideally, i'd treat  [editor-in-chief]
    [go-ahead]  [pen-knife]
    [know-how]  [far-fetched] ...
    as one unit.





Split into words - defined as you will.
Use Counter.

Show some (of your) code and we'll be happy to critique...



hard to decide what to do with hyphens
    and apostrophes
  (I'd,  he's,  can't, haven't,  A's  and  B's)


2-step-Process

   1. make a file listing all words (one word per line)

   2.  then, doing the counting.  using
   from collections import Counter



Apologies for lateness - only just able to come back to this.

This issue is not Python, and is not solved by code!

If you/your teacher can't define a "word", the code, any code, will 
almost-certainly be wrong!



One of the interesting aspects of our work is that we can write all 
manner of tests to try to ensure that the code is correct: unit tests, 
integration tests, system tests, acceptance tests, eye-tests, ...


However, there is no such thing as a test (or proof) that statements of 
requirements are complete or correct!

(nor for any other previous stages of the full project life-cycle)

As coders we need to learn to require clear specifications and not 
attempt to read-between-the-lines, use our initiative, or otherwise 'not 
bother the ...'. When there is ambiguity, we should go back to the 
user/client/boss and seek clarification. They are the 
domain/subject-matter experts...


I'm reminded of a cartoon, possibly from some IBM source, first seen in 
black-and-white but here in living-color: 
https://www.monolithic.org/blogs/presidents-sphere/what-the-customer-really-wants


That one's been kicking around for years ... good job in finding a link 
for it!


That has been the sad history of programming and dev.projects - wherein 
we are blamed for every short-coming, because no-one else understands 
the nuances of development projects.


Of course, we see this lack of clarity all the time in questions to the 
list.  I often wonder how these askers can possibly come up with 
acceptable code if they don't realize they don't truly know what it's 
supposed to do.



If we don't insist on clarity, are we our own worst enemy?




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


Re: Fwd: IDLE: clearing the screen

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



On 05/06/2024 04:09, Cameron Simpson wrote:

On 04Jun2024 22:43, Rob Cliffe  wrote:

import os
def cls(): x=os.system("cls")

Now whenever you type
cls()
it will clear the screen and show the prompt at the top of the screen.

(The reason for the "x=" is: os.system returns a result, in this case 
0.  When you evaluate an expression in the IDE, the IDE prints the 
result.  So without the "x=" you get an extra line at the top of the 
screen containing "0".)


Not if it's in a function, because the IDLE prints the result if it 
isn't None, and your function returns None. So:


    def cls():
    os.system("cls")

should be just fine.


Yes, you're right.
Rob Cliffe

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


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

2024-06-05 Thread Grant Edwards via Python-list
On 2024-06-05, dn via Python-list  wrote:

> If you/your teacher can't define a "word", the code, any code, will 
> almost-certainly be wrong!

Back when I was a student...

When there was a homework/project assignemnt with a vague requirement
(and it wasn't practical to get the requirement refined), what always
worked for me was to put in the project report or program comments or
somewhere a statement that the requirement could be interpreted in
different ways and here is the precise interpretation of the
requirement that is being implemented.



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


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

2024-06-04 Thread dn via Python-list

On 31/05/24 14:26, HenHanna via Python-list wrote:

On 5/30/2024 2:18 PM, dn wrote:

On 31/05/24 08:03, HenHanna via Python-list wrote:


Given a text file of a novel (JoyceUlysses.txt) ...

could someone give me a pretty fast (and simple) Python program 
that'd give me a list of all words occurring exactly once?


   -- Also, a list of words occurring once, twice or 3 times



re: hyphenated words    (you can treat it anyway you like)

    but ideally, i'd treat  [editor-in-chief]
    [go-ahead]  [pen-knife]
    [know-how]  [far-fetched] ...
    as one unit.





Split into words - defined as you will.
Use Counter.

Show some (of your) code and we'll be happy to critique...



hard to decide what to do with hyphens
    and apostrophes
  (I'd,  he's,  can't, haven't,  A's  and  B's)


2-step-Process

   1. make a file listing all words (one word per line)

   2.  then, doing the counting.  using
   from collections import Counter



Apologies for lateness - only just able to come back to this.

This issue is not Python, and is not solved by code!

If you/your teacher can't define a "word", the code, any code, will 
almost-certainly be wrong!



One of the interesting aspects of our work is that we can write all 
manner of tests to try to ensure that the code is correct: unit tests, 
integration tests, system tests, acceptance tests, eye-tests, ...


However, there is no such thing as a test (or proof) that statements of 
requirements are complete or correct!

(nor for any other previous stages of the full project life-cycle)

As coders we need to learn to require clear specifications and not 
attempt to read-between-the-lines, use our initiative, or otherwise 'not 
bother the ...'. When there is ambiguity, we should go back to the 
user/client/boss and seek clarification. They are the 
domain/subject-matter experts...


I'm reminded of a cartoon, possibly from some IBM source, first seen in 
black-and-white but here in living-color: 
https://www.monolithic.org/blogs/presidents-sphere/what-the-customer-really-wants


That has been the sad history of programming and dev.projects - wherein 
we are blamed for every short-coming, because no-one else understands 
the nuances of development projects.


If we don't insist on clarity, are we our own worst enemy?


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


Re: Fwd: IDLE: clearing the screen

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

On 04Jun2024 22:43, Rob Cliffe  wrote:

import os
def cls(): x=os.system("cls")

Now whenever you type
cls()
it will clear the screen and show the prompt at the top of the screen.

(The reason for the "x=" is: os.system returns a result, in this case 
0.  When you evaluate an expression in the IDE, the IDE prints the 
result.  So without the "x=" you get an extra line at the top of the 
screen containing "0".)


Not if it's in a function, because the IDLE prints the result if it 
isn't None, and your function returns None. So:


def cls():
os.system("cls")

should be just fine.
--
https://mail.python.org/mailman/listinfo/python-list


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

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

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

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

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


Fwd: IDLE: clearing the screen

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

Welcome to Python!  A great language for program development.

Answers might be platform-dependent (are you using WIndows, Linux, etc.).
However, the following works for me on WIndows.  You can put it in the 
startup.py file so you don't have to type it every time you start up the 
IDLE.


import os
def cls(): x=os.system("cls")

Now whenever you type
cls()
it will clear the screen and show the prompt at the top of the screen.

(The reason for the "x=" is: os.system returns a result, in this case 
0.  When you evaluate an expression in the IDE, the IDE prints the 
result.  So without the "x=" you get an extra line at the top of the 
screen containing "0".)


I am sure that some jiggery-pokery could be used so you don't have to 
type the "()".  But that's more advanced ...


Best wishes
Rob Cliffe


On 04/06/2024 14:34, Cave Man via Python-list wrote:

Hello everyone,

I am  new to Python, and I have been using IDLE (v3.10.11) to run 
small Python code. However, I have seen that the output scrolls to the 
bottom in the output window.


Is there a way to clear the output window (something like cls in 
command prompt or clear in terminal), so that output stays at the top?



Thanks in anticipation!


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


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

2024-06-04 Thread AVI GROSS via Python-list
>> Well.when using the file linux.words as a useful master list of
>> "words".linux.words is strict ASCII

The meaning of "words" depends on the context. The contents of the file
mentioned are a minor attempt to capture a common subset of words in English
but probably are not what you mean by words in other contexts including
words also in ASCII format  like names and especially uncommon names or
words like UNESCO. There are other selected lists of words such as valid
Scrabble words or WORLDLE words for specialized purposes that exclude words
of lengths that can not be used. The person looking to count words in a work
must determine what words make sense for their purpose.

ASCII is a small subset of UNICODE. So when using a concept of word that
includes many characters from many character sets, and in many languages,
things may not be easy to parse uniquely such as words containing something
like an apostrophe earlier on as in d'eau. Words can flow in different
directions. There can be fairly complex rules and sometimes things like
compound words may need to be considered to either be one or multiple words
and may even occur both ways in the same work so is every body the same as
everybody?

So what is being discussed here may have several components. One is to
tokenize all the text to make a set of categories. Another is to count them.
Perhaps another might even analyze and combine multiple categories or even
look at words in context to determine if two uses of the same word are
different enough to try to keep both apart in two categories Is polish the
same as Polish?

Once that is decided, you have a fairly simple exercise in storing the data
in a searchable data structure and doing your searches to get subsets and
counts and so on.

As mentioned, the default native format in Python is UNICODE and ASCII files
being read in may well be UNICODE internally unless you carefully ask
otherwise. The conversion from ASCII to UNICODE is trivial. 

As for how well the regular expressions like \w work in general, I have no
idea. I can be very sure they are way more costly than the simpler ones you
can write that just know enough about what English words in ASCII look like
and perhaps get it wrong on some edge cases.


-Original Message-
From: Python-list  On
Behalf Of Edward Teach via Python-list
Sent: Tuesday, June 4, 2024 7:22 AM
To: python-list@python.org
Subject: Re: From JoyceUlysses.txt -- words occurring exactly once

On Mon, 03 Jun 2024 14:58:26 -0400 (EDT)
Grant Edwards  wrote:

> On 2024-06-03, Edward Teach via Python-list 
> wrote:
> 
> > The Gutenburg Project publishes "plain text".  That's another
> > problem, because "plain text" means UTF-8and that means
> > unicode...and that means running some sort of unicode-to-ascii
> > conversion in order to get something like "words".  A couple of
> > hoursa couple of hundred lines of Cproblem solved!  
> 
> I'm curious.  Why does it need to be converted frum Unicode to ASCII?
> 
> When you read it into Python, it gets converted right back to
> Unicode...
> 
> 
> 

Well.when using the file linux.words as a useful master list of
"words".linux.words is strict ASCII

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

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


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

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

> Well.when using the file linux.words as a useful master list of
> "words".linux.words is strict ASCII

I guess I missed the part of the problem description where it said to
use linux.words to decide what a word is. :)

--
Grant


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


IDLE: clearing the screen

2024-06-04 Thread Cave Man via Python-list

Hello everyone,

I am  new to Python, and I have been using IDLE (v3.10.11) to run small 
Python code. However, I have seen that the output scrolls to the bottom 
in the output window.


Is there a way to clear the output window (something like cls in command 
prompt or clear in terminal), so that output stays at the top?



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


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

2024-06-04 Thread Edward Teach via Python-list
On Mon, 03 Jun 2024 14:58:26 -0400 (EDT)
Grant Edwards  wrote:

> On 2024-06-03, Edward Teach via Python-list 
> wrote:
> 
> > The Gutenburg Project publishes "plain text".  That's another
> > problem, because "plain text" means UTF-8and that means
> > unicode...and that means running some sort of unicode-to-ascii
> > conversion in order to get something like "words".  A couple of
> > hoursa couple of hundred lines of Cproblem solved!  
> 
> I'm curious.  Why does it need to be converted frum Unicode to ASCII?
> 
> When you read it into Python, it gets converted right back to
> Unicode...
> 
> 
> 

Well.when using the file linux.words as a useful master list of
"words".linux.words is strict ASCII

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


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

2024-06-04 Thread Dieter Maurer via Python-list
Edward Teach wrote at 2024-6-3 10:47 +0100:
> ...
>The Gutenburg Project publishes "plain text".  That's another problem,
>because "plain text" means UTF-8and that means unicode...and that
>means running some sort of unicode-to-ascii conversion in order to get
>something like "words".  A couple of hoursa couple of hundred lines
>of Cproblem solved!

Unicode supports the notion "owrd" even better "ASCII".
For example, the `\w` (word charavter) regular expression wild card,
works for Unicode like for ASCII (of course with enhanced letter,
digits, punctuation, etc.)
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2024-06-03 Thread Grant Edwards via Python-list
On 2024-06-03, Edward Teach via Python-list  wrote:

> The Gutenburg Project publishes "plain text".  That's another
> problem, because "plain text" means UTF-8and that means
> unicode...and that means running some sort of unicode-to-ascii
> conversion in order to get something like "words".  A couple of
> hoursa couple of hundred lines of Cproblem solved!

I'm curious.  Why does it need to be converted frum Unicode to ASCII?

When you read it into Python, it gets converted right back to Unicode...



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


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

2024-06-03 Thread Edward Teach via Python-list
On Sat, 1 Jun 2024 13:34:11 -0600
Mats Wichmann  wrote:

> On 5/31/24 11:59, Dieter Maurer via Python-list wrote:
> 
> hmmm, I "sent" this but there was some problem and it remained
> unsent. Just in case it hasn't All Been Said Already, here's the
> retry:
> 
> > HenHanna wrote at 2024-5-30 13:03 -0700:  
> >>
> >> Given a text file of a novel (JoyceUlysses.txt) ...
> >>
> >> could someone give me a pretty fast (and simple) Python program
> >> that'd give me a list of all words occurring exactly once?  
> > 
> > Your task can be split into several subtasks:
> >   * parse the text into words
> > 
> > This depends on your notion of "word".
> > In the simplest case, a word is any maximal sequence of
> > non-whitespace characters. In this case, you can use `split` for
> > this task  
> 
> This piece is by far "the hard part", because of the ambiguity. For 
> example, if I just say non-whitespace, then I get as distinct words 
> followed by punctuation. What about hyphenation - of which there's
> both the compound word forms and the ones at the end of lines if the
> source text has been formatted that way.  Are all-lowercase words
> different than the same word starting with a capital?  What about
> non-initial capitals, as happens a fair bit in modern usage with
> acronyms, trademarks (perhaps not in Ulysses? :-) ), etc. What about
> accented letters?
> 
> If you want what's at least a quick starting point to play with, you 
> could use a very simple regex - a fair amount of thought has gone
> into what a "word character" is (\w), so it deals with excluding both 
> punctuation and whitespace.
> 
> import re
> from collections import Counter
> 
> with open("JoyceUlysses/txt", "r") as f:
>  wordcount = Counter(re.findall(r'\w+', f.read().lower()))
> 
> Now you have a Counter object counting all the "words" with their 
> occurrence counts (by this definition) in the document. You can fish 
> through that to answer the questions asked (find entries with a count
> of 1, 2, 3, etc.)
> 
> Some people Go Big and use something that actually tries to recognize 
> the language, and opposed to making assumptions from ranges of 
> characters.  nltk is a choice there.  But at this point it's not
> really "simple" any longer (though nltk experts might end up
> disagreeing with that).
> 
> 

The Gutenburg Project publishes "plain text".  That's another problem,
because "plain text" means UTF-8and that means unicode...and that
means running some sort of unicode-to-ascii conversion in order to get
something like "words".  A couple of hoursa couple of hundred lines
of Cproblem solved!

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


Cannot install python properly - python310.dll not found - no pip

2024-06-03 Thread Jay Cadet | Studio JPC via Python-list
Hi. I'm attempting to install and use stable diffusion. However, while 
installing python 3.10.6, I'm getting the error that the python 310.dll is not 
found. I've made sure the PATH option is enabled, but it makes no difference. 
I've also removed and reinstalled python multiple times.

Even though I get that error, the python still installs, but when I open the 
webui-user.bat file in the stable diffusion folder, it opens up the command 
center and says that there's no module named pip.

Please advise on how to fix this problem.

Thank you,

Jay Cadet

Architectural 3D Artist / Photographer
studio JPC
[p] 516.567.1996  | [w] studiojpc.com  | [ig] @studiojpc
-- 
https://mail.python.org/mailman/listinfo/python-list


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

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

On 5/31/24 11:59, Dieter Maurer via Python-list wrote:

hmmm, I "sent" this but there was some problem and it remained unsent. 
Just in case it hasn't All Been Said Already, here's the retry:



HenHanna wrote at 2024-5-30 13:03 -0700:


Given a text file of a novel (JoyceUlysses.txt) ...

could someone give me a pretty fast (and simple) Python program that'd
give me a list of all words occurring exactly once?


Your task can be split into several subtasks:
  * parse the text into words

This depends on your notion of "word".
In the simplest case, a word is any maximal sequence of non-whitespace
characters. In this case, you can use `split` for this task


This piece is by far "the hard part", because of the ambiguity. For 
example, if I just say non-whitespace, then I get as distinct words 
followed by punctuation. What about hyphenation - of which there's both 
the compound word forms and the ones at the end of lines if the source 
text has been formatted that way.  Are all-lowercase words different 
than the same word starting with a capital?  What about non-initial 
capitals, as happens a fair bit in modern usage with acronyms, 
trademarks (perhaps not in Ulysses? :-) ), etc. What about accented letters?


If you want what's at least a quick starting point to play with, you 
could use a very simple regex - a fair amount of thought has gone into 
what a "word character" is (\w), so it deals with excluding both 
punctuation and whitespace.


import re
from collections import Counter

with open("JoyceUlysses/txt", "r") as f:
wordcount = Counter(re.findall(r'\w+', f.read().lower()))

Now you have a Counter object counting all the "words" with their 
occurrence counts (by this definition) in the document. You can fish 
through that to answer the questions asked (find entries with a count of 
1, 2, 3, etc.)


Some people Go Big and use something that actually tries to recognize 
the language, and opposed to making assumptions from ranges of 
characters.  nltk is a choice there.  But at this point it's not really 
"simple" any longer (though nltk experts might end up disagreeing with 
that).



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


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

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

On 6/1/2024 4:04 AM, Peter J. Holzer via Python-list wrote:

On 2024-05-30 19:26:37 -0700, HenHanna via Python-list wrote:

hard to decide what to do with hyphens
and apostrophes
  (I'd,  he's,  can't, haven't,  A's  and  B's)


Especially since the same character is used as both an apostrophe and a
closing quotation mark. And while that's pretty unambiguous between to
characters it isn't at the end of a word:

 This is Alex’ house.
 This type of building is called an ‘Alex’ house.
 The sentence ‘We are meeting at Alex’ house’ contains an apostrophe.

(using proper unicode quotation marks. It get's worse if you stick to
ASCII.)

Personally I like to use U+0027 APOSTROPHE as an apostrophe and U+2018
LEFT SINGLE QUOTATION MARK and U+2019 RIGHT SINGLE QUOTATION MARK as
single quotation marks[1], but despite the suggestive names, this is not
the common typographical convention, so your texts are unlikely to make
this distinction.

 hp

[1] Which I use rarely, anyway.


My usual approach is to replace punctuation by spaces and then to 
discard anything remaining that is only one character long (or sometimes 
two, depending on what I'm working on).  Yes, OK, I will miss words like 
"I". Usually I don't care about them. Make exceptions to the policy if 
you like.


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


Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )

2024-06-01 Thread Peter J. Holzer via Python-list
On 2024-05-30 21:47:14 -0700, HenHanna via Python-list wrote:
> [('the', 36225), ('and', 17551), ('of', 16759), ('i', 16696), ('a', 15816),
> ('to', 15722), ('that', 11252), ('in', 10743), ('it', 10687)]
> 
> ((the 36225) (and 17551) (of 16759) (i 16696) (a 15816) (to 15722) (that
> 11252) (in 10743) (it 10687))
> 
> 
> i think the latter is easier-to-read, so i use this code
>(by Peter Norvig)

This doesn't work well if your strings contain spaces:

Lprint(
[
["Just", "three", "words"],
["Just", "three words"],
["Just three", "words"],
["Just three words"],
]
)

prints:

((Just three words) (Just three words) (Just three words) (Just three words))

Output is often a compromise between readability and precision.


> def lispstr(exp):
># "Convert a Python object back into a Lisp-readable string."
> if isinstance(exp, list):

This won't work for your example, since you have a list of tuples, not a
list of lists and a tuple is not an instance of a list.

> return '(' + ' '.join(map(lispstr, exp)) + ')'
> else:
> return str(exp)
> 
> def Lprint(x): print(lispstr(x))

I like to use pprint, but it's lacking support for user-defined types. I
should be able to add a method (maybe __pprint__?) to my classes which
handle proper formatting (with line breaks and indentation).

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: From JoyceUlysses.txt -- words occurring exactly once

2024-06-01 Thread Peter J. Holzer via Python-list
On 2024-05-30 19:26:37 -0700, HenHanna via Python-list wrote:
> hard to decide what to do with hyphens
>and apostrophes
>  (I'd,  he's,  can't, haven't,  A's  and  B's)

Especially since the same character is used as both an apostrophe and a
closing quotation mark. And while that's pretty unambiguous between to
characters it isn't at the end of a word:

This is Alex’ house.
This type of building is called an ‘Alex’ house.
The sentence ‘We are meeting at Alex’ house’ contains an apostrophe.

(using proper unicode quotation marks. It get's worse if you stick to
ASCII.)

Personally I like to use U+0027 APOSTROPHE as an apostrophe and U+2018
LEFT SINGLE QUOTATION MARK and U+2019 RIGHT SINGLE QUOTATION MARK as
single quotation marks[1], but despite the suggestive names, this is not
the common typographical convention, so your texts are unlikely to make
this distinction.

hp

[1] Which I use rarely, anyway.

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


  1   2   3   4   5   6   7   8   9   10   >