From hjp-python at hjp.at Sat Jun 1 04:04:29 2024 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 1 Jun 2024 10:04:29 +0200 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: References: Message-ID: <20240601080429.ygyg75jzdoxdofa2@hjp.at> 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. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From hjp-python at hjp.at Sat Jun 1 04:24:14 2024 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 1 Jun 2024 10:24:14 +0200 Subject: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python ) In-Reply-To: References: Message-ID: <20240601082414.zmn5vpklreqrnirr@hjp.at> 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. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From list1 at tompassin.net Sat Jun 1 09:38:51 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 1 Jun 2024 09:38:51 -0400 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: <20240601080429.ygyg75jzdoxdofa2@hjp.at> References: <20240601080429.ygyg75jzdoxdofa2@hjp.at> Message-ID: 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. From mats at wichmann.us Sat Jun 1 15:34:11 2024 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 1 Jun 2024 13:34:11 -0600 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: <26202.4083.590062.42312@ixdm.fritz.box> References: <26202.4083.590062.42312@ixdm.fritz.box> Message-ID: <32b20599-1cf1-4aeb-904b-b9afa3dea3a3@wichmann.us> 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). From hackbeard at linuxmail.org Mon Jun 3 05:47:42 2024 From: hackbeard at linuxmail.org (Edward Teach) Date: Mon, 3 Jun 2024 10:47:42 +0100 Subject: From JoyceUlysses.txt -- words occurring exactly once References: <26202.4083.590062.42312@ixdm.fritz.box> <32b20599-1cf1-4aeb-904b-b9afa3dea3a3@wichmann.us> Message-ID: <20240603104742.1664b37c@fedora> 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-8....and that means unicode...and that means running some sort of unicode-to-ascii conversion in order to get something like "words". A couple of hours....a couple of hundred lines of C....problem solved! From grant.b.edwards at gmail.com Mon Jun 3 14:58:26 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 03 Jun 2024 14:58:26 -0400 (EDT) Subject: From JoyceUlysses.txt -- words occurring exactly once References: <26202.4083.590062.42312@ixdm.fritz.box> <32b20599-1cf1-4aeb-904b-b9afa3dea3a3@wichmann.us> <20240603104742.1664b37c@fedora> Message-ID: <4VtNKZ70YdznVGW@mail.python.org> 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-8....and that means > unicode...and that means running some sort of unicode-to-ascii > conversion in order to get something like "words". A couple of > hours....a couple of hundred lines of C....problem 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... From dieter.maurer at online.de Tue Jun 4 12:13:47 2024 From: dieter.maurer at online.de (dieter.maurer at online.de) Date: Tue, 4 Jun 2024 18:13:47 +0200 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: <20240603104742.1664b37c@fedora> References: <26202.4083.590062.42312@ixdm.fritz.box> <32b20599-1cf1-4aeb-904b-b9afa3dea3a3@wichmann.us> <20240603104742.1664b37c@fedora> Message-ID: <26207.15675.710915.692146@ixdm.fritz.box> 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-8....and that means unicode...and that >means running some sort of unicode-to-ascii conversion in order to get >something like "words". A couple of hours....a couple of hundred lines >of C....problem 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.) From hackbeard at linuxmail.org Tue Jun 4 07:21:34 2024 From: hackbeard at linuxmail.org (Edward Teach) Date: Tue, 4 Jun 2024 12:21:34 +0100 Subject: From JoyceUlysses.txt -- words occurring exactly once References: <26202.4083.590062.42312@ixdm.fritz.box> <32b20599-1cf1-4aeb-904b-b9afa3dea3a3@wichmann.us> <20240603104742.1664b37c@fedora> <4VtNKZ70YdznVGW@mail.python.org> Message-ID: <20240604122134.2696c36d@fedora> 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-8....and that means > > unicode...and that means running some sort of unicode-to-ascii > > conversion in order to get something like "words". A couple of > > hours....a couple of hundred lines of C....problem 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........ From caveman at example.invalid Tue Jun 4 09:34:17 2024 From: caveman at example.invalid (Cave Man) Date: Tue, 4 Jun 2024 19:04:17 +0530 Subject: IDLE: clearing the screen Message-ID: 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! From grant.b.edwards at gmail.com Tue Jun 4 13:05:10 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 04 Jun 2024 13:05:10 -0400 (EDT) Subject: From JoyceUlysses.txt -- words occurring exactly once References: <26202.4083.590062.42312@ixdm.fritz.box> <32b20599-1cf1-4aeb-904b-b9afa3dea3a3@wichmann.us> <20240603104742.1664b37c@fedora> <4VtNKZ70YdznVGW@mail.python.org> <20240604122134.2696c36d@fedora> Message-ID: <4VtxmQ15hSznVHV@mail.python.org> 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-8....and that means >> > unicode...and that means running some sort of unicode-to-ascii >> > conversion in order to get something like "words". A couple of >> > hours....a couple of hundred lines of C....problem 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 From avi.e.gross at gmail.com Tue Jun 4 17:30:47 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Tue, 4 Jun 2024 17:30:47 -0400 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: <20240604122134.2696c36d@fedora> References: <26202.4083.590062.42312@ixdm.fritz.box> <32b20599-1cf1-4aeb-904b-b9afa3dea3a3@wichmann.us> <20240603104742.1664b37c@fedora> <4VtNKZ70YdznVGW@mail.python.org> <20240604122134.2696c36d@fedora> Message-ID: <008a01dab6c6$77557500$66005f00$@gmail.com> >> 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 at 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-8....and that means > > unicode...and that means running some sort of unicode-to-ascii > > conversion in order to get something like "words". A couple of > > hours....a couple of hundred lines of C....problem 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 From rob.cliffe at btinternet.com Tue Jun 4 17:43:14 2024 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Tue, 4 Jun 2024 22:43:14 +0100 Subject: Fwd: IDLE: clearing the screen In-Reply-To: References: Message-ID: <0b2a163c-6e83-4739-960d-35a038d4ff0b@btinternet.com> 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! From rosuav at gmail.com Tue Jun 4 18:02:26 2024 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Jun 2024 08:02:26 +1000 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: <20240604122134.2696c36d@fedora> References: <26202.4083.590062.42312@ixdm.fritz.box> <32b20599-1cf1-4aeb-904b-b9afa3dea3a3@wichmann.us> <20240603104742.1664b37c@fedora> <4VtNKZ70YdznVGW@mail.python.org> <20240604122134.2696c36d@fedora> Message-ID: 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-8....and that means > > > unicode...and that means running some sort of unicode-to-ascii > > > conversion in order to get something like "words". A couple of > > > hours....a couple of hundred lines of C....problem 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 From cs at cskk.id.au Tue Jun 4 23:09:29 2024 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 5 Jun 2024 13:09:29 +1000 Subject: Fwd: IDLE: clearing the screen In-Reply-To: <0b2a163c-6e83-4739-960d-35a038d4ff0b@btinternet.com> References: <0b2a163c-6e83-4739-960d-35a038d4ff0b@btinternet.com> Message-ID: 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. From PythonList at DancesWithMice.info Wed Jun 5 00:33:15 2024 From: PythonList at DancesWithMice.info (dn) Date: Wed, 5 Jun 2024 16:33:15 +1200 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: References: Message-ID: <3dedbc3b-7db0-4a39-863f-56324d434b12@DancesWithMice.info> 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 From grant.b.edwards at gmail.com Wed Jun 5 11:24:32 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 05 Jun 2024 11:24:32 -0400 (EDT) Subject: From JoyceUlysses.txt -- words occurring exactly once References: <3dedbc3b-7db0-4a39-863f-56324d434b12@DancesWithMice.info> Message-ID: <4VvWTr6YX0znVFD@mail.python.org> 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. From rob.cliffe at btinternet.com Wed Jun 5 18:16:13 2024 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Wed, 5 Jun 2024 23:16:13 +0100 Subject: Fwd: IDLE: clearing the screen In-Reply-To: References: <0b2a163c-6e83-4739-960d-35a038d4ff0b@btinternet.com> Message-ID: <2267f36e-bdd5-4089-921e-4664421d5bbd@btinternet.com> 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 From list1 at tompassin.net Wed Jun 5 07:10:19 2024 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 5 Jun 2024 07:10:19 -0400 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: <3dedbc3b-7db0-4a39-863f-56324d434b12@DancesWithMice.info> References: <3dedbc3b-7db0-4a39-863f-56324d434b12@DancesWithMice.info> Message-ID: <8409fd89-8b42-43c4-8511-704d57b3a4be@tompassin.net> 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? > > From thomas at python.org Thu Jun 6 21:53:55 2024 From: thomas at python.org (Thomas Wouters) Date: Fri, 7 Jun 2024 03:53:55 +0200 Subject: [RELEASE] Python 3.13.0 beta 2 released. Message-ID: 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, msilib, nis, nntplib, ossaudiodev, pipes, sndhdr, spwd, sunau, telnetlib, uu, xdrlib, lib2to3. - Many other removals of deprecated classes, functions and methods in various standard library modules. - C API removals and deprecations . (Some removals present in alpha 1 were reverted in alpha 2, as the removals were deemed too disruptive at this time.) - New deprecations , most of which are scheduled for removal from Python 3.15 or 3.16. (Hey, *fellow core developer,* if a feature you find important is missing from this list, let Thomas know .) For more details on the changes to Python 3.13, see What?s new in Python 3.13 . The next pre-release of Python 3.13 will be 3.13.0b3, currently scheduled for 2024-06-25. More resources - Online Documentation - PEP 719 , 3.13 Release Schedule - Report bugs at Issues ? python/cpython ? GitHub . - 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 efforts by volunteering yourself or through organization contributions to the Python Software Foundation. Regards from *scorchingly* sunny Sunnyvale (hey, the name fits!), Your release team, Thomas Wouters @thomas ?ukasz Langa @ambv Ned Deily @nad Steve Dower @steve.dower From thomas at python.org Thu Jun 6 21:55:07 2024 From: thomas at python.org (Thomas Wouters) Date: Fri, 7 Jun 2024 03:55:07 +0200 Subject: [RELEASE] Python 3.12.4 released Message-ID: 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 efforts by volunteering yourself or through organization contributions to the Python Software Foundation. Regards from still quite sunny Sunnyvale, Your release team, Thomas Wouters @thomas ?ukasz Langa @ambv Ned Deily @nad Steve Dower @steve.dower From mats at wichmann.us Fri Jun 7 10:37:07 2024 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 7 Jun 2024 08:37:07 -0600 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: <8409fd89-8b42-43c4-8511-704d57b3a4be@tompassin.net> References: <3dedbc3b-7db0-4a39-863f-56324d434b12@DancesWithMice.info> <8409fd89-8b42-43c4-8511-704d57b3a4be@tompassin.net> Message-ID: <2f37a78b-0757-4e1a-860a-9fe3f86200cf@wichmann.us> 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). From larry.martell at gmail.com Sat Jun 8 11:54:07 2024 From: larry.martell at gmail.com (Larry Martell) Date: Sat, 8 Jun 2024 10:54:07 -0500 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: <2f37a78b-0757-4e1a-860a-9fe3f86200cf@wichmann.us> References: <3dedbc3b-7db0-4a39-863f-56324d434b12@DancesWithMice.info> <8409fd89-8b42-43c4-8511-704d57b3a4be@tompassin.net> <2f37a78b-0757-4e1a-860a-9fe3f86200cf@wichmann.us> Message-ID: On Sat, Jun 8, 2024 at 10:39?AM Mats Wichmann via Python-list < python-list at 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. > From list1 at tompassin.net Sat Jun 8 13:10:13 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 8 Jun 2024 13:10:13 -0400 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: References: <3dedbc3b-7db0-4a39-863f-56324d434b12@DancesWithMice.info> <8409fd89-8b42-43c4-8511-704d57b3a4be@tompassin.net> <2f37a78b-0757-4e1a-860a-9fe3f86200cf@wichmann.us> Message-ID: 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 at 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. From avi.e.gross at gmail.com Sat Jun 8 14:46:43 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 8 Jun 2024 14:46:43 -0400 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: References: <3dedbc3b-7db0-4a39-863f-56324d434b12@DancesWithMice.info> <8409fd89-8b42-43c4-8511-704d57b3a4be@tompassin.net> <2f37a78b-0757-4e1a-860a-9fe3f86200cf@wichmann.us> Message-ID: <005b01dab9d4$350d7290$9f2857b0$@gmail.com> 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: Python-list On Behalf Of Thomas Passin via Python-list Sent: Saturday, June 8, 2024 1:10 PM To: python-list at python.org Subject: Re: From JoyceUlysses.txt -- words occurring exactly once 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 at 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 From rob.cliffe at btinternet.com Sat Jun 8 15:18:16 2024 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Sat, 8 Jun 2024 20:18:16 +0100 Subject: IDLE: clearing the screen Message-ID: <66670225-276b-48cf-b271-6962daef903b@btinternet.com> 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 From list1 at tompassin.net Sat Jun 8 15:41:03 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 8 Jun 2024 15:41:03 -0400 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: <005b01dab9d4$350d7290$9f2857b0$@gmail.com> References: <3dedbc3b-7db0-4a39-863f-56324d434b12@DancesWithMice.info> <8409fd89-8b42-43c4-8511-704d57b3a4be@tompassin.net> <2f37a78b-0757-4e1a-860a-9fe3f86200cf@wichmann.us> <005b01dab9d4$350d7290$9f2857b0$@gmail.com> Message-ID: On 6/8/2024 2:46 PM, avi.e.gross at 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? 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: Python-list On Behalf Of Thomas Passin via Python-list > Sent: Saturday, June 8, 2024 1:10 PM > To: python-list at python.org > Subject: Re: From JoyceUlysses.txt -- words occurring exactly once > > 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 at 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. > From avi.e.gross at gmail.com Sat Jun 8 18:07:07 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 8 Jun 2024 18:07:07 -0400 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: References: <3dedbc3b-7db0-4a39-863f-56324d434b12@DancesWithMice.info> <8409fd89-8b42-43c4-8511-704d57b3a4be@tompassin.net> <2f37a78b-0757-4e1a-860a-9fe3f86200cf@wichmann.us> Message-ID: <007201dab9f0$342b8d50$9c82a7f0$@gmail.com> 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 at 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 at 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 From grant.b.edwards at gmail.com Sat Jun 8 21:51:09 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 08 Jun 2024 21:51:09 -0400 (EDT) Subject: From JoyceUlysses.txt -- words occurring exactly once References: <3dedbc3b-7db0-4a39-863f-56324d434b12@DancesWithMice.info> <8409fd89-8b42-43c4-8511-704d57b3a4be@tompassin.net> <2f37a78b-0757-4e1a-860a-9fe3f86200cf@wichmann.us> Message-ID: <4VxdFT4zZtznVFy@mail.python.org> 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. From learn2program at gmail.com Sun Jun 9 14:06:07 2024 From: learn2program at gmail.com (Alan Gauld) Date: Sun, 9 Jun 2024 19:06:07 +0100 Subject: IDLE: clearing the screen In-Reply-To: <66670225-276b-48cf-b271-6962daef903b@btinternet.com> References: <66670225-276b-48cf-b271-6962daef903b@btinternet.com> Message-ID: <532f6235-300a-40a3-85ca-12e573243090@yahoo.co.uk> 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 From HenHanna at devnull.tb Sun Jun 9 17:20:20 2024 From: HenHanna at devnull.tb (HenHanna) Date: Sun, 9 Jun 2024 14:20:20 -0700 Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3)) Message-ID: 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)) From python at mrabarnett.plus.com Sun Jun 9 18:50:26 2024 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 9 Jun 2024 23:50:26 +0100 Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3)) In-Reply-To: References: Message-ID: 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. From avi.e.gross at gmail.com Sun Jun 9 19:30:02 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sun, 9 Jun 2024 19:30:02 -0400 Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3)) In-Reply-To: References: Message-ID: <00a801dabac4$f3d463f0$db7d2bd0$@gmail.com> 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 at 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 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 From avi.e.gross at gmail.com Sun Jun 9 22:05:33 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sun, 9 Jun 2024 22:05:33 -0400 Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3)) In-Reply-To: References: Message-ID: <010f01dabada$ad867d00$08937700$@gmail.com> 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 at 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 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 From HenHanna at devnull.tb Sun Jun 9 19:16:27 2024 From: HenHanna at devnull.tb (HenHanna) Date: Sun, 9 Jun 2024 16:16:27 -0700 Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3)) In-Reply-To: References: Message-ID: 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 '(a b b a a a b b b b))) (print (gp '(c c c a d d d d a e e e e e))) From HenHanna at devnull.tb Sun Jun 9 22:36:39 2024 From: HenHanna at devnull.tb (HenHanna) Date: Sun, 9 Jun 2024 19:36:39 -0700 Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3)) In-Reply-To: References: <010f01dabada$ad867d00$08937700$@gmail.com> Message-ID: On 6/9/2024 7:05 PM, avi.e.gross at 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 at 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 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)) 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 '(a b b a 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 '(a b b a a a b b b b))) (print (gpC '(c c c a d d d d a e e e e e))) From michael.stemper at gmail.com Mon Jun 10 09:55:20 2024 From: michael.stemper at gmail.com (Michael F. Stemper) Date: Mon, 10 Jun 2024 08:55:20 -0500 Subject: IDLE: clearing the screen In-Reply-To: References: <66670225-276b-48cf-b271-6962daef903b@btinternet.com> Message-ID: 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. From michael.stemper at gmail.com Mon Jun 10 11:49:42 2024 From: michael.stemper at gmail.com (Michael F. Stemper) Date: Mon, 10 Jun 2024 10:49:42 -0500 Subject: IDLE: clearing the screen In-Reply-To: References: <66670225-276b-48cf-b271-6962daef903b@btinternet.com> Message-ID: 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. From avi.e.gross at gmail.com Mon Jun 10 14:07:38 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Mon, 10 Jun 2024 14:07:38 -0400 Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3)) In-Reply-To: References: <010f01dabada$ad867d00$08937700$@gmail.com> Message-ID: <00b901dabb61$1428a200$3c79e600$@gmail.com> > 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 at 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.gross at 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 at 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 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)) 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 '(a b b a 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 '(a b b a 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 From rob.cliffe at btinternet.com Mon Jun 10 09:29:08 2024 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 10 Jun 2024 14:29:08 +0100 Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3)) In-Reply-To: References: Message-ID: <91823458-bc96-4725-8d9e-35c9c687c5d2@btinternet.com> 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='aaabbccccaa' print(chunk1(s)) print(chunk2(s)) ################################### Program output: ['aaa', 'bb', 'cccc', '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)) From avi.e.gross at gmail.com Tue Jun 11 14:13:08 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Tue, 11 Jun 2024 14:13:08 -0400 Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3)) In-Reply-To: <91823458-bc96-4725-8d9e-35c9c687c5d2@btinternet.com> References: <91823458-bc96-4725-8d9e-35c9c687c5d2@btinternet.com> Message-ID: <004701dabc2b$032d3180$09879480$@gmail.com> 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 at 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='aaabbccccaa' print(chunk1(s)) print(chunk2(s)) ################################### Program output: ['aaa', 'bb', 'cccc', '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 From HenHanna at devnull.tb Tue Jun 11 18:07:34 2024 From: HenHanna at devnull.tb (HenHanna) Date: Tue, 11 Jun 2024 15:07:34 -0700 Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3)) In-Reply-To: References: <91823458-bc96-4725-8d9e-35c9c687c5d2@btinternet.com> Message-ID: 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='aaabbccccaa' > print(chunk1(s)) > print(chunk2(s)) > ################################### > Program output: > ['aaa', 'bb', 'cccc', '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)) > From mk1853387 at gmail.com Wed Jun 12 07:30:18 2024 From: mk1853387 at gmail.com (marc nicole) Date: Wed, 12 Jun 2024 13:30:18 +0200 Subject: Couldn't install numpy on Python 2.7 Message-ID: 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? From rosuav at gmail.com Wed Jun 12 07:41:14 2024 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Jun 2024 21:41:14 +1000 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: References: Message-ID: 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 From gordinator at gordinator.org Wed Jun 12 10:19:23 2024 From: gordinator at gordinator.org (Gordinator) Date: Wed, 12 Jun 2024 15:19:23 +0100 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: References: Message-ID: 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. From avi.e.gross at gmail.com Wed Jun 12 12:31:39 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 12 Jun 2024 12:31:39 -0400 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: References: Message-ID: <004401dabce6$004569e0$00d03da0$@gmail.com> 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 at 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 From python at mrabarnett.plus.com Wed Jun 12 12:55:43 2024 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Jun 2024 17:55:43 +0100 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: <004401dabce6$004569e0$00d03da0$@gmail.com> References: <004401dabce6$004569e0$00d03da0$@gmail.com> Message-ID: <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> 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 at 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. From avi.e.gross at gmail.com Wed Jun 12 13:40:15 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 12 Jun 2024 13:40:15 -0400 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> Message-ID: <004f01dabcef$95d76d60$c1864820$@gmail.com> 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 at 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 at 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 From rosuav at gmail.com Wed Jun 12 13:59:40 2024 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Jun 2024 03:59:40 +1000 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: <004f01dabcef$95d76d60$c1864820$@gmail.com> References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> <004f01dabcef$95d76d60$c1864820$@gmail.com> Message-ID: 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 From list1 at tompassin.net Wed Jun 12 14:32:44 2024 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 12 Jun 2024 14:32:44 -0400 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> <004f01dabcef$95d76d60$c1864820$@gmail.com> Message-ID: <6186925b-1154-4ad3-9be0-70498996b32d@tompassin.net> 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 From rosuav at gmail.com Wed Jun 12 17:16:56 2024 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Jun 2024 07:16:56 +1000 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: <6186925b-1154-4ad3-9be0-70498996b32d@tompassin.net> References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> <004f01dabcef$95d76d60$c1864820$@gmail.com> <6186925b-1154-4ad3-9be0-70498996b32d@tompassin.net> Message-ID: 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 From avi.e.gross at gmail.com Wed Jun 12 17:36:18 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 12 Jun 2024 17:36:18 -0400 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> <004f01dabcef$95d76d60$c1864820$@gmail.com> Message-ID: <007a01dabd10$8fda0f50$af8e2df0$@gmail.com> 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 at 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 From rosuav at gmail.com Wed Jun 12 17:52:18 2024 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Jun 2024 07:52:18 +1000 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: <007a01dabd10$8fda0f50$af8e2df0$@gmail.com> References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> <004f01dabcef$95d76d60$c1864820$@gmail.com> <007a01dabd10$8fda0f50$af8e2df0$@gmail.com> Message-ID: 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 From oscar.j.benjamin at gmail.com Wed Jun 12 17:55:45 2024 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 12 Jun 2024 22:55:45 +0100 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: <007a01dabd10$8fda0f50$af8e2df0$@gmail.com> References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> <004f01dabcef$95d76d60$c1864820$@gmail.com> <007a01dabd10$8fda0f50$af8e2df0$@gmail.com> Message-ID: 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 From rosuav at gmail.com Wed Jun 12 18:09:09 2024 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Jun 2024 08:09:09 +1000 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> <004f01dabcef$95d76d60$c1864820$@gmail.com> <007a01dabd10$8fda0f50$af8e2df0$@gmail.com> Message-ID: 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 From oscar.j.benjamin at gmail.com Wed Jun 12 18:44:41 2024 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 12 Jun 2024 23:44:41 +0100 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> <004f01dabcef$95d76d60$c1864820$@gmail.com> <007a01dabd10$8fda0f50$af8e2df0$@gmail.com> Message-ID: 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 From greg.ewing at canterbury.ac.nz Wed Jun 12 18:49:18 2024 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 13 Jun 2024 10:49:18 +1200 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: References: <004401dabce6$004569e0$00d03da0$@gmail.com> Message-ID: On 13/06/24 4:31 am, avi.e.gross at 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 From rosuav at gmail.com Wed Jun 12 18:56:35 2024 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Jun 2024 08:56:35 +1000 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> <004f01dabcef$95d76d60$c1864820$@gmail.com> <007a01dabd10$8fda0f50$af8e2df0$@gmail.com> Message-ID: 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 From oscar.j.benjamin at gmail.com Wed Jun 12 18:56:49 2024 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 12 Jun 2024 23:56:49 +0100 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: References: <004401dabce6$004569e0$00d03da0$@gmail.com> Message-ID: 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 From avi.e.gross at gmail.com Wed Jun 12 19:20:30 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 12 Jun 2024 19:20:30 -0400 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> <004f01dabcef$95d76d60$c1864820$@gmail.com> <007a01dabd10$8fda0f50$af8e2df0$@gmail.com> Message-ID: <00a201dabd1f$1dfd5b30$59f81190$@gmail.com> 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 at 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 From rosuav at gmail.com Wed Jun 12 19:23:03 2024 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Jun 2024 09:23:03 +1000 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: <00a201dabd1f$1dfd5b30$59f81190$@gmail.com> References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> <004f01dabcef$95d76d60$c1864820$@gmail.com> <007a01dabd10$8fda0f50$af8e2df0$@gmail.com> <00a201dabd1f$1dfd5b30$59f81190$@gmail.com> Message-ID: 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 From avi.e.gross at gmail.com Wed Jun 12 20:58:10 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 12 Jun 2024 20:58:10 -0400 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> <004f01dabcef$95d76d60$c1864820$@gmail.com> <007a01dabd10$8fda0f50$af8e2df0$@gmail.com> <00a201dabd1f$1dfd5b30$59f81190$@gmail.com> Message-ID: <00bd01dabd2c$c2dc9e60$4895db20$@gmail.com> 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 at 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 From rosuav at gmail.com Wed Jun 12 21:07:18 2024 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Jun 2024 11:07:18 +1000 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: <00bd01dabd2c$c2dc9e60$4895db20$@gmail.com> References: <004401dabce6$004569e0$00d03da0$@gmail.com> <399785e3-0cab-4e38-b219-89863a762d38@mrabarnett.plus.com> <004f01dabcef$95d76d60$c1864820$@gmail.com> <007a01dabd10$8fda0f50$af8e2df0$@gmail.com> <00a201dabd1f$1dfd5b30$59f81190$@gmail.com> <00bd01dabd2c$c2dc9e60$4895db20$@gmail.com> Message-ID: 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 From guruyaya at gmail.com Thu Jun 13 06:01:11 2024 From: guruyaya at gmail.com (Yair Eshel) Date: Thu, 13 Jun 2024 13:01:11 +0300 Subject: Suggested python feature: allowing except in context maneger Message-ID: 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 From cl at isbd.net Thu Jun 13 04:54:36 2024 From: cl at isbd.net (Chris Green) Date: Thu, 13 Jun 2024 09:54:36 +0100 Subject: Couldn't install numpy on Python 2.7 References: <007a01dabd10$8fda0f50$af8e2df0$@gmail.com> <00a201dabd1f$1dfd5b30$59f81190$@gmail.com> <00bd01dabd2c$c2dc9e60$4895db20$@gmail.com> Message-ID: 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 ? From pc+usenet at asdf.org Thu Jun 13 08:01:32 2024 From: pc+usenet at asdf.org (Phil Carmody) Date: Thu, 13 Jun 2024 15:01:32 +0300 Subject: in Python: (101 102 103 201 202 203 301 302 303 401 402 403 ) References: <87v82hph0u.fsf@nightsong.com> Message-ID: <87bk45aw6b.fsf@fatphil.org> 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/ From barry at barrys-emacs.org Thu Jun 13 09:40:36 2024 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 13 Jun 2024 14:40:36 +0100 Subject: Suggested python feature: allowing except in context maneger In-Reply-To: References: Message-ID: <358CCCFD-53BE-401B-B785-7580747D3EBB@barrys-emacs.org> > 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 From ethan at stoneleaf.us Thu Jun 13 13:33:29 2024 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 13 Jun 2024 10:33:29 -0700 Subject: Couldn't install numpy on Python 2.7 In-Reply-To: References: Message-ID: <04c3d12b-4942-4010-9d16-5f97e67ad0ae@stoneleaf.us> 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 From dieter.maurer at online.de Thu Jun 13 13:44:30 2024 From: dieter.maurer at online.de (dieter.maurer at online.de) Date: Thu, 13 Jun 2024 19:44:30 +0200 Subject: Suggested python feature: allowing except in context maneger In-Reply-To: References: Message-ID: <26219.12286.674908.902341@ixdm.fritz.box> 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 From cs at cskk.id.au Thu Jun 13 18:49:48 2024 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 14 Jun 2024 08:49:48 +1000 Subject: Suggested python feature: allowing except in context maneger In-Reply-To: <26219.12286.674908.902341@ixdm.fritz.box> References: <26219.12286.674908.902341@ixdm.fritz.box> Message-ID: On 13Jun2024 19:44, dieter.maurer at 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 From guruyaya at gmail.com Fri Jun 14 02:07:39 2024 From: guruyaya at gmail.com (Yair Eshel) Date: Fri, 14 Jun 2024 09:07:39 +0300 Subject: Suggested python feature: allowing except in context maneger In-Reply-To: References: <26219.12286.674908.902341@ixdm.fritz.box> Message-ID: 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.maurer at 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 > From candycanearter07 at candycanearter07.nomail.afraid Fri Jun 14 02:10:06 2024 From: candycanearter07 at candycanearter07.nomail.afraid (candycanearter07) Date: Fri, 14 Jun 2024 06:10:06 -0000 (UTC) Subject: in Python: (101 102 103 201 202 203 301 302 303 401 402 403 ) References: <87v82hph0u.fsf@nightsong.com> <87bk45aw6b.fsf@fatphil.org> Message-ID: 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 From avi.e.gross at gmail.com Fri Jun 14 18:00:37 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Fri, 14 Jun 2024 18:00:37 -0400 Subject: Anonymous email users Message-ID: <006901dabea6$4a159d30$de40d790$@gmail.com> 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: HenHanna at devnull.tb no.email at nospam.invalid candycanearter07 at 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. From PythonList at DancesWithMice.info Fri Jun 14 18:30:36 2024 From: PythonList at DancesWithMice.info (dn) Date: Sat, 15 Jun 2024 10:30:36 +1200 Subject: Anonymous email users In-Reply-To: <006901dabea6$4a159d30$de40d790$@gmail.com> References: <006901dabea6$4a159d30$de40d790$@gmail.com> Message-ID: 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 From rosuav at gmail.com Fri Jun 14 18:36:02 2024 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 15 Jun 2024 08:36:02 +1000 Subject: Anonymous email users In-Reply-To: References: <006901dabea6$4a159d30$de40d790$@gmail.com> Message-ID: 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 From cs at cskk.id.au Fri Jun 14 21:34:16 2024 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 15 Jun 2024 11:34:16 +1000 Subject: Anonymous email users In-Reply-To: <006901dabea6$4a159d30$de40d790$@gmail.com> References: <006901dabea6$4a159d30$de40d790$@gmail.com> Message-ID: On 14Jun2024 18:00, avi.e.gross at 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: > > HenHanna at 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. From cs at cskk.id.au Fri Jun 14 22:56:35 2024 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 15 Jun 2024 12:56:35 +1000 Subject: Suggested python feature: allowing except in context maneger In-Reply-To: References: Message-ID: 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. From sjeik_appie at hotmail.com Sun Jun 16 17:41:52 2024 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Sun, 16 Jun 2024 23:41:52 +0200 Subject: Suggested python feature: allowing except in context maneger In-Reply-To: Message-ID: 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 From rtm443x at googlemail.com Mon Jun 17 07:35:54 2024 From: rtm443x at googlemail.com (j) Date: Mon, 17 Jun 2024 12:35:54 +0100 Subject: Suggested python feature: allowing except in context maneger In-Reply-To: References: <26219.12286.674908.902341@ixdm.fritz.box> Message-ID: On 2024-06-13 23:49, Cameron Simpson via Python-list wrote: > On 13Jun2024 19:44, dieter.maurer at 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 From mm+usenet-es at dorfdsl.de Sat Jun 15 02:02:58 2024 From: mm+usenet-es at dorfdsl.de (Marco Moock) Date: Sat, 15 Jun 2024 08:02:58 +0200 Subject: Anonymous email users References: <006901dabea6$4a159d30$de40d790$@gmail.com> Message-ID: 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 1718440236muell at cartoonies.org From avi.e.gross at gmail.com Mon Jun 17 11:03:31 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Mon, 17 Jun 2024 11:03:31 -0400 Subject: Anonymous email users In-Reply-To: References: <006901dabea6$4a159d30$de40d790$@gmail.com> Message-ID: <006e01dac0c7$8486c2a0$8d9447e0$@gmail.com> 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 myname at 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 at 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 1718440236muell at cartoonies.org -- https://mail.python.org/mailman/listinfo/python-list From roel at roelschroeven.net Mon Jun 17 13:29:18 2024 From: roel at roelschroeven.net (Roel Schroeven) Date: Mon, 17 Jun 2024 19:29:18 +0200 Subject: Anonymous email users In-Reply-To: <006e01dac0c7$8486c2a0$8d9447e0$@gmail.com> References: <006901dabea6$4a159d30$de40d790$@gmail.com> <006e01dac0c7$8486c2a0$8d9447e0$@gmail.com> Message-ID: <18d003b8-f222-42b9-9666-712e5b07f10a@roelschroeven.net> 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 From rob.cliffe at btinternet.com Mon Jun 17 15:27:51 2024 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 17 Jun 2024 20:27:51 +0100 Subject: win32clipboard writing to clipboard on Windows 11 Message-ID: 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 From grant.b.edwards at gmail.com Mon Jun 17 17:07:42 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 17 Jun 2024 17:07:42 -0400 (EDT) Subject: Anonymous email users References: <006901dabea6$4a159d30$de40d790$@gmail.com> <006e01dac0c7$8486c2a0$8d9447e0$@gmail.com> <18d003b8-f222-42b9-9666-712e5b07f10a@roelschroeven.net> Message-ID: <4W32XG6ksWznV1q@mail.python.org> 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 From avi.e.gross at gmail.com Mon Jun 17 17:21:15 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Mon, 17 Jun 2024 17:21:15 -0400 Subject: Anonymous email users In-Reply-To: <4W32XG6ksWznV1q@mail.python.org> References: <006901dabea6$4a159d30$de40d790$@gmail.com> <006e01dac0c7$8486c2a0$8d9447e0$@gmail.com> <18d003b8-f222-42b9-9666-712e5b07f10a@roelschroeven.net> <4W32XG6ksWznV1q@mail.python.org> Message-ID: <011001dac0fc$49c1cc20$dd456460$@gmail.com> 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 MrSpock at 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 at 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 From PythonList at DancesWithMice.info Mon Jun 17 19:51:04 2024 From: PythonList at DancesWithMice.info (dn) Date: Tue, 18 Jun 2024 11:51:04 +1200 Subject: Anonymous email users In-Reply-To: <18d003b8-f222-42b9-9666-712e5b07f10a@roelschroeven.net> References: <006901dabea6$4a159d30$de40d790$@gmail.com> <006e01dac0c7$8486c2a0$8d9447e0$@gmail.com> <18d003b8-f222-42b9-9666-712e5b07f10a@roelschroeven.net> Message-ID: <51b573ce-5d92-4326-98a4-967163ad4036@DancesWithMice.info> 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 From python at mrabarnett.plus.com Mon Jun 17 21:30:46 2024 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 18 Jun 2024 02:30:46 +0100 Subject: win32clipboard writing to clipboard on Windows 11 In-Reply-To: References: Message-ID: <7e8c9107-6f71-4c49-a78b-ac5094073499@mrabarnett.plus.com> 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. From list1 at tompassin.net Mon Jun 17 22:23:07 2024 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 17 Jun 2024 22:23:07 -0400 Subject: win32clipboard writing to clipboard on Windows 11 In-Reply-To: <7e8c9107-6f71-4c49-a78b-ac5094073499@mrabarnett.plus.com> References: <7e8c9107-6f71-4c49-a78b-ac5094073499@mrabarnett.plus.com> Message-ID: <78d80380-639c-432e-921d-6f5b7a7027fd@tompassin.net> 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. From eryksun at gmail.com Tue Jun 18 03:19:09 2024 From: eryksun at gmail.com (Eryk Sun) Date: Tue, 18 Jun 2024 02:19:09 -0500 Subject: win32clipboard writing to clipboard on Windows 11 In-Reply-To: <7e8c9107-6f71-4c49-a78b-ac5094073499@mrabarnett.plus.com> References: <7e8c9107-6f71-4c49-a78b-ac5094073499@mrabarnett.plus.com> Message-ID: 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) From eryksun at gmail.com Tue Jun 18 03:26:39 2024 From: eryksun at gmail.com (Eryk Sun) Date: Tue, 18 Jun 2024 02:26:39 -0500 Subject: win32clipboard writing to clipboard on Windows 11 In-Reply-To: References: <7e8c9107-6f71-4c49-a78b-ac5094073499@mrabarnett.plus.com> Message-ID: 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 From mats at wichmann.us Tue Jun 18 13:45:21 2024 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 18 Jun 2024 11:45:21 -0600 Subject: Anonymous email users In-Reply-To: <51b573ce-5d92-4326-98a4-967163ad4036@DancesWithMice.info> References: <006901dabea6$4a159d30$de40d790$@gmail.com> <006e01dac0c7$8486c2a0$8d9447e0$@gmail.com> <18d003b8-f222-42b9-9666-712e5b07f10a@roelschroeven.net> <51b573ce-5d92-4326-98a4-967163ad4036@DancesWithMice.info> Message-ID: <9630bb85-f236-4470-a812-3a897c480fc2@wichmann.us> 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). From grant.b.edwards at gmail.com Tue Jun 18 13:58:47 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 18 Jun 2024 13:58:47 -0400 (EDT) Subject: Anonymous email users References: <006901dabea6$4a159d30$de40d790$@gmail.com> <006e01dac0c7$8486c2a0$8d9447e0$@gmail.com> <18d003b8-f222-42b9-9666-712e5b07f10a@roelschroeven.net> <51b573ce-5d92-4326-98a4-967163ad4036@DancesWithMice.info> <9630bb85-f236-4470-a812-3a897c480fc2@wichmann.us> Message-ID: <4W3ZHq2qTdznVH0@mail.python.org> 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 From hjp-python at hjp.at Tue Jun 18 17:26:50 2024 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 18 Jun 2024 23:26:50 +0200 Subject: in Python: (101 102 103 201 202 203 301 302 303 401 402 403 ) In-Reply-To: References: <87v82hph0u.fsf@nightsong.com> <87bk45aw6b.fsf@fatphil.org> Message-ID: <20240618212650.ijp5cv3hyl3iplsf@hjp.at> On 2024-06-14 06:10:06 -0000, 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. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From rambiusparkisanius at gmail.com Tue Jun 18 19:32:17 2024 From: rambiusparkisanius at gmail.com (Ivan "Rambius" Ivanov) Date: Tue, 18 Jun 2024 19:32:17 -0400 Subject: Timezone in HH:MM Format Message-ID: 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 From python at mrabarnett.plus.com Tue Jun 18 19:52:07 2024 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 19 Jun 2024 00:52:07 +0100 Subject: Timezone in HH:MM Format In-Reply-To: References: Message-ID: 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. From jon+usenet at unequivocal.eu Tue Jun 18 20:12:28 2024 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 19 Jun 2024 00:12:28 -0000 (UTC) Subject: Timezone in HH:MM Format References: Message-ID: 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() From rambiusparkisanius at gmail.com Tue Jun 18 22:15:25 2024 From: rambiusparkisanius at gmail.com (Ivan "Rambius" Ivanov) Date: Tue, 18 Jun 2024 22:15:25 -0400 Subject: Timezone in HH:MM Format In-Reply-To: References: Message-ID: 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 From vallor at cultnix.org Thu Jun 20 18:13:51 2024 From: vallor at cultnix.org (vallor) Date: Thu, 20 Jun 2024 22:13:51 -0000 (UTC) Subject: glibc strverscmp called from python Message-ID: 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&d 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 From usenet202101 at magic-cookie.co.ukNOSPAMPLEASE Fri Jun 21 11:49:08 2024 From: usenet202101 at magic-cookie.co.ukNOSPAMPLEASE (Rayner Lucas) Date: Fri, 21 Jun 2024 16:49:08 +0100 Subject: Decoding bytes to text strings in Python 2 Message-ID: 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 From rosuav at gmail.com Fri Jun 21 13:42:39 2024 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Jun 2024 03:42:39 +1000 Subject: Decoding bytes to text strings in Python 2 In-Reply-To: References: Message-ID: 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 From mk1853387 at gmail.com Sat Jun 22 17:54:21 2024 From: mk1853387 at gmail.com (marc nicole) Date: Sat, 22 Jun 2024 23:54:21 +0200 Subject: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects) In-Reply-To: References: Message-ID: My code is just an attempt at the task, it is not exact as what relates to the coordinates (e.g., doesn't account for the size of the object. I would like to have a idea on the general approach to such problems (even a pseudo code would do) "Get the hands rapidly enough in the vicinity and then do some fine coordinated motions to capture the object and then presumably move it." seems to be a good approach indeed, The grabbing with both hands code should be more precise. Thanks for the help anyways! Le sam. 22 juin 2024 ? 23:04, ThreeBlindQuarks a ?crit : > Marc, > > Could you specify what is wrong with what you are doing? you show us code > that uses an environment you point to that is largely outside of basic > Python. > > There is no one way to get from point A to point B and various constraints > you have not mentioned can apply. How many joints does the assemblage have > and what are the limits and costs associated with each. Cam there be > barriers along a route, including to the side where they may brush part of > your equipment. Are other things moving (independently even) that may end > up blocking. > > You seem to need both "hands" and presumably at the same time. So > solutions can take that into account. You need to define what is meant by > contacting the object to move and you don't want to approach it and hit > with some speed. > > So, the problem may be in parts. Get the hands rapidly enough in the > vicinity and then do some fine coordinated motions to capture the object > and then presumably move it. > > If you could point to what code is not doing what is expected, someone who > knows the details or is willing to learn, might help, If you want an > overall algorithm, there may be some people could share but they may not > easily translate into the package of sorts you are using. > > But the web site you point us to may well already contain examples of > doing some aspects that you might learn from. > > For me, this is too detailed to focus on as I struggle to figure out how > to move my hands to different parts of my keyboard while looking ... > > And that may be one variant of an algorithm where instead of trying to > move all the way, you move art-way and LOOK where you are, then repeat. > > > Sent with Proton Mail secure email. > > On Saturday, June 22nd, 2024 at 8:41 AM, marc nicole > wrote: > > > Hello to all of this magnificent community! > > > > I have this problem I had already spent a few days on and still can't > > figure out a proper solution. > > > > So, given the x,y,z coordinates of a target object and the offset x,y,z > of > > arms of a robot, what is a good algorithm to perform to grab the object > > between the hands (either from both sides or from below all using both > > hands). > > > > Specifically, my problem is applied to a NAO robot environment where I > > retrieve a target object coordinates using the following code: > > > > tracker_service= session.service("ALTracker") > > xyz_pos = tracker_service.getTargetPosition(motion.FRAME_TORSO) > > > > > > src: > > > http://doc.aldebaran.com/2-8/naoqi/motion/control-cartesian.html#motion-cartesian-effectors > > > > > > Then I get to move the right arm towards nearby the object using the > > following code: > > > > effector = "RArm" > > > > frame = motion.FRAME_TORSO > > effector_offset = > > almath.Transform(self.motion.getTransform(effector, frame, False)) > > effector_init_3d_position = almath.position3DFromTransform( > > effector_offset) > > > > target_3d_position = almath.Position3D(target_position) > > move_3d = target_3d_position - effector_init_3d_position > > moveTransform = almath.Transform.fromPosition(move_3d.x, > > move_3d.y, move_3d.z) > > target_transformer_list = list(moveTransform.toVector()) > > times = [2.0] > > axis_mask_list = motion.AXIS_MASK_VEL > > self.motion.transformInterpolations(effector, frame, > > target_transformer_list, axis_mask_list, times). > > > > src: > http://doc.aldebaran.com/1-14/dev/python/examples/almath/index.html?highlight=offset > > This question is specific to NAO environment but in general how to go > > about this task? what is a most common algorithm used in this case? Do > > I have to also get the side of the object in order to know where > > exactly the arms should be placed? > > _______________________________________________ > > Tutor maillist - Tutor at python.org > > To unsubscribe or change subscription options: > > https://mail.python.org/mailman/listinfo/tutor > From mk1853387 at gmail.com Sat Jun 22 08:41:47 2024 From: mk1853387 at gmail.com (marc nicole) Date: Sat, 22 Jun 2024 14:41:47 +0200 Subject: How to go about a simple object grabbing in python (given coordinates of arms and objects) Message-ID: Hello to all of this magnificent community! I have this problem I had already spent a few days on and still can't figure out a proper solution. So, given the x,y,z coordinates of a target object and the offset x,y,z of arms of a robot, what is a good algorithm to perform to grab the object between the hands (either from both sides or from below all using both hands). Specifically, my problem is applied to a NAO robot environment where I retrieve a target object coordinates using the following code: tracker_service= session.service("ALTracker") xyz_pos = tracker_service.getTargetPosition(motion.FRAME_TORSO) src: http://doc.aldebaran.com/2-8/naoqi/motion/control-cartesian.html#motion-cartesian-effectors Then I get to move the right arm towards nearby the object using the following code: effector = "RArm" frame = motion.FRAME_TORSO effector_offset = almath.Transform(self.motion.getTransform(effector, frame, False)) effector_init_3d_position = almath.position3DFromTransform( effector_offset) target_3d_position = almath.Position3D(target_position) move_3d = target_3d_position - effector_init_3d_position moveTransform = almath.Transform.fromPosition(move_3d.x, move_3d.y, move_3d.z) target_transformer_list = list(moveTransform.toVector()) times = [2.0] axis_mask_list = motion.AXIS_MASK_VEL self.motion.transformInterpolations(effector, frame, target_transformer_list, axis_mask_list, times). src: http://doc.aldebaran.com/1-14/dev/python/examples/almath/index.html?highlight=offset This question is specific to NAO environment but in general how to go about this task? what is a most common algorithm used in this case? Do I have to also get the side of the object in order to know where exactly the arms should be placed? From usenet202101 at magic-cookie.co.ukNOSPAMPLEASE Sat Jun 22 08:13:28 2024 From: usenet202101 at magic-cookie.co.ukNOSPAMPLEASE (Rayner Lucas) Date: Sat, 22 Jun 2024 13:13:28 +0100 Subject: Decoding bytes to text strings in Python 2 References: Message-ID: In article , rosuav at gmail.com says... > > If you switch to a Linux system, it should work correctly, and you'll > be able to migrate the rest of the way onto Python 3. Once you achieve > that, you'll be able to operate on Windows or Linux equivalently, > since Python 3 solved this problem. At least, I *think* it will; my > current system has a Python 2 installed, but doesn't have tkinter > (because I never bothered to install it), and it's no longer available > from the upstream Debian repos, so I only tested it in the console. > But the decoding certainly worked. Thank you for the idea of trying it on a Linux system. I did so, and my example code generated the error: _tkinter.TclError: character U+1f40d is above the range (U+0000-U+FFFF) allowed by Tcl So it looks like the problem is ultimately due to a limitation of Tcl/Tk. I'm still not sure why it doesn't give an error on Windows and instead either works (when UTF-8 encoding is specified) or converts the out-of-range characters to ones it can display (when the encoding isn't specified). But now I know what the root of the problem is, I can deal with it appropriately (and my curiosity is at least partly satisfied). This has given me a much better understanding of what I need to do in order to migrate to Python 3 and add proper support for non-ASCII characters, so I'm very grateful for your help! Thanks, Rayner From usenet202101 at magic-cookie.co.ukNOSPAMPLEASE Sat Jun 22 08:26:00 2024 From: usenet202101 at magic-cookie.co.ukNOSPAMPLEASE (Rayner Lucas) Date: Sat, 22 Jun 2024 13:26:00 +0100 Subject: Decoding bytes to text strings in Python 2 References: Message-ID: In article , ram at zedat.fu- berlin.de says... > > I didn't really do a super thorough deep dive on this, > but I'm just giving the initial impression without > actually being familiar with Tkinter under Python 2, > so I might be wrong! > > The Text widget typically expects text in Tcl encoding, > which is usually UTF-8. > > This is independent of the result returned by sys.get- > defaultencoding()! > > If a UTF-8 string is inserted directly as a bytes object, > its code points will be displayed correctly by the Text > widget as long as they are in the BMP (Basic Multilingual > Plane), as you already found out yourself. Many thanks, you've helped me greatly in understanding what's happening. When I tried running my example code on a different system (Python 2.7.18 on Linux, with Tcl/Tk 8.5), I got the error: _tkinter.TclError: character U+1f40d is above the range (U+0000-U+FFFF) allowed by Tcl So, as your reply suggests, the problem is ultimately a limitation of Tcl/Tk itself. Perhaps I should have spent more time studying the docs for that instead of puzzling over the details of character encodings in Python! I'm not sure why it doesn't give the same error on Windows, but at least now I know where the root of the issue is. I am now much better informed about how to migrate the code I'm working on, so I am very grateful for your help. Thanks, Rayner From sebastian at here.com.invalid Sun Jun 23 01:58:17 2024 From: sebastian at here.com.invalid (Sebastian Wells) Date: Sun, 23 Jun 2024 05:58:17 -0000 (UTC) Subject: Anonymous email users References: <006901dabea6$4a159d30$de40d790$@gmail.com> Message-ID: On Fri, 14 Jun 2024 18:00:37 -0400, avi.e.gross wrote: > I notice that in some recent discussions, we have users who cannot be > replied to directly as their email addresses are not valid ones, and I > believe on purpose. Examples in the thread I was going to reply to are: > > HenHanna at devnull.tb > > no.email at nospam.invalid > > > candycanearter07 at candycanearter07.nomail.afraid (user is > generated from /dev/urandom) > > I know some here suggest that we only reply to the wider community and > they have a point. But I think there is a role for having some > conversations offline and especially when they are not likely to be > wanted, or even tolerated, by many in the community. > > Using such fake or invalid emails makes it hard to answer the person > directly or perhaps politely ask them for more info on their request or > discuss unrelated common interests. Worse, when I reply, unless I use > reply-all, my mailer sends to them futilely. When I do the reply-all, I > have to edit out their name or get a rejection. > The spammers won the spam wars, so even if you have someone's real e-mail address, that's no guarantee that you can contact them. You certainly wouldn't be able to contact me at my real e-mail address, unless you also had my phone number, so you could call me and tell me that you sent me an e-mail, and what the subject line was so I can find it. I don't even open my e-mail inbox unless there's a specific message I'm expecting to find there right now. With e-mail addresses being phone-validated, it's not easy to create a new one either. And even if I did, you can't even trust e-mail providers not to give your address out to spammers. The only function e-mail addresses serve now is to positively identify the sender of a Usenet posting so he can be targeted for harassment, lawsuits, or worse. From rosuav at gmail.com Sun Jun 23 19:30:30 2024 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Jun 2024 09:30:30 +1000 Subject: Decoding bytes to text strings in Python 2 In-Reply-To: References: Message-ID: On Mon, 24 Jun 2024 at 08:20, Rayner Lucas via Python-list wrote: > > In article , > rosuav at gmail.com says... > > > > If you switch to a Linux system, it should work correctly, and you'll > > be able to migrate the rest of the way onto Python 3. Once you achieve > > that, you'll be able to operate on Windows or Linux equivalently, > > since Python 3 solved this problem. At least, I *think* it will; my > > current system has a Python 2 installed, but doesn't have tkinter > > (because I never bothered to install it), and it's no longer available > > from the upstream Debian repos, so I only tested it in the console. > > But the decoding certainly worked. > > Thank you for the idea of trying it on a Linux system. I did so, and my > example code generated the error: > > _tkinter.TclError: character U+1f40d is above the range (U+0000-U+FFFF) > allowed by Tcl > > So it looks like the problem is ultimately due to a limitation of > Tcl/Tk. Yep, that seems to be the case. Not sure if that's still true on a more recent Python, but it does look like you won't get astral characters in tkinter on the one you're using. > I'm still not sure why it doesn't give an error on Windows and Because of the aforementioned weirdness of old (that is: pre-3.3) Python versions on Windows. They were built to use a messy, buggy hybrid of UCS-2 and UTF-16. Sometimes this got you around problems, or at least masked them; but it wouldn't be reliable. That's why, in Python 3.3, all that was fixed :) > instead either works (when UTF-8 encoding is specified) or converts the > out-of-range characters to ones it can display (when the encoding isn't > specified). But now I know what the root of the problem is, I can deal > with it appropriately (and my curiosity is at least partly satisfied). Converting out-of-range characters is fairly straightforward, at least as long as your Python interpreter is correctly built (so, Python 3, or a Linux build of Python 2). "".join(c if ord(c) < 65536 else "?" for c in text) > This has given me a much better understanding of what I need to do in > order to migrate to Python 3 and add proper support for non-ASCII > characters, so I'm very grateful for your help! > Excellent. Hopefully all this mess is just a transitional state and you'll get to something that REALLY works, soon! ChrisA From python at mrabarnett.plus.com Sun Jun 23 20:14:22 2024 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 24 Jun 2024 01:14:22 +0100 Subject: Decoding bytes to text strings in Python 2 In-Reply-To: References: Message-ID: <41260f11-89ae-433d-b44a-26c604b91356@mrabarnett.plus.com> On 2024-06-24 00:30, Chris Angelico via Python-list wrote: > On Mon, 24 Jun 2024 at 08:20, Rayner Lucas via Python-list > wrote: >> >> In article , >> rosuav at gmail.com says... >> > >> > If you switch to a Linux system, it should work correctly, and you'll >> > be able to migrate the rest of the way onto Python 3. Once you achieve >> > that, you'll be able to operate on Windows or Linux equivalently, >> > since Python 3 solved this problem. At least, I *think* it will; my >> > current system has a Python 2 installed, but doesn't have tkinter >> > (because I never bothered to install it), and it's no longer available >> > from the upstream Debian repos, so I only tested it in the console. >> > But the decoding certainly worked. >> >> Thank you for the idea of trying it on a Linux system. I did so, and my >> example code generated the error: >> >> _tkinter.TclError: character U+1f40d is above the range (U+0000-U+FFFF) >> allowed by Tcl >> >> So it looks like the problem is ultimately due to a limitation of >> Tcl/Tk. > Yep, that seems to be the case. Not sure if that's still true on a > more recent Python, but it does look like you won't get astral > characters in tkinter on the one you're using. > [snip] Tkinter in recent versions of Python can handle astral characters, at least back to Python 3.8, the oldest I have on my Windows PC. From rosuav at gmail.com Sun Jun 23 21:43:28 2024 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Jun 2024 11:43:28 +1000 Subject: Decoding bytes to text strings in Python 2 In-Reply-To: <41260f11-89ae-433d-b44a-26c604b91356@mrabarnett.plus.com> References: <41260f11-89ae-433d-b44a-26c604b91356@mrabarnett.plus.com> Message-ID: On Mon, 24 Jun 2024 at 10:18, MRAB via Python-list wrote: > Tkinter in recent versions of Python can handle astral characters, at > least back to Python 3.8, the oldest I have on my Windows PC. Good to know, thanks! I was hoping that would be the case, but I don't have a Windows system to check on, so I didn't want to speak without facts. ChrisA From mk1853387 at gmail.com Mon Jun 24 05:23:30 2024 From: mk1853387 at gmail.com (marc nicole) Date: Mon, 24 Jun 2024 11:23:30 +0200 Subject: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects) In-Reply-To: References: Message-ID: What are the parameters to account for in this type of algorithm? are there some checks to perform the arm moves ? for example angle moves or cartesian moves based on some distance thresholds? Any idea about the pseudo-algorithm is welcome. Thanks. Le dim. 23 juin 2024 ? 10:33, Alan Gauld via Tutor a ?crit : > On 22/06/2024 13:41, marc nicole wrote: > > > So, given the x,y,z coordinates of a target object and the offset x,y,z > of > > arms of a robot, what is a good algorithm to perform to grab the object > > between the hands (either from both sides or from below all using both > > hands). > > > > Specifically, my problem is applied to a NAO robot environment where I > > retrieve a target object coordinates using the following code: > > This is almost entirely outside the Python domain and all within > your 3rd party environment. Do they have a user forum or mailing > list? You will probably get better results asking there? > > Another possibility is that you are using a Python wrapper around > a C (or other language) library and there might be FAQs, fora or > lists supporting that. If so you should be able to translate > their examples to your Python code? > > In terms of generic solutions the only thing I can suggest that > might help is to research collision detection algorithms. > Wikipedia is likely a good starting point. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > From hjp-python at hjp.at Mon Jun 24 07:03:45 2024 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 24 Jun 2024 13:03:45 +0200 Subject: Tkinter and astral characters (was: Decoding bytes to text strings in Python 2) In-Reply-To: <41260f11-89ae-433d-b44a-26c604b91356@mrabarnett.plus.com> References: <41260f11-89ae-433d-b44a-26c604b91356@mrabarnett.plus.com> Message-ID: <20240624110345.k5ojn4j5tmejwu6k@hjp.at> On 2024-06-24 01:14:22 +0100, MRAB via Python-list wrote: > Tkinter in recent versions of Python can handle astral characters, at least > back to Python 3.8, the oldest I have on my Windows PC. I just tried modifying https://docs.python.org/3/library/tkinter.html#a-hello-world-program to display "Hello World \N{ROCKET}" instead (Python 3.10.12 as included with Ubuntu 22.04). I don't get a warning or error, but the emoji isn't displayed either. I suspect that the default font doesn't include emojis and Tk isn't smart enough to fall back to a different font (unlike xfce4-terminal which shows the emoji just fine). hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From barry at barrys-emacs.org Mon Jun 24 05:51:38 2024 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 24 Jun 2024 10:51:38 +0100 Subject: Anonymous email users In-Reply-To: References: <006901dabea6$4a159d30$de40d790$@gmail.com> Message-ID: <4CB44E85-2DF4-47DE-844B-DA7371D80836@barrys-emacs.org> > On 23 Jun 2024, at 06:58, Sebastian Wells via Python-list wrote: > > The spammers won the spam wars, so even if you have someone's real > e-mail address, that's no guarantee that you can contact them. You > certainly wouldn't be able to contact me at my real e-mail address, > unless you also had my phone number, so you could call me and tell > me that you sent me an e-mail, and what the subject line was so I > can find it. I don't even open my e-mail inbox unless there's a > specific message I'm expecting to find there right now. My email address is well known and yes I get spam emails. I use the wonderful python based spambayes software to detect spam and file into a Junk folder. It works for 99.9% of the emails I get. I am subscribed to a lot of mailing lists. I just checked and I am getting ~3,200 emails a month of which less than 200 are spam. A few years ago the spam count was greater than a 1,000 a month. I have been using spambayes for a very long time, 20 years I guess at this point and bayesian categorisation has stood the test of time for me. For me the spammers have not won, I have the tech to keep ahead of them. Barry From list1 at tompassin.net Mon Jun 24 13:17:13 2024 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 24 Jun 2024 13:17:13 -0400 Subject: Anonymous email users In-Reply-To: <4CB44E85-2DF4-47DE-844B-DA7371D80836@barrys-emacs.org> References: <006901dabea6$4a159d30$de40d790$@gmail.com> <4CB44E85-2DF4-47DE-844B-DA7371D80836@barrys-emacs.org> Message-ID: On 6/24/2024 5:51 AM, Barry Scott via Python-list wrote: > > >> On 23 Jun 2024, at 06:58, Sebastian Wells via Python-list wrote: >> >> The spammers won the spam wars, so even if you have someone's real >> e-mail address, that's no guarantee that you can contact them. You >> certainly wouldn't be able to contact me at my real e-mail address, >> unless you also had my phone number, so you could call me and tell >> me that you sent me an e-mail, and what the subject line was so I >> can find it. I don't even open my e-mail inbox unless there's a >> specific message I'm expecting to find there right now. > > My email address is well known and yes I get spam emails. > > I use the wonderful python based spambayes software to detect spam and > file into a Junk folder. It works for 99.9% of the emails I get. I use the Thunderbird mail client and I just use its built in spam detector. I don't know how it works but it's pretty darn good. Very few false positives or false negatives. And it learns each time I classify a message as "Junk", in case it missed one. > I am subscribed to a lot of mailing lists. I just checked and I am getting ~3,200 > emails a month of which less than 200 are spam. > > A few years ago the spam count was greater than a 1,000 a month. > > I have been using spambayes for a very long time, 20 years I guess at this > point and bayesian categorisation has stood the test of time for me. > > For me the spammers have not won, I have the tech to keep ahead of them. > > Barry > From avi.e.gross at gmail.com Mon Jun 24 17:57:00 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Mon, 24 Jun 2024 17:57:00 -0400 Subject: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects) In-Reply-To: References: Message-ID: <000601dac681$70bbaf00$52330d00$@gmail.com> Marc, Several people have supplied feedback on whether your request is a good fit for here. Ultimately it is up to the owner/moderator. In particular, your request to the Tutor List may not fit the purpose and be a bit complex and to the main Python List also outside some common usage whether it is about a specific module or product you are using, or asking about algorithms in a very general way. You question has evolved to being about algorithms, more than about Python as a basic language or even commonly used modules. So, I suggest you simplify your model and then maybe bring it in-line with the module(s) you showed us you were using. Some of what you ask sounds like it would be extremely commonly done in things like robotics, or even just machines with moving parts. Consider the somewhat related concept often seen of how you get from one place to another in parts of Manhattan where most of the streets run either in one direction or the orthogonal direction. How do you get from say East 14th Street at 1st Avenue to West 28th Street and 11th Avenue? This is a slight imitation of how to move a robotic arm that can mainly either go one way or another but not both at once. And, in the real world, parts of Manhattan are more complex with streets ending or renaming or running more diagonally or huge voids like Central Park. The number of solutions is huge for walking, and smaller for driving as some streets are one way. But assuming you avoid wasteful paths (except when roads are closed for endless purposes) and you do not take a path through Brooklyn, Queens and The Bronx and back to Manhattan as in the NY Marathon that also touches another borough, the solutions mainly look like this: Go as far horizontally as you need and then as far vertically. Or, do vertical, then horizontal. Or lots of combined versions such as climbing stairs by doing a block or three one way then some in the other and repeat. The above is referred to as Manhattan Distance, as compared to other measures like Euclidean distance. So back to your robot arm, you can see a set of simple solutions where you make a sort of triangle with the direct Euclidean arm being a hypoteneuse and the X and Y movements are the other two sides. You can then break up your problem as heading one way and pausing and turning the other way and stopping just short of the object you want. If there are no obstacles, you can do that in either order. Or, you could alternate in smaller amounts and get to the same destination. Grabbing it would be something else I will not address except to say that depending on what is grabbing and how it is shaped, you may need to aim not for the object, but the appropriate distance and direction so that when you stop moving, the "grasper" can close on it, again, avoiding existing obstacles. And note, speed is a consideration as many things need to be approached slowly and gently. Next, consider what it would mean if you could have a combined motion based on both operations allowed at the same time. Consider a robot that is on wheels that can move horizontally while also having a "lift" component that lifts the part with the graspers vertically. Both could be programmed to run in tandem at appropriate speeds so the graspers are traveling along the hypotenuse I mention and are going the shortest path. This might be faster and more economical in other ways but can be more complex. And, it may be the robot does not have power or computing ability to do both at the same time. Your design is beyond vague. Both of the approaches above make a plan and carry it out. But in the real world, many algorithms must adjust and work somewhat probabilistically. One algorithm for say catching a moving object, especially one that can change speed and direction a bit, like a running dog or a kite flying in the wind, is to locate where the object seems to be now, perhaps just a direction and a guess at distance, and maybe with some observation make a guess at where it might be at some time in the future that is approximately when you might move the robot near there. Then, use a technique like above (or completely different) that perhaps aims to get you something like halfway there. Monitor along the way to update your position and the newest destination position (if it is moving) and re-evaluate and adjust for the next round and maybe evaluate again as you approach halfway or so, again. Eventually, if you are close, slow down and gradually try to come to a stop where you can grab. If the object reacts to your attempting to go after it, it can be complex. And, you may overshoot and sort of circle back. Now, expand the problem more if needed. What does the robot look like. How many places can it bend? For example, can it have something like two or more elbows, perhaps one allowing twisting of up to 30 degrees and one moving forward and backward and another allowing movement side to side, up to some number of degrees. Are all these degrees of freedom absolute or are there constraints? For example, to turn beyond some number of combined degrees may not be allowed, and instead of turning 400 degrees clockwise, you simply move forward or back to a 40 degree angle from some baseline. Perhaps bending certain ways while carrying some kind of weight, can cause it to topple. There can be an amazing number of considerations that cannot be anticipated and depend on specific choices in making a robot. A longer arm, for example, requires fewer degrees of turn to move some known amount. As before, there are an amazing number of ways to do such things in any language as we are discussing "algorithms." If the goal is finding A WAY, any simpler ones will do. If it is to find an optimum way, we have tons you need to learn and consider. If this was a contest and a contestant on the other side of the object was supposed to start at the same time as you, and the first to grab the object wins, ... And, if this has machine learning components, which python is in some ways well suited to, you may design a robot that moves clumsily and almost randomly, at first, and then "learns" from such experiments and gradually figures out better and maybe even better ways until it just does well at reaching and grasping for any similar enough problems and maybe even somewhat different ones. I suspect that is more than you need but in real-world robotics, may be part of how to make more sophisticated and even general-purpose robots. But if you want to talk more about python in doing parts of this, there are several things to consider. Base python has data structures you can use to store and manipulate many things you may need to keep track of, or if planning a whole routine in advance, things like lists to hold the steps you can then hand over to function. Add-on modules like numpy can be very helpful in extending python for some purposes, as an example. There are probably many functions that already do things like given two points, calculate the slope and distance of a direct line between them, or compare two or more approaches and return what is best in some way and so on. There ways of running things in parallel while sharing some data while making sure to avoid them interfering with each other. You can set timers to wake up and recalculate and much more. Then there are all kinds of modules that help you with parts. There is a good chance that whatever you showed us is just one of many such modules people have shared or sold for purposes similar enough to your robot problem. But if your main goal is to do this mainly with the kind of functionality you pointed at, since likely none of us have read the documentation, nor care to without getting paid a lot, it means you should be reading a lot and looking carefully at examples that may apply AND finding resources more about that than asking people about "python" and especially asking python people how one does things in robotics. Mose specific questions such as how to calculate a distance using python, will likely get helpful responses, and brief but complete examples of code that you want debugged, may also be responded to. But asking for complex algorithms in the abstract probably will result in silence or ever more elaborate debates till a moderator suggest a halt! LOL! Python, like many languages, is a fairly general purpose language that can do many things well, and some less well, and some mainly by standing on it's head while including software built in other languages. Your project may happen to be in python, but more likely most of it should be using functions built-in to whatever add-ons you are using if it is designed to do what you want. Your goal is not to create it all from scratch, I would think. You may end up using just a little base python to glue things together. Good Luck. -----Original Message----- From: Python-list On Behalf Of marc nicole via Python-list Sent: Monday, June 24, 2024 5:24 AM To: Alan Gauld ; python-list at python.org; Tutor at python.org Subject: Re: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects) What are the parameters to account for in this type of algorithm? are there some checks to perform the arm moves ? for example angle moves or cartesian moves based on some distance thresholds? Any idea about the pseudo-algorithm is welcome. Thanks. Le dim. 23 juin 2024 ? 10:33, Alan Gauld via Tutor a ?crit : > On 22/06/2024 13:41, marc nicole wrote: > > > So, given the x,y,z coordinates of a target object and the offset x,y,z > of > > arms of a robot, what is a good algorithm to perform to grab the object > > between the hands (either from both sides or from below all using both > > hands). > > > > Specifically, my problem is applied to a NAO robot environment where I > > retrieve a target object coordinates using the following code: > > This is almost entirely outside the Python domain and all within > your 3rd party environment. Do they have a user forum or mailing > list? You will probably get better results asking there? > > Another possibility is that you are using a Python wrapper around > a C (or other language) library and there might be FAQs, fora or > lists supporting that. If so you should be able to translate > their examples to your Python code? > > In terms of generic solutions the only thing I can suggest that > might help is to research collision detection algorithms. > Wikipedia is likely a good starting point. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- https://mail.python.org/mailman/listinfo/python-list From PythonList at DancesWithMice.info Mon Jun 24 18:29:08 2024 From: PythonList at DancesWithMice.info (dn) Date: Tue, 25 Jun 2024 10:29:08 +1200 Subject: Anonymous email users In-Reply-To: References: <006901dabea6$4a159d30$de40d790$@gmail.com> <4CB44E85-2DF4-47DE-844B-DA7371D80836@barrys-emacs.org> Message-ID: On 25/06/24 05:17, Thomas Passin via Python-list wrote: > On 6/24/2024 5:51 AM, Barry Scott via Python-list wrote: >> >> >>> On 23 Jun 2024, at 06:58, Sebastian Wells via Python-list >>> wrote: >>> >>> The spammers won the spam wars, so even if you have someone's real >>> e-mail address, that's no guarantee that you can contact them. You >>> certainly wouldn't be able to contact me at my real e-mail address, >>> unless you also had my phone number, so you could call me and tell >>> me that you sent me an e-mail, and what the subject line was so I >>> can find it. I don't even open my e-mail inbox unless there's a >>> specific message I'm expecting to find there right now. >> >> My email address is well known and yes I get spam emails. >> >> I use the wonderful python based spambayes software to detect spam and >> file into a Junk folder. It works for 99.9% of the emails I get. > > I use the Thunderbird mail client and I just use its built in spam > detector.? I don't know how it works but it's pretty darn good.? Very > few false positives or false negatives.? And it learns each time I > classify a message as "Junk", in case it missed one. > >> I am subscribed to a lot of mailing lists. I just checked and I am >> getting ~3,200 >> emails a month of which less than 200 are spam. >> >> A few years ago the spam count was greater than a 1,000 a month. >> >> I have been using spambayes for a very long time, 20 years I guess at >> this >> point and bayesian categorisation has stood the test of time for me. >> >> For me the spammers have not won, I have the tech to keep ahead of them. Aside from the attractions of the new, and the 'shiny', what email-antagonists didn't anticipate, was that as fast as they moved to non-email messaging, the spammers, advertisers, and malcontents would simply do the same. Thus, a variation on whack-a-mole, as folk move from platform to platform trying to stay-ahead and find an illusion of safety. Quite how one out-runs human-nature is an issue philosophised-over by the (Ancient) Greeks (and was no-doubt old even-then). Paradoxically, applying for an account elsewhere usually involves providing an email address. Even backing-up a cell-phone (communication tool) to the cloud requires an email address(!!!) Most of the non-email platforms are provided by organisations who have 'other uses' for your personal-data (and not forgetting GMail and MSFT's email services). Python mailing-lists are covered by the Code of Conduct and monitored by ListAdmins. Thus, there are controls which limit the impact which advertisers and others with non-pythonic aims might otherwise exert! -- Regards, =dn From rosuav at gmail.com Mon Jun 24 18:44:54 2024 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Jun 2024 08:44:54 +1000 Subject: Anonymous email users In-Reply-To: References: <006901dabea6$4a159d30$de40d790$@gmail.com> <4CB44E85-2DF4-47DE-844B-DA7371D80836@barrys-emacs.org> Message-ID: On Tue, 25 Jun 2024 at 08:31, dn via Python-list wrote: > Python mailing-lists are covered by the Code of Conduct and monitored by > ListAdmins. Thus, there are controls which limit the impact which > advertisers and others with non-pythonic aims might otherwise exert! > So long as there's a newsgroup gateway, those controls are toothless. ChrisA From grant.b.edwards at gmail.com Mon Jun 24 14:12:16 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 24 Jun 2024 14:12:16 -0400 (EDT) Subject: Anonymous email users References: <006901dabea6$4a159d30$de40d790$@gmail.com> <4CB44E85-2DF4-47DE-844B-DA7371D80836@barrys-emacs.org> Message-ID: <4W7GJc0BcSznVFw@mail.python.org> On 2024-06-24, Barry Scott via Python-list wrote: >> On 23 Jun 2024, at 06:58, Sebastian Wells via Python-list wrote: >> >> The spammers won the spam wars, so even if you have someone's real >> e-mail address, that's no guarantee that you can contact them. [...] > > My email address is well known and yes I get spam emails. I've been puzzled by this for a long time. Many people talk about how they get so much spam e-mail that there's little chance they'll notice if I send them an e-mail. I've been using the same e-mail address for about 20 years. I've use that e-mail address with probably close to 100 retailers, charities, open-source projects, media sites, and various other organizations. I get at most a few spam emails per week [I just checked my spam folder: 8 in the past 30 days]. And Gmail is very, very close to 100% accurate at filtering them out. I can't remember the last time I actually got a spam message in my inbox. > A few years ago the spam count was greater than a 1,000 a month. I'm baffled. Is Gmail silently rejecting that much junk before it even gets to the filter that puts stuff into my "spam" folder? -- Grant From rosuav at gmail.com Mon Jun 24 21:49:16 2024 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Jun 2024 11:49:16 +1000 Subject: Anonymous email users In-Reply-To: <4W7GJc0BcSznVFw@mail.python.org> References: <006901dabea6$4a159d30$de40d790$@gmail.com> <4CB44E85-2DF4-47DE-844B-DA7371D80836@barrys-emacs.org> <4W7GJc0BcSznVFw@mail.python.org> Message-ID: On Tue, 25 Jun 2024 at 11:41, Grant Edwards via Python-list wrote: > I've been using the same e-mail address for about 20 years. I've use > that e-mail address with probably close to 100 retailers, charities, > open-source projects, media sites, and various other organizations. Mostly the same, although in my case, I've had multiple email addresses for different purposes (and still kept all of them for decades). > I get at most a few spam emails per week [I just checked my spam > folder: 8 in the past 30 days]. And Gmail is very, very close to 100% > accurate at filtering them out. I can't remember the last time I > actually got a spam message in my inbox. > > > A few years ago the spam count was greater than a 1,000 a month. > > I'm baffled. Is Gmail silently rejecting that much junk before it > even gets to the filter that puts stuff into my "spam" folder? > It really depends on how you count. On my mail server (can't get stats for Gmail), I have a number of anti-spam and anti-abuse rules that apply prior to the Bayesian filtering (for example, protocol violations), and any spam that gets blocked by those rules isn't shown in my stats. And then I have a further set of rules that nuke some of the most blatant spam, and finally the regular trainable filter. I should probably keep better stats on the stuff I don't keep, but at the moment, all I actually track is the ones that the filter sees - which is roughly 25-50 a day. So.... yeah, Gmail is probably rejecting that much junk, but most of it for protocol violations. ChrisA From avi.e.gross at gmail.com Tue Jun 25 00:13:16 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Tue, 25 Jun 2024 00:13:16 -0400 Subject: Anonymous email users In-Reply-To: References: <006901dabea6$4a159d30$de40d790$@gmail.com> <4CB44E85-2DF4-47DE-844B-DA7371D80836@barrys-emacs.org> <4W7GJc0BcSznVFw@mail.python.org> Message-ID: <009b01dac6b6$01584300$0408c900$@gmail.com> This discussion has wandered far from my original mention that I found it hard to reply to people using an invalid email address. I see no real connection to python except insofar as at least one spam-filter mentioned is written in python! Just to add an observation, the people writing here have obviously had many different experiences with their email addresses and whether yours is hijacked in some way, and made less useful, can even just become down to random luck. But SPAM filters can also be manipulated and cause you to lose mail. I think some people have been reporting email from a source they do not favor, such as for political reasons, that then ends up being junked for people who would welcome the messages. And, I can well imagine how something like a post about python programs can start being filtered out because some key words commonly use end up being used a lot in some kind of SPAM and the filter "learns" to filter those out. Imagine of "python" appeared in lots of actual SPAM messages as the war moved on, such as in the metadata designed to make it look legit. Email addresses can go bad for many reasons. My wife had a nice simple address like jane.smith at gmail.com that was messed up probably by well-meaning people when another Jane Smith had an email address like smith.jane or janesmith123 and they or others typed in the more straightforward ones. It seems we ended up getting odd email from many continents such as e-tickets for airplanes, initial estimates or bills from vendors for products in places we have never been for services rendered in say Tennessee or South Africa (well, I've been in Tennessee, but) and subscriptions to internet magazines or groups that sent lots of messages, or conversations between lots of people (all To: or Cc:) that included her email address wrongly and even when she replied to ask to be taken off, the conversations continued for months as many kept hitting reply-all, ...) And, obviously, with so many people using the address wrongly, SPAM followed. Of course, choosing a strange name designed not to be typed by accident, has it's own disadvantages. But for those who want me to CALL their unspecified phone number and tell them the subject line and then maybe you will look for my message, FUGGEDABOUTIT! I have a cousin who does a trick with her phone service where she never answers and I have to run some gauntlet to identify myself and then wait for a call back. After a few times, I solved the problem and simply never call her. Admittedly, making it hard for an email address to be abused in a forum like this is understandable. Making it very hard to reach you legitimately when the message is that your house is burning or just that your appointment is canceled, may not work as well as you think. And, FYI, I check my junkmail regularly and I have a fairly high rate of finding things, including posts on forums like this one, that are NOT in my opinion junk as I ordered them and they are on topic and not easily visible as having committed some kind of sin. And as I use many email services, I still find a high rate of false negatives everywhere. It would not surprise me if a phrase like "not SPAM" gets this message dumped into /dev/null -----Original Message----- From: Python-list On Behalf Of Chris Angelico via Python-list Sent: Monday, June 24, 2024 9:49 PM To: python-list at python.org Subject: Re: Anonymous email users On Tue, 25 Jun 2024 at 11:41, Grant Edwards via Python-list wrote: > I've been using the same e-mail address for about 20 years. I've use > that e-mail address with probably close to 100 retailers, charities, > open-source projects, media sites, and various other organizations. Mostly the same, although in my case, I've had multiple email addresses for different purposes (and still kept all of them for decades). > I get at most a few spam emails per week [I just checked my spam > folder: 8 in the past 30 days]. And Gmail is very, very close to 100% > accurate at filtering them out. I can't remember the last time I > actually got a spam message in my inbox. > > > A few years ago the spam count was greater than a 1,000 a month. > > I'm baffled. Is Gmail silently rejecting that much junk before it > even gets to the filter that puts stuff into my "spam" folder? > It really depends on how you count. On my mail server (can't get stats for Gmail), I have a number of anti-spam and anti-abuse rules that apply prior to the Bayesian filtering (for example, protocol violations), and any spam that gets blocked by those rules isn't shown in my stats. And then I have a further set of rules that nuke some of the most blatant spam, and finally the regular trainable filter. I should probably keep better stats on the stuff I don't keep, but at the moment, all I actually track is the ones that the filter sees - which is roughly 25-50 a day. So.... yeah, Gmail is probably rejecting that much junk, but most of it for protocol violations. ChrisA -- https://mail.python.org/mailman/listinfo/python-list From anton.txt at g{oogle}mail.com Tue Jun 25 05:09:22 2024 From: anton.txt at g{oogle}mail.com (Anton Shepelev) Date: Tue, 25 Jun 2024 12:09:22 +0300 Subject: Anonymous email users References: <006901dabea6$4a159d30$de40d790$@gmail.com> Message-ID: <20240625120922.8eea04fd369a0d05c94b43e5@g{oogle}mail.com> Sebastian Wells: > The spammers won the spam wars, so even if you have > someone's real e-mail address, that's no guarantee that > you can contact them. No so with me. My e-mail address here is munged, but in a very obvious way, and no, my mailbox is not overwhelmed with spam. I make a habit of reporting spam via: 1. https://www.spamcop.net/anonsignup.shtml 2. https://submit.spamhaus.org/submit/ They maintain blacklists of e-mail providers or notify them of spam e-mails. It helps. -- () ascii ribbon campaign -- against html e-mail /\ www.asciiribbon.org -- against proprietary attachments From anton.txt at g{oogle}mail.com Tue Jun 25 05:59:54 2024 From: anton.txt at g{oogle}mail.com (Anton Shepelev) Date: Tue, 25 Jun 2024 12:59:54 +0300 Subject: Anonymous email users References: <006901dabea6$4a159d30$de40d790$@gmail.com> <4CB44E85-2DF4-47DE-844B-DA7371D80836@barrys-emacs.org> Message-ID: <20240625125954.4425a9d41eb8ef8fd92f4af0@g{oogle}mail.com> Chris Angelico to dn: > > Python mailing-lists are covered by the Code of Conduct > > and monitored by ListAdmins. Thus, there are controls > > which limit the impact which advertisers and others with > > non-pythonic aims might otherwise exert! > > So long as there's a newsgroup gateway, those controls are > toothless. The gateway operator can have the usual anti-spam software installed, and of course there is Gmane: which actually subscribes users to mailing lists (on their behalf). Gmane's NNTP server is: news.gmane.io . -- () ascii ribbon campaign -- against html e-mail /\ www.asciiribbon.org -- against proprietary attachments From rosuav at gmail.com Tue Jun 25 14:35:31 2024 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Jun 2024 04:35:31 +1000 Subject: Anonymous email users In-Reply-To: <20240625125954.4425a9d41eb8ef8fd92f4af0@g{oogle}mail.com> References: <006901dabea6$4a159d30$de40d790$@gmail.com> <4CB44E85-2DF4-47DE-844B-DA7371D80836@barrys-emacs.org> <20240625125954.4425a9d41eb8ef8fd92f4af0@g{oogle}mail.com> Message-ID: On Wed, 26 Jun 2024 at 03:40, Anton Shepelev via Python-list wrote: > > Chris Angelico to dn: > > > > Python mailing-lists are covered by the Code of Conduct > > > and monitored by ListAdmins. Thus, there are controls > > > which limit the impact which advertisers and others with > > > non-pythonic aims might otherwise exert! > > > > So long as there's a newsgroup gateway, those controls are > > toothless. > > The gateway operator can have the usual anti-spam software > installed Anti-spam is not the same as CoC and admins, though. Without putting an actual moderation barrier in there, it's still toothless. (Yes, there are a scant few posters who've been blocked from the gateway, but it's rare.) ChrisA From mk1853387 at gmail.com Wed Jun 26 11:29:00 2024 From: mk1853387 at gmail.com (marc nicole) Date: Wed, 26 Jun 2024 17:29:00 +0200 Subject: How to install tensorflow on Python 2.7 in Windows? Message-ID: Browsing the available version of tensorflow for the dates before January 2021 (date when Python 2.7 stopped being supported) I can't find a tensorflow version for Python 2.7 that works under Windows. The reference site I use is https://pypi.org/project/tensorflow/ Anybody can point out a compatible .whl file with Python 2.7 and Windows? From mats at wichmann.us Wed Jun 26 15:40:12 2024 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 26 Jun 2024 13:40:12 -0600 Subject: [Tutor] How to install tensorflow on Python 2.7 in Windows? In-Reply-To: References: Message-ID: On 6/26/24 09:29, marc nicole wrote: > Browsing the available version of tensorflow for the dates before January > 2021 (date when Python 2.7 stopped being supported) I can't find a > tensorflow version for Python 2.7 that works under Windows. > > The reference site I use is https://pypi.org/project/tensorflow/ > > Anybody can point out a compatible .whl file with Python 2.7 and Windows? The last version of tensorflow to support Python 2.7 was indeed 2.1, and I don't think there was *ever* an official Windows wheel for Python 2, but I'm not that expert to be completely sure. tensorflow support on Windows has never been good, and in a way they've given up, at least part of the fight: they no longer produce official releases for Windows with GPU support (although you may be able to get one from the vendor that produces the GPU hardware like Nvidia or Intel, or from a third party like Amazon Web Services). The official recommendation for WIndows used to be "build your own" (which nearly always failed), then for a few years they tried making Windows builds, now the new "best practice" recommendation is to install on WSL if you want to run on a Windows box (this *might* work for you, unless you're also on an ancient Windows that won't run WSL). Or, try seeing if you can find a docker setup (which, again, will give you a Linux environment running tensorflow). Note that like your other problem, getting numpy going, this is going to be an uphill battle trying to cobble things together to run on 2.7. This is really the problem when something like Python goes out of date / out of support: it's not that it magically stops working, it's that vast amounts of the ecosystem around it stop providing support for *their* bits on the old version, and the combinations become progressively harder to make work. From thomas at python.org Thu Jun 27 15:59:19 2024 From: thomas at python.org (Thomas Wouters) Date: Thu, 27 Jun 2024 21:59:19 +0200 Subject: [RELEASE] Python 3.13.0 beta 3 released. Message-ID: The *next to last* Python 3.13 beta version, beta 3, is now released: https://www.python.org/downloads/release/python-3130b3/ *This is a beta preview of Python 3.13* Python 3.13 is still in development. This release, 3.13.0b3, is the third of four beta release previews of 3.13. Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their projects to support the new feature release. We *strongly encourage* maintainers of third-party Python projects to *test with 3.13* during the beta phase and report issues found to the Python bug tracker as soon as possible. While the release is planned to be feature complete entering the beta phase, it is possible that features may be modified or, in rare cases, deleted up until the start of the release candidate phase (Tuesday 2024-07-30). Our goal is to have no ABI changes after beta 4 and as few code changes as possible after 3.13.0rc1, the first release candidate. To achieve that, it will be *extremely important* to get as much exposure for 3.13 as possible during the beta phase. Please keep in mind that this is a preview release and its use is *not* recommended for production environments. Major new features of the 3.13 series, compared to 3.12 Some of the new major new features and changes in Python 3.13 are: New features - A new and improved interactive interpreter , based on PyPy ?s, featuring multi-line editing and color support, as well as colorized exception tracebacks . - An *experimental* free-threaded build mode , which disables the Global Interpreter Lock, allowing threads to run more concurrently. The build mode is available as an experimental feature in the Windows and macOS installers as well. - A preliminary, *experimental* JIT , providing the ground work for significant performance improvements. - The (cyclic) garbage collector is now incremental , which should mean shorter pauses for collection in programs with a lot of objects. - A modified version of mimalloc is now included, optional but enabled by default if supported by the platform, and required for the free-threaded build mode. - Docstrings now have their leading indentation stripped , reducing memory use and the size of .pyc files. (Most tools handling docstrings already strip leading indentation.) - The dbm module has a new dbm.sqlite3 backend that is used by default when creating new files. - The minimum supported macOS version was changed from 10.9 to *10.13 (High Sierra)*. Older macOS versions will not be supported going forward. Typing - Support for type defaults in type parameters . - A new type narrowing annotation , typing.TypeIs. - A new annotation for read-only items in TypeDicts . Removals and new deprecations - PEP 594 (Removing dead batteries from the standard library) scheduled removals of many deprecated modules: aifc, audioop, chunk, cgi, cgitb, crypt, imghdr, mailcap, msilib, nis, nntplib, ossaudiodev, pipes, sndhdr, spwd, sunau, telnetlib, uu, xdrlib, lib2to3. - Many other removals of deprecated classes, functions and methods in various standard library modules. - C API removals and deprecations . (Some removals present in alpha 1 were reverted in alpha 2, as the removals were deemed too disruptive at this time.) - New deprecations , most of which are scheduled for removal from Python 3.15 or 3.16. (Hey, *fellow core developer,* if a feature you find important is missing from this list, let Thomas know .) For more details on the changes to Python 3.13, see What?s new in Python 3.13 . The next pre-release of Python 3.13 will be 3.13.0b4, currently scheduled for 2024-07-16. More resources - Online Documentation - PEP 719 , 3.13 Release Schedule - Report bugs at https://github.com/python/cpython/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 efforts by volunteering yourself or through organization contributions to the Python Software Foundation. Regards from *scorchingly* hot Amsterdam (hey, we get good weather too!), Your release team, Thomas Wouters ?ukasz Langa Ned Deily Steve Dower -- Thomas Wouters From ml at fam-goebel.de Fri Jun 28 12:08:54 2024 From: ml at fam-goebel.de (Ulrich Goebel) Date: Fri, 28 Jun 2024 18:08:54 +0200 Subject: Difference method vs attribut = function Message-ID: <20240628180854.7ee713db744e9672ad668f36@fam-goebel.de> Hi, a class can have methods, and it can have attributes, which can hold a function. Both is well known, of course. My question: Is there any difference? The code snipped shows that both do what they should do. But __dict__ includes just the method, while dir detects the method and the attribute holding a function. My be that is the only difference? class MyClass: def __init__(self): functionAttribute = None def method(self): print("I'm a method") def function(): print("I'm a function passed to an attribute") mc = MyClass() mc.functionAttribute = function mc.method() mc.functionAttribute() print('Dict: ', mc.__dict__) # shows functionAttribute but not method print('Dir: ', dir(mc)) # shows both functionAttribute and method By the way: in my usecase I want to pass different functions to different instances of MyClass. It is in the context of a database app where I build Getters for database data and pass one Getter per instance. Thanks for hints Ulrich -- Ulrich Goebel From hjp-python at hjp.at Sat Jun 29 15:53:05 2024 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 29 Jun 2024 21:53:05 +0200 Subject: Difference method vs attribut = function In-Reply-To: <20240628180854.7ee713db744e9672ad668f36@fam-goebel.de> References: <20240628180854.7ee713db744e9672ad668f36@fam-goebel.de> Message-ID: <20240629195305.kxzys5ht7hottfup@hjp.at> On 2024-06-28 18:08:54 +0200, Ulrich Goebel via Python-list wrote: > a class can have methods, and it can have attributes, which can hold a > function. Both is well known, of course. > > My question: Is there any difference? > > The code snipped shows that both do what they should do. But __dict__ > includes just the method, The other way around: It includes only the attributes, not the methods. > while dir detects the method and the > attribute holding a function. My be that is the only difference? > > > class MyClass: > def __init__(self): > functionAttribute = None > > def method(self): > print("I'm a method") > > def function(): > print("I'm a function passed to an attribute") Here is the other main difference: The object is not passed implicitely to the function. You have no way to access mc here. You can create a method on the fly with types.MethodType: import types mc.functionAttribute = types.MethodType(function, mc) > By the way: in my usecase I want to pass different functions to > different instances of MyClass. It is in the context of a database app > where I build Getters for database data and pass one Getter per > instance. Or in this case, since each function is specific to one instance, you could just use a closure to capture the object. But that might be confusing to any future maintainers (e.g. yourself in 6 months), if the method doesn't actually behave like a method. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From mats at wichmann.us Sat Jun 29 16:03:13 2024 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 29 Jun 2024 14:03:13 -0600 Subject: Difference method vs attribut = function In-Reply-To: <20240628180854.7ee713db744e9672ad668f36@fam-goebel.de> References: <20240628180854.7ee713db744e9672ad668f36@fam-goebel.de> Message-ID: <5804d7a6-c434-4e03-bf44-f84f836536dd@wichmann.us> On 6/28/24 10:08, Ulrich Goebel via Python-list wrote: > By the way: in my usecase I want to pass different functions to different instances of MyClass. It is in the context of a database app where I build Getters for database data and pass one Getter per instance. If I understood what you're trying to accomplish, you could take a look here (possibly a bit complex for what you need). https://refactoring.guru/design-patterns/strategy/python/example From list1 at tompassin.net Sat Jun 29 16:01:49 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 29 Jun 2024 16:01:49 -0400 Subject: Difference method vs attribut = function In-Reply-To: <20240628180854.7ee713db744e9672ad668f36@fam-goebel.de> References: <20240628180854.7ee713db744e9672ad668f36@fam-goebel.de> Message-ID: <02720cd8-690a-41aa-afaa-548a7430c791@tompassin.net> On 6/28/2024 12:08 PM, Ulrich Goebel via Python-list wrote: > Hi, > > a class can have methods, and it can have attributes, which can hold a function. Both is well known, of course. > > My question: Is there any difference? > > The code snipped shows that both do what they should do. But __dict__ includes just the method, while dir detects the method and the attribute holding a function. My be that is the only difference? > > > class MyClass: > def __init__(self): > functionAttribute = None > > def method(self): > print("I'm a method") > > def function(): > print("I'm a function passed to an attribute") > > mc = MyClass() > mc.functionAttribute = function > > mc.method() > mc.functionAttribute() > > print('Dict: ', mc.__dict__) # shows functionAttribute but not method > print('Dir: ', dir(mc)) # shows both functionAttribute and method > > > By the way: in my usecase I want to pass different functions to different instances of MyClass. It is in the context of a database app where I build Getters for database data and pass one Getter per instance. > > Thanks for hints > Ulrich https://docs.python.org/3/library/functions.html#dir - object.__dict__? A dictionary or other mapping object used to store an object?s (writable) attributes. dir(object) ... With an argument, attempt to return a list of valid attributes for that object. "functionAttribute" is a class method, not an instance method. If you want an instance method: class MyClass: def __init__(self): functionAttribute = None self.instance_functionAttribute = None def method(self): print("I'm a method") From dieter.maurer at online.de Sun Jun 30 13:58:37 2024 From: dieter.maurer at online.de (dieter.maurer at online.de) Date: Sun, 30 Jun 2024 19:58:37 +0200 Subject: Difference method vs attribut = function In-Reply-To: <20240628180854.7ee713db744e9672ad668f36@fam-goebel.de> References: <20240628180854.7ee713db744e9672ad668f36@fam-goebel.de> Message-ID: <26241.40141.483093.401213@ixdm.fritz.box> Ulrich Goebel wrote at 2024-6-28 18:08 +0200: >Hi, > >a class can have methods, and it can have attributes, which can hold a function. Both is well known, of course. > >My question: Is there any difference? I think you should make the distinction "class versus instance attribute" rather than "mether versus function". If you look at the `__dict__` of an instance, you see only the instance variables (the class's `__dict__` gives you the (most) attributes of the class). You can access (most) class attributes via an instance; if a function is accessed in this way, it becomes (typically) a method.