From jon+usenet at unequivocal.eu Thu Feb 1 20:31:03 2024 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 2 Feb 2024 01:31:03 -0000 (UTC) Subject: Await expressions (Posting On Python-List Prohibited) References: Message-ID: On 2024-02-02, Lawrence D'Oliveiro wrote: > On 1 Feb 2024 10:09:10 GMT, Stefan Ram wrote: > >> Heck, even of the respected members of this newsgroup, IIRC, no one >> mentioned "__await__". > > It?s part of the definition of an ?awaitable?, if you had looked that up. > > To be fair, I've been using Python for well over quarter of a century, and I never knew it had a glossary. From avi.e.gross at gmail.com Sat Feb 3 11:14:10 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 3 Feb 2024 11:14:10 -0500 Subject: Extract lines from file, add to new files In-Reply-To: <146ad2c4-b243-47ed-87d5-c3f48fa2d3af@tompassin.net> References: <3acb2c7a-54a9-191d-b721-8f7180f32810@appl-ecosys.com> <146ad2c4-b243-47ed-87d5-c3f48fa2d3af@tompassin.net> Message-ID: <007001da56bc$05b5c590$112150b0$@gmail.com> This discussion has circled back to where it started. It illustrates quite a few points about how many different ways someone can do something as well as doing it using different tools and also about how others may see aspects of mission creep as they look for making it perfect when it need not be. I mean the OP wants a simple personal tool and is not currently concerned with lots of things. The data seems to be in a data base and can be extracted from there into one or two files mostly for convenience. Presumably, all the usual additions/deletions/modifications are being done in the DB. If so, then as long as his latest vision of having two synchronized files is done consistently by making both, they are in sync. In addition, it sounds like the original idea was a tad too simple. The OP wanted to add a single-line or so at the head of a message that simply interpolates a name. This could be handled with all kinds of form-letter-merge methods as well as search and replace methods of great generality. But, for now, the OP is asking for something truly simple and would be happy with a solution that is slow and clunky and uses a few utilities in a shell script on LINUX. I took a look at doing this on bash and ran into some surprises as this would have been trivial for me in a shell like ksh. Setting variables is now done in a subshell which was done why? All I know is if you could simply read a file one line at a time in a loop and set one or more variables, then it becomes easy to use something like combining an echo and a cat of the original message to make a message with a variable heading and feed that to the mailer. And if the storage format was CSV, again, you could easily peel it apart using something like cut or awk or whatever. The main reason for trying it in python may have been frustration with doing it as a shell script. Fair enough. But the idea of two files may have been made in the first place by the original idea of such a script. The question posed was sort of how to search in one and then somehow find the corresponding part of another. The mindset of the OP may have been focused in a direction we were not clear on. As an example, there are ways to search file A and get back a line number of the first match and then using perhaps another utility you ask it to scan file B and just print out that line number and nothing else. The current solution the OP is considering sounds like a loop that goes through both files in parallel. This would mean when one loop finds what it is looking for, the other delivers what is in the same location. That may work well enough for the purpose. But I have learned over the years that having a few well-designed tools and ideas and using them consistently, is often a good way to get results even if it is not as imaginative and efficient as some other. If you are allowed to design something from top to bottom, there may be very nice solutions. But if asked to just do one small part in a design that already feels it has solved other aspects, then suggesting they start over is often not taken well. LOL! I happen to think some storage format such as CSV would be a good idea IFF doing this in Python for some reasons I mentioned earlier. I am not in love with CSV and use other data formats as needed and some others would be fine as long as your toolkit included some easy and reliable way to read the contents in and manipulate to get your results. I do programming in multiple languages and whether I am using python or something like R, I often end up importing the data into some data.frame format, performing a pipeline of manipulations using it and perhaps other such structures and generating results and optionally saving some back to files. Tons of well-tested and comfortable tools can be used if the data is set up right so even when it can be easily done by hand, it may not be worth the effort as the standard tools and tricks work and work fast enough. Rich (AKA the OP) seems satisfied with having a solution. It may not be ideal but for his needs, ... -----Original Message----- From: Python-list On Behalf Of Thomas Passin via Python-list Sent: Wednesday, January 31, 2024 10:36 AM To: python-list at python.org Subject: Re: Extract lines from file, add to new files On 1/31/2024 9:05 AM, Rich Shepard via Python-list wrote: > On Tue, 30 Jan 2024, Thomas Passin via Python-list wrote: > >> If I had a script that's been working for 30 years, I'd probably just use >> Python to do the personalizing and let the rest of the bash script do the >> rest, like it always has. The Python program would pipe or send the >> personalized messages to the rest of the bash program. Something in that >> ballpark, anyway. > > Thomas, > > A bash shell script looks easier for me and more promising. Using a while > loop (one for the name file the other for the address file), and sed for > putting the name at the head of the message replacing a generic placeholder > should work with the existing for loop script. Sounds good. I'd still be a bit worried about the two files getting out of sync, as others have mentioned. -- https://mail.python.org/mailman/listinfo/python-list From avi.e.gross at gmail.com Sat Feb 3 11:33:23 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 3 Feb 2024 11:33:23 -0500 Subject: Extract lines from file, add to new files In-Reply-To: <17769063-0f0d-49ef-9599-88157690cefd@tompassin.net> References: <2a5eef2d-3d66-8cea-64eb-602ea5aff946@appl-ecosys.com> <9028bd96-dbc8-fbc1-8584-a965ef7def5d@appl-ecosys.com> <5cea1ab2-1848-41bd-8e5b-323fe55ba8c9@tompassin.net> <478e3bbe-db95-9533-595b-7a19a5e2cf@appl-ecosys.com> <004c01da53fd$9273b9e0$b75b2da0$@gmail.com> <17769063-0f0d-49ef-9599-88157690cefd@tompassin.net> Message-ID: <007701da56be$b4ae7cc0$1e0b7640$@gmail.com> Thomas, I have been thinking about the concept of being stingy with information as this is a fairly common occurrence when people ask for help. They often ask for what they think they want while people like us keep asking why they want that and perhaps offer guidance on how to get closer to what they NEED or a better way. In retrospect, Rich did give all the info he thought he needed. It boiled down to saying that he wants to distribute data into two files in such a way that finding an item in file A then lets him find the corresponding item in file B. He was not worried about how to make the files or what to do with the info afterward. He had those covered and was missing what he considered a central piece. And, it seems he programs in multiple languages and environments as needed and is not exactly a newbie. He just wanted a way to implement his overall design. We threw many solutions and ideas at him but some of us (like me) also got frustrated as some ideas were not received due to one objection or another that had not been mentioned earlier when it was not seen as important. I particularly notice a disconnect some of us had. Was this supposed to be a search that read only as much as needed to find something and stopped reading, or a sort of filter that returned zero or more matches and went to the end, or perhaps something that read entire files and swallowed them into data structures in memory and then searched and found corresponding entries, or maybe something else? All the above approaches could work but some designs not so much. For example, some files are too large. We, as programmers, often consciously or unconsciously look at many factors to try to zoom in on what approaches me might use. To be given minimal amounts of info can be frustrating. We worry about making a silly design. But the OP may want something minimal and not worry as long as it is fairly easy to program and works. We could have suggested something very simple like: Open both files A and B In a loop get a line from each. If the line from A is a match, do something with the current line from B. If you are getting only one, exit the loop. Or, if willing, we could have suggested any other file format, such as a CSV, in which the algorithm is similar but different as in: Open file A Read a line in a loop Split it in parts If the party of the first part matches something, use the party of the second part Or, of course, suggest they read the entire file, into a list of lines or a data.frame and use some tools that search all of it and produce results. I find I personally now often lean toward the latter approach but ages ago when memory and CPU were considerations and maybe garbage collection was not automatic, ... -----Original Message----- From: Python-list On Behalf Of Thomas Passin via Python-list Sent: Wednesday, January 31, 2024 7:25 AM To: python-list at python.org Subject: Re: Extract lines from file, add to new files On 1/30/2024 11:25 PM, avi.e.gross at gmail.com wrote: > Thomas, on some points we may see it differently. I'm mostly going by what the OP originally asked for back on Jan 11. He's been too stingy with information since then to be worth spending much time on, IMHO. > Some formats can be done simply but are maybe better done in somewhat > standard ways. > > Some of what the OP has is already tables in a database and that can > trivially be exported into a CSV file or other formats like your TSV file > and more. They can also import from there. As I mentioned, many spreadsheets > and all kinds of statistical programs tend to support some formats making it > quite flexible. > > Python has all kinds of functionality, such as in the pandas module, to read > in a CSV or write it out. And once you have the data structure in memory, al > kinds of queries and changes can be made fairly straightforwardly. As one > example, Rich has mentioned wanting finer control in selecting who gets some > version of the email based on concepts like market segmentation. He already > may have info like the STATE (as in Arizona) in his database. He might at > some point enlarge his schema so each entry is placed in one or more > categories and thus his CSV, once imported, can do the usual tasks of > selecting various rows and columns or doing joins or whatever. > > Mind you, another architecture could place quite a bit of work completely on > the back end and he could send SQL queries to the database from python and > get back his results into python which would then make the email messages > and pass them on to other functionality to deliver. This would remove any > need for files and just rely on the DB. > > There as as usual, too many choices and not necessarily one best answer. Of > course if this was a major product that would be heavily used, sure, you > could tweak and optimize. As it is, Rich is getting a chance to improve his > python skills no matter which way he goes. > > > > -----Original Message----- > From: Python-list On > Behalf Of Thomas Passin via Python-list > Sent: Tuesday, January 30, 2024 10:37 PM > To: python-list at python.org > Subject: Re: Extract lines from file, add to new files > > On 1/30/2024 12:21 PM, Rich Shepard via Python-list wrote: >> On Tue, 30 Jan 2024, Thomas Passin via Python-list wrote: >> >>> Fine, my toy example will still be applicable. But, you know, you haven't >>> told us enough to give you help. Do you want to replace text from values >>> in a file? That's been covered. Do you want to send the messages using >>> those libraries? You haven't said what you don't know how to do. >>> Something >>> else? What is it that you want to do that you don't know how? >> >> Thomas, >> >> For 30 years I've used a bash script using mailx to send messages to a > list >> of recipients. They have no salutation to personalize each one. Since I >> want >> to add that personalized salutation I decided to write a python script to >> replace the bash script. >> >> I have collected 11 docs explaining the smtplib and email modules and >> providing example scripts to apply them to send multiple individual >> messages >> with salutations and attachments. > > If I had a script that's been working for 30 years, I'd probably just > use Python to do the personalizing and let the rest of the bash script > do the rest, like it always has. The Python program would pipe or send > the personalized messages to the rest of the bash program. Something in > that ballpark, anyway. > >> Today I'm going to be reading these. They each recommend using .csv input >> files for names and addresses. My first search is learning whether I can >> write a single .csv file such as: >> "name1","address1" >> "mane2","address2" >> which I believe will work; and by inserting at the top of the message > block >> Hi, {yourname} >> the name in the .csv file will replace the bracketed place holder > If the file contents are going to be people's names and email addresses, > I would just tab separate them and split each line on the tab. Names > aren't going to include tabs so that would be safe. Email addresses > might theoretically include a tab inside a quoted name but that would be > extremely obscure and unlikely. No need for CSV, it would just add > complexity. > > data = f.readlines() > for d in data: > name, addr = line.split('\t') if line.strip() else ('', '') > >> Still much to learn and the batch of downloaded PDF files should educate >> me. >> >> Regards, >> >> Rich > -- https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Sat Feb 3 12:58:57 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 3 Feb 2024 12:58:57 -0500 Subject: Extract lines from file, add to new files In-Reply-To: <007701da56be$b4ae7cc0$1e0b7640$@gmail.com> References: <2a5eef2d-3d66-8cea-64eb-602ea5aff946@appl-ecosys.com> <9028bd96-dbc8-fbc1-8584-a965ef7def5d@appl-ecosys.com> <5cea1ab2-1848-41bd-8e5b-323fe55ba8c9@tompassin.net> <478e3bbe-db95-9533-595b-7a19a5e2cf@appl-ecosys.com> <004c01da53fd$9273b9e0$b75b2da0$@gmail.com> <17769063-0f0d-49ef-9599-88157690cefd@tompassin.net> <007701da56be$b4ae7cc0$1e0b7640$@gmail.com> Message-ID: <1edcbbc8-f785-4b72-aed3-d6131794989b@tompassin.net> In my view this whole thread became murky and complicated because the OP did not write down the requirements for the program. Requirements are needed to communicate with other people. An individual may not need to actually write down the requirements - depending on their complexity - but they always exist even if only vaguely in a person's mind. The requirements may include what tools or languages the person wants to use and why. If you are asking for help, you need to communicate the requirements to the people you are asking for help from. The OP may have thought the original post(s) contained enough of the requirements but as we know by now, they didn't. The person asking for help may not realize they don't know enough to write down all the requirements; an effort to do so may bring that lack to visibility. Mailing lists like these have a drawback that it's hard to impossible for someone not involved in a thread to learn anything general from it. We can write over and over again to please state clearly what you want to do and where the sticking points are, but newcomers post new questions without ever reading these pleas. Then good-hearted people who want to be helpful end up spending a lot of time trying to guess what is actually being asked for, and maybe never find out with enough clarity. Others take a guess and then spend time working up a solution that may or may not be on target. So please! before posting a request for help, write down the requirements as best you can figure them out, and then make sure that they are expressed such that the readers can understand. On 2/3/2024 11:33 AM, avi.e.gross at gmail.com wrote: > Thomas, > > I have been thinking about the concept of being stingy with information as > this is a fairly common occurrence when people ask for help. They often ask > for what they think they want while people like us keep asking why they want > that and perhaps offer guidance on how to get closer to what they NEED or a > better way. > > In retrospect, Rich did give all the info he thought he needed. It boiled > down to saying that he wants to distribute data into two files in such a way > that finding an item in file A then lets him find the corresponding item in > file B. He was not worried about how to make the files or what to do with > the info afterward. He had those covered and was missing what he considered > a central piece. And, it seems he programs in multiple languages and > environments as needed and is not exactly a newbie. He just wanted a way to > implement his overall design. > > We threw many solutions and ideas at him but some of us (like me) also got > frustrated as some ideas were not received due to one objection or another > that had not been mentioned earlier when it was not seen as important. > > I particularly notice a disconnect some of us had. Was this supposed to be a > search that read only as much as needed to find something and stopped > reading, or a sort of filter that returned zero or more matches and went to > the end, or perhaps something that read entire files and swallowed them into > data structures in memory and then searched and found corresponding entries, > or maybe something else? > > All the above approaches could work but some designs not so much. For > example, some files are too large. We, as programmers, often consciously or > unconsciously look at many factors to try to zoom in on what approaches me > might use. To be given minimal amounts of info can be frustrating. We worry > about making a silly design. But the OP may want something minimal and not > worry as long as it is fairly easy to program and works. > > We could have suggested something very simple like: > > Open both files A and B > In a loop get a line from each. If the line from A is a match, do something > with the current line from B. > If you are getting only one, exit the loop. > > Or, if willing, we could have suggested any other file format, such as a > CSV, in which the algorithm is similar but different as in: > > Open file A > Read a line in a loop > Split it in parts > If the party of the first part matches something, use the party of the > second part > > Or, of course, suggest they read the entire file, into a list of lines or a > data.frame and use some tools that search all of it and produce results. > > I find I personally now often lean toward the latter approach but ages ago > when memory and CPU were considerations and maybe garbage collection was not > automatic, ... > > > -----Original Message----- > From: Python-list On > Behalf Of Thomas Passin via Python-list > Sent: Wednesday, January 31, 2024 7:25 AM > To: python-list at python.org > Subject: Re: Extract lines from file, add to new files > > On 1/30/2024 11:25 PM, avi.e.gross at gmail.com wrote: >> Thomas, on some points we may see it differently. > > I'm mostly going by what the OP originally asked for back on Jan 11. > He's been too stingy with information since then to be worth spending > much time on, IMHO. > >> Some formats can be done simply but are maybe better done in somewhat >> standard ways. >> >> Some of what the OP has is already tables in a database and that can >> trivially be exported into a CSV file or other formats like your TSV file >> and more. They can also import from there. As I mentioned, many > spreadsheets >> and all kinds of statistical programs tend to support some formats making > it >> quite flexible. >> >> Python has all kinds of functionality, such as in the pandas module, to > read >> in a CSV or write it out. And once you have the data structure in memory, > al >> kinds of queries and changes can be made fairly straightforwardly. As one >> example, Rich has mentioned wanting finer control in selecting who gets > some >> version of the email based on concepts like market segmentation. He > already >> may have info like the STATE (as in Arizona) in his database. He might at >> some point enlarge his schema so each entry is placed in one or more >> categories and thus his CSV, once imported, can do the usual tasks of >> selecting various rows and columns or doing joins or whatever. >> >> Mind you, another architecture could place quite a bit of work completely > on >> the back end and he could send SQL queries to the database from python and >> get back his results into python which would then make the email messages >> and pass them on to other functionality to deliver. This would remove any >> need for files and just rely on the DB. >> >> There as as usual, too many choices and not necessarily one best answer. > Of >> course if this was a major product that would be heavily used, sure, you >> could tweak and optimize. As it is, Rich is getting a chance to improve > his >> python skills no matter which way he goes. >> >> >> >> -----Original Message----- >> From: Python-list > On >> Behalf Of Thomas Passin via Python-list >> Sent: Tuesday, January 30, 2024 10:37 PM >> To: python-list at python.org >> Subject: Re: Extract lines from file, add to new files >> >> On 1/30/2024 12:21 PM, Rich Shepard via Python-list wrote: >>> On Tue, 30 Jan 2024, Thomas Passin via Python-list wrote: >>> >>>> Fine, my toy example will still be applicable. But, you know, you > haven't >>>> told us enough to give you help. Do you want to replace text from values >>>> in a file? That's been covered. Do you want to send the messages using >>>> those libraries? You haven't said what you don't know how to do. >>>> Something >>>> else? What is it that you want to do that you don't know how? >>> >>> Thomas, >>> >>> For 30 years I've used a bash script using mailx to send messages to a >> list >>> of recipients. They have no salutation to personalize each one. Since I >>> want >>> to add that personalized salutation I decided to write a python script to >>> replace the bash script. >>> >>> I have collected 11 docs explaining the smtplib and email modules and >>> providing example scripts to apply them to send multiple individual >>> messages >>> with salutations and attachments. >> >> If I had a script that's been working for 30 years, I'd probably just >> use Python to do the personalizing and let the rest of the bash script >> do the rest, like it always has. The Python program would pipe or send >> the personalized messages to the rest of the bash program. Something in >> that ballpark, anyway. >> >>> Today I'm going to be reading these. They each recommend using .csv input >>> files for names and addresses. My first search is learning whether I can >>> write a single .csv file such as: >>> "name1","address1" >>> "mane2","address2" >>> which I believe will work; and by inserting at the top of the message >> block >>> Hi, {yourname} >>> the name in the .csv file will replace the bracketed place holder >> If the file contents are going to be people's names and email addresses, >> I would just tab separate them and split each line on the tab. Names >> aren't going to include tabs so that would be safe. Email addresses >> might theoretically include a tab inside a quoted name but that would be >> extremely obscure and unlikely. No need for CSV, it would just add >> complexity. >> >> data = f.readlines() >> for d in data: >> name, addr = line.split('\t') if line.strip() else ('', '') >> >>> Still much to learn and the batch of downloaded PDF files should educate >>> me. >>> >>> Regards, >>> >>> Rich >> > From mats at wichmann.us Sat Feb 3 13:56:37 2024 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 3 Feb 2024 11:56:37 -0700 Subject: Extract lines from file, add to new files In-Reply-To: <1edcbbc8-f785-4b72-aed3-d6131794989b@tompassin.net> References: <2a5eef2d-3d66-8cea-64eb-602ea5aff946@appl-ecosys.com> <9028bd96-dbc8-fbc1-8584-a965ef7def5d@appl-ecosys.com> <5cea1ab2-1848-41bd-8e5b-323fe55ba8c9@tompassin.net> <478e3bbe-db95-9533-595b-7a19a5e2cf@appl-ecosys.com> <004c01da53fd$9273b9e0$b75b2da0$@gmail.com> <17769063-0f0d-49ef-9599-88157690cefd@tompassin.net> <007701da56be$b4ae7cc0$1e0b7640$@gmail.com> <1edcbbc8-f785-4b72-aed3-d6131794989b@tompassin.net> Message-ID: <42adcf31-922b-463b-945d-ff1a895f8aaf@wichmann.us> On 2/3/24 10:58, Thomas Passin via Python-list wrote: > In my view this whole thread became murky and complicated because the OP > did not write down the requirements for the program.? Requirements are > needed to communicate with other people.? An individual may not need to > actually write down the requirements - depending on their complexity - > but they always exist even if only vaguely in a person's mind.? The > requirements may include what tools or languages the person wants to use > and why. > > If you are asking for help, you need to communicate the requirements to > the people you are asking for help from. > > The OP may have thought the original post(s) contained enough of the > requirements but as we know by now, they didn't. > > The person asking for help may not realize they don't know enough to > write down all the requirements; an effort to do so may bring that lack > to visibility. > > Mailing lists like these have a drawback that it's hard to impossible > for someone not involved in a thread to learn anything general from it. > We can write over and over again to please state clearly what you want > to do and where the sticking points are, but newcomers post new > questions without ever reading these pleas.? Then good-hearted people > who want to be helpful end up spending a lot of time trying to guess > what is actually being asked for, and maybe never find out with enough > clarity.? Others take a guess and then spend time working up a solution > that may or may not be on target. > > So please! before posting a request for help, write down the > requirements as best you can figure them out, and then make sure that > they are expressed such that the readers can understand. Indeed. I've occasionally practised the following technique (in some form) over the years without knowing it had grown a name, and wikipedia page to go with it. It may be handy to use to help come up with a clearer explanation before sending off a post to a mailing list or other static medium, because of the inevitable delays in going back and forth. Interactive formus like the Python Discord have a bit of an advantage in that you can try to tease out the intent more quickly. But as you say... a newcomer won't know this. https://en.wikipedia.org/wiki/Rubber_duck_debugging From avi.e.gross at gmail.com Sat Feb 3 14:43:48 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 3 Feb 2024 14:43:48 -0500 Subject: Extract lines from file, add to new files In-Reply-To: <1edcbbc8-f785-4b72-aed3-d6131794989b@tompassin.net> References: <2a5eef2d-3d66-8cea-64eb-602ea5aff946@appl-ecosys.com> <9028bd96-dbc8-fbc1-8584-a965ef7def5d@appl-ecosys.com> <5cea1ab2-1848-41bd-8e5b-323fe55ba8c9@tompassin.net> <478e3bbe-db95-9533-595b-7a19a5e2cf@appl-ecosys.com> <004c01da53fd$9273b9e0$b75b2da0$@gmail.com> <17769063-0f0d-49ef-9599-88157690cefd@tompassin.net> <007701da56be$b4ae7cc0$1e0b7640$@gmail.com> <1edcbbc8-f785-4b72-aed3-d6131794989b@tompassin.net> Message-ID: <009901da56d9$4e8b87b0$eba29710$@gmail.com> We substantially agree with that, Thomas. In the best of all possible worlds, someone who gets stuck will sit down and try to carefully spell out things in ways like you mention and, incidentally, may often catch the error or figure out how to do it and not even send in a request! LOL! I think a main thing that the OP and others can do is to not just be abstract but supply a small example including what output they expect and perhaps what they did not receive properly along with error messages. Rich had not tried doing what he wanted in python, yet. I don't know if he did any other parts yet. I think he was still in a somewhat abstract design state and hoping for someone to push him at something like a resource to continue and he did accept suggestions on what now seem somewhat random things to read as people guessed. In a sense, I and others can take some blame for the way we widened the problem while trying to look at it our own way. But looking back, I think Rich asked close to what he wanted. An example might have helped such as: 'I have information about multiple clients including an email address and a human name such as: user at domain.com Sally fido at bark.com Barky I want to save the info in a file or maybe two in such a way that when I write a program and ask it to send an email to "fido at bark.com" then it finds an entry that matches the email address and then uses that to find the matching name and sends a specified message with a specific salutation in front like "Dear Barky,". I was thinking of having two files with one having email address after another and the other having the corresponding names. I want to use python to search one file and then return the name in the other. Are there other and perhaps better ways commonly used to associate one keyword with a value?' Back to me. The above is not polished but might still have engendered a discussion such as how to keep the files synchronized. Yes, the OP could have added endless clauses saying that they are not asking how to create the data files or keep them synchronized but just how to match them. The reply in this case possibly could have suggested they count the lines they have read until the match and, assuming no blank lines are used, read a second file till the nth line. We might have been done quickly and THEN had a long discussion about other ways! I have participated, like you, in another forum designed for tutoring and I think the rules and expectations there may be a bit different. Over here, it is fairer to expect people to take a bit of time and ask clearer questions. We live and we learn and then Alzheimer's ... -----Original Message----- From: Python-list On Behalf Of Thomas Passin via Python-list Sent: Saturday, February 3, 2024 12:59 PM To: python-list at python.org Subject: Re: Extract lines from file, add to new files In my view this whole thread became murky and complicated because the OP did not write down the requirements for the program. Requirements are needed to communicate with other people. An individual may not need to actually write down the requirements - depending on their complexity - but they always exist even if only vaguely in a person's mind. The requirements may include what tools or languages the person wants to use and why. If you are asking for help, you need to communicate the requirements to the people you are asking for help from. The OP may have thought the original post(s) contained enough of the requirements but as we know by now, they didn't. The person asking for help may not realize they don't know enough to write down all the requirements; an effort to do so may bring that lack to visibility. Mailing lists like these have a drawback that it's hard to impossible for someone not involved in a thread to learn anything general from it. We can write over and over again to please state clearly what you want to do and where the sticking points are, but newcomers post new questions without ever reading these pleas. Then good-hearted people who want to be helpful end up spending a lot of time trying to guess what is actually being asked for, and maybe never find out with enough clarity. Others take a guess and then spend time working up a solution that may or may not be on target. So please! before posting a request for help, write down the requirements as best you can figure them out, and then make sure that they are expressed such that the readers can understand. On 2/3/2024 11:33 AM, avi.e.gross at gmail.com wrote: > Thomas, > > I have been thinking about the concept of being stingy with information as > this is a fairly common occurrence when people ask for help. They often ask > for what they think they want while people like us keep asking why they want > that and perhaps offer guidance on how to get closer to what they NEED or a > better way. > > In retrospect, Rich did give all the info he thought he needed. It boiled > down to saying that he wants to distribute data into two files in such a way > that finding an item in file A then lets him find the corresponding item in > file B. He was not worried about how to make the files or what to do with > the info afterward. He had those covered and was missing what he considered > a central piece. And, it seems he programs in multiple languages and > environments as needed and is not exactly a newbie. He just wanted a way to > implement his overall design. > > We threw many solutions and ideas at him but some of us (like me) also got > frustrated as some ideas were not received due to one objection or another > that had not been mentioned earlier when it was not seen as important. > > I particularly notice a disconnect some of us had. Was this supposed to be a > search that read only as much as needed to find something and stopped > reading, or a sort of filter that returned zero or more matches and went to > the end, or perhaps something that read entire files and swallowed them into > data structures in memory and then searched and found corresponding entries, > or maybe something else? > > All the above approaches could work but some designs not so much. For > example, some files are too large. We, as programmers, often consciously or > unconsciously look at many factors to try to zoom in on what approaches me > might use. To be given minimal amounts of info can be frustrating. We worry > about making a silly design. But the OP may want something minimal and not > worry as long as it is fairly easy to program and works. > > We could have suggested something very simple like: > > Open both files A and B > In a loop get a line from each. If the line from A is a match, do something > with the current line from B. > If you are getting only one, exit the loop. > > Or, if willing, we could have suggested any other file format, such as a > CSV, in which the algorithm is similar but different as in: > > Open file A > Read a line in a loop > Split it in parts > If the party of the first part matches something, use the party of the > second part > > Or, of course, suggest they read the entire file, into a list of lines or a > data.frame and use some tools that search all of it and produce results. > > I find I personally now often lean toward the latter approach but ages ago > when memory and CPU were considerations and maybe garbage collection was not > automatic, ... > > > -----Original Message----- > From: Python-list On > Behalf Of Thomas Passin via Python-list > Sent: Wednesday, January 31, 2024 7:25 AM > To: python-list at python.org > Subject: Re: Extract lines from file, add to new files > > On 1/30/2024 11:25 PM, avi.e.gross at gmail.com wrote: >> Thomas, on some points we may see it differently. > > I'm mostly going by what the OP originally asked for back on Jan 11. > He's been too stingy with information since then to be worth spending > much time on, IMHO. > >> Some formats can be done simply but are maybe better done in somewhat >> standard ways. >> >> Some of what the OP has is already tables in a database and that can >> trivially be exported into a CSV file or other formats like your TSV file >> and more. They can also import from there. As I mentioned, many > spreadsheets >> and all kinds of statistical programs tend to support some formats making > it >> quite flexible. >> >> Python has all kinds of functionality, such as in the pandas module, to > read >> in a CSV or write it out. And once you have the data structure in memory, > al >> kinds of queries and changes can be made fairly straightforwardly. As one >> example, Rich has mentioned wanting finer control in selecting who gets > some >> version of the email based on concepts like market segmentation. He > already >> may have info like the STATE (as in Arizona) in his database. He might at >> some point enlarge his schema so each entry is placed in one or more >> categories and thus his CSV, once imported, can do the usual tasks of >> selecting various rows and columns or doing joins or whatever. >> >> Mind you, another architecture could place quite a bit of work completely > on >> the back end and he could send SQL queries to the database from python and >> get back his results into python which would then make the email messages >> and pass them on to other functionality to deliver. This would remove any >> need for files and just rely on the DB. >> >> There as as usual, too many choices and not necessarily one best answer. > Of >> course if this was a major product that would be heavily used, sure, you >> could tweak and optimize. As it is, Rich is getting a chance to improve > his >> python skills no matter which way he goes. >> >> >> >> -----Original Message----- >> From: Python-list > On >> Behalf Of Thomas Passin via Python-list >> Sent: Tuesday, January 30, 2024 10:37 PM >> To: python-list at python.org >> Subject: Re: Extract lines from file, add to new files >> >> On 1/30/2024 12:21 PM, Rich Shepard via Python-list wrote: >>> On Tue, 30 Jan 2024, Thomas Passin via Python-list wrote: >>> >>>> Fine, my toy example will still be applicable. But, you know, you > haven't >>>> told us enough to give you help. Do you want to replace text from values >>>> in a file? That's been covered. Do you want to send the messages using >>>> those libraries? You haven't said what you don't know how to do. >>>> Something >>>> else? What is it that you want to do that you don't know how? >>> >>> Thomas, >>> >>> For 30 years I've used a bash script using mailx to send messages to a >> list >>> of recipients. They have no salutation to personalize each one. Since I >>> want >>> to add that personalized salutation I decided to write a python script to >>> replace the bash script. >>> >>> I have collected 11 docs explaining the smtplib and email modules and >>> providing example scripts to apply them to send multiple individual >>> messages >>> with salutations and attachments. >> >> If I had a script that's been working for 30 years, I'd probably just >> use Python to do the personalizing and let the rest of the bash script >> do the rest, like it always has. The Python program would pipe or send >> the personalized messages to the rest of the bash program. Something in >> that ballpark, anyway. >> >>> Today I'm going to be reading these. They each recommend using .csv input >>> files for names and addresses. My first search is learning whether I can >>> write a single .csv file such as: >>> "name1","address1" >>> "mane2","address2" >>> which I believe will work; and by inserting at the top of the message >> block >>> Hi, {yourname} >>> the name in the .csv file will replace the bracketed place holder >> If the file contents are going to be people's names and email addresses, >> I would just tab separate them and split each line on the tab. Names >> aren't going to include tabs so that would be safe. Email addresses >> might theoretically include a tab inside a quoted name but that would be >> extremely obscure and unlikely. No need for CSV, it would just add >> complexity. >> >> data = f.readlines() >> for d in data: >> name, addr = line.split('\t') if line.strip() else ('', '') >> >>> Still much to learn and the batch of downloaded PDF files should educate >>> me. >>> >>> Regards, >>> >>> Rich >> > -- https://mail.python.org/mailman/listinfo/python-list From PythonList at DancesWithMice.info Sat Feb 3 17:02:17 2024 From: PythonList at DancesWithMice.info (dn) Date: Sun, 4 Feb 2024 11:02:17 +1300 Subject: Extract lines from file, add to new files In-Reply-To: <1edcbbc8-f785-4b72-aed3-d6131794989b@tompassin.net> References: <2a5eef2d-3d66-8cea-64eb-602ea5aff946@appl-ecosys.com> <9028bd96-dbc8-fbc1-8584-a965ef7def5d@appl-ecosys.com> <5cea1ab2-1848-41bd-8e5b-323fe55ba8c9@tompassin.net> <478e3bbe-db95-9533-595b-7a19a5e2cf@appl-ecosys.com> <004c01da53fd$9273b9e0$b75b2da0$@gmail.com> <17769063-0f0d-49ef-9599-88157690cefd@tompassin.net> <007701da56be$b4ae7cc0$1e0b7640$@gmail.com> <1edcbbc8-f785-4b72-aed3-d6131794989b@tompassin.net> Message-ID: <1c43f539-ec95-4421-8809-e057b19b0bfa@DancesWithMice.info> Every trainer, in any field, has to deal with these problems - all the time, and over-and-over. On 4/02/24 06:58, Thomas Passin via Python-list wrote: > In my view this whole thread became murky and complicated because the OP > did not write down the requirements for the program.? Requirements are > needed to communicate with other people.? An individual may not need to > actually write down the requirements - depending on their complexity - > but they always exist even if only vaguely in a person's mind.? The > requirements may include what tools or languages the person wants to use > and why. > > If you are asking for help, you need to communicate the requirements to > the people you are asking for help from. > > The OP may have thought the original post(s) contained enough of the > requirements but as we know by now, they didn't. There is another possible interpretation in such situations (not necessarily this one): that the person is fixated on a particular solution (and unable/unwilling to adjust his/her thinking to consider more widely). Thus, the question is not: 'here's an entire problem, how can it be solved', but more: 'I have a solution, and want help to implement it (and only it) just-so'. The latter is an interesting psychology: 1 an experienced person who is trying to translate from one tool to another (Python), but discovers that a word-for-word solution is difficult because of the artificial-constraints they've placed on the situation. 2 a beginner who doesn't know what (s)he doesn't know and comes-up with an idea, but fails to appreciate that there is likely more than one path to the goal. > The person asking for help may not realize they don't know enough to > write down all the requirements; an effort to do so may bring that lack > to visibility. In the case of 'Beginners' this should probably be taken-as-read! Which is why we will always find ourselves asking questions or 'please give more information'... However, there are other reasons, eg corporate concerns or personality; why people don't want to give more information. The former is reasonable (have suffered from same myself). The latter may reveal that the person is 'difficult to deal with'... > Mailing lists like these have a drawback that it's hard to impossible > for someone not involved in a thread to learn anything general from it. > We can write over and over again to please state clearly what you want > to do and where the sticking points are, but newcomers post new > questions without ever reading these pleas.? Then good-hearted people > who want to be helpful end up spending a lot of time trying to guess > what is actually being asked for, and maybe never find out with enough > clarity.? Others take a guess and then spend time working up a solution > that may or may not be on target. > > So please! before posting a request for help, write down the > requirements as best you can figure them out, and then make sure that > they are expressed such that the readers can understand. Unfortunately, if the person doesn't understand the problem (leave-aside any ideas of solution), then (s)he will not be able to clearly communicate same to us, in any way, shape, or form... Which brings one to the question: if a person cannot express the problem clearly and completely, is (s)he suited to development work? If the problem is not understood, could 'the solution' ever be more than an exercise in hope? (prototyping and experimentation aside) Yes, it is frustrating to invest time and effort in helping someone, only for same to disappear 'into a black hole'. The lack of response seems to indicate a lack of respect or appreciation. Is this perhaps part of today's "consumer" life-style, where so few are contributors or creators? On the other side of that coin: do the people who make assumptions and (kindly) blaze-ahead with 'a solution', actually help the conversation? If the assumptions are correct, yes! What if they are not? ...and don't get me started on folk who want us to do their training-assignments or build some application, for them! As a slight aside: on one training-course DiscussionList/BulletinBoard set-up, if a trainee asked a question without a descriptive title/SubjectLine, eg "Python not working" or "Urgent: please help"; I asked them to re-post with a title that would help others in a similar situation find the topic - and closed the original thread. Some found it "brutal" - probably skewing towards those who felt "Urgent" because they'd left things too close to deadline. Others joined the (later) thread because they could identify the topic and realise their interest in learning or contributing to the conversation... Time pressures lead to a multitude of evils! There's a quotation that goes something like "the poor will be with your always"? (?possibly Biblical) Whether we (here) are talking about 'poor' manners, 'poor' understanding, 'poor' communication skills, 'poor' Python knowledge, or whatever; isn't such one of the rationales for this DiscussionList? That said, we're all volunteering our (valuable) time! -- Regards, =dn From list1 at tompassin.net Sat Feb 3 17:41:41 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 3 Feb 2024 17:41:41 -0500 Subject: Extract lines from file, add to new files In-Reply-To: <1c43f539-ec95-4421-8809-e057b19b0bfa@DancesWithMice.info> References: <2a5eef2d-3d66-8cea-64eb-602ea5aff946@appl-ecosys.com> <9028bd96-dbc8-fbc1-8584-a965ef7def5d@appl-ecosys.com> <5cea1ab2-1848-41bd-8e5b-323fe55ba8c9@tompassin.net> <478e3bbe-db95-9533-595b-7a19a5e2cf@appl-ecosys.com> <004c01da53fd$9273b9e0$b75b2da0$@gmail.com> <17769063-0f0d-49ef-9599-88157690cefd@tompassin.net> <007701da56be$b4ae7cc0$1e0b7640$@gmail.com> <1edcbbc8-f785-4b72-aed3-d6131794989b@tompassin.net> <1c43f539-ec95-4421-8809-e057b19b0bfa@DancesWithMice.info> Message-ID: <97be7743-dfdb-42e6-b844-7030aa4557c7@tompassin.net> On 2/3/2024 5:02 PM, dn via Python-list wrote: > Every trainer, in any field, has to deal with these problems - all the > time, and over-and-over. > > > On 4/02/24 06:58, Thomas Passin via Python-list wrote: >> In my view this whole thread became murky and complicated because the >> OP did not write down the requirements for the program.? Requirements >> are needed to communicate with other people.? An individual may not >> need to actually write down the requirements - depending on their >> complexity - but they always exist even if only vaguely in a person's >> mind.? The requirements may include what tools or languages the person >> wants to use and why. >> >> If you are asking for help, you need to communicate the requirements >> to the people you are asking for help from. >> >> The OP may have thought the original post(s) contained enough of the >> requirements but as we know by now, they didn't. > > There is another possible interpretation in such situations (not > necessarily this one): that the person is fixated on a particular > solution (and unable/unwilling to adjust his/her thinking to consider > more widely). > > Thus, the question is not: 'here's an entire problem, how can it be > solved', but more: 'I have a solution, and want help to implement it > (and only it) just-so'. > > > The latter is an interesting psychology: > > 1 > an experienced person who is trying to translate from one tool to > another (Python), but discovers that a word-for-word solution is > difficult because of the artificial-constraints they've placed on the > situation. > > 2 > a beginner who doesn't know what (s)he doesn't know and comes-up with an > idea, but fails to appreciate that there is likely more than one path to > the goal. > > >> The person asking for help may not realize they don't know enough to >> write down all the requirements; an effort to do so may bring that >> lack to visibility. > > In the case of 'Beginners' this should probably be taken-as-read! > > Which is why we will always find ourselves asking questions or 'please > give more information'... > > > However, there are other reasons, eg corporate concerns or personality; > why people don't want to give more information. The former is reasonable > (have suffered from same myself). The latter may reveal that the person > is 'difficult to deal with'... > > >> Mailing lists like these have a drawback that it's hard to impossible >> for someone not involved in a thread to learn anything general from >> it. We can write over and over again to please state clearly what you >> want to do and where the sticking points are, but newcomers post new >> questions without ever reading these pleas.? Then good-hearted people >> who want to be helpful end up spending a lot of time trying to guess >> what is actually being asked for, and maybe never find out with enough >> clarity.? Others take a guess and then spend time working up a >> solution that may or may not be on target. >> >> So please! before posting a request for help, write down the >> requirements as best you can figure them out, and then make sure that >> they are expressed such that the readers can understand. > > Unfortunately, if the person doesn't understand the problem (leave-aside > any ideas of solution), then (s)he will not be able to clearly > communicate same to us, in any way, shape, or form... > > Which brings one to the question: if a person cannot express the problem > clearly and completely, is (s)he suited to development work? If the > problem is not understood, could 'the solution' ever be more than an > exercise in hope? > (prototyping and experimentation aside) Pairs programming can be fun and productive, if you are lucky to have the right person to work with. I've had one person like that over the years. > Yes, it is frustrating to invest time and effort in helping someone, > only for same to disappear 'into a black hole'. The lack of response > seems to indicate a lack of respect or appreciation. Is this perhaps > part of today's "consumer" life-style, where so few are contributors or > creators? > > > On the other side of that coin: do the people who make assumptions and > (kindly) blaze-ahead with 'a solution', actually help the conversation? > If the assumptions are correct, yes! What if they are not? > > > ...and don't get me started on folk who want us to do their > training-assignments or build some application, for them! > > > As a slight aside: on one training-course DiscussionList/BulletinBoard > set-up, if a trainee asked a question without a descriptive > title/SubjectLine, eg "Python not working" or "Urgent: please help"; I > asked them to re-post with a title that would help others in a similar > situation find the topic - and closed the original thread. > > Some found it "brutal" - probably skewing towards those who felt > "Urgent" because they'd left things too close to deadline. Others joined > the (later) thread because they could identify the topic and realise > their interest in learning or contributing to the conversation... > > > Time pressures lead to a multitude of evils! > > > There's a quotation that goes something like "the poor will be with your > always"? > (?possibly Biblical) > > Whether we (here) are talking about 'poor' manners, 'poor' > understanding, 'poor' communication skills, 'poor' Python knowledge, or > whatever; isn't such one of the rationales for this DiscussionList? > > That said, we're all volunteering our (valuable) time! From avi.e.gross at gmail.com Sat Feb 3 19:20:18 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 3 Feb 2024 19:20:18 -0500 Subject: Extract lines from file, add to new files In-Reply-To: <1c43f539-ec95-4421-8809-e057b19b0bfa@DancesWithMice.info> References: <2a5eef2d-3d66-8cea-64eb-602ea5aff946@appl-ecosys.com> <9028bd96-dbc8-fbc1-8584-a965ef7def5d@appl-ecosys.com> <5cea1ab2-1848-41bd-8e5b-323fe55ba8c9@tompassin.net> <478e3bbe-db95-9533-595b-7a19a5e2cf@appl-ecosys.com> <004c01da53fd$9273b9e0$b75b2da0$@gmail.com> <17769063-0f0d-49ef-9599-88157690cefd@tompassin.net> <007701da56be$b4ae7cc0$1e0b7640$@gmail.com> <1edcbbc8-f785-4b72-aed3-d6131794989b@tompassin.net> <1c43f539-ec95-4421-8809-e057b19b0bfa@DancesWithMice.info> Message-ID: <010401da56ff$ef5ab780$ce102680$@gmail.com> Dave, You and I have had some experience in teaching or tutoring others and I think it fair to say our motivation is closer to teaching someone how they can fish for themselves rather than just handing them a fully-cooked fish. My favorite kinds of questions, thus, include someone who explains what they are trying to do and shows some code along with indications of what it produced (including error messages) and what it should produce. Then the question should not be a request to just FIX THIS or WRITE IT FOR ME but asking if someone can show what they did wrong with some idea where it went wrong. This may not be so common but it allows faster and easier help. But others out there probably can be helped including people who want suggestions of approaches to try. We have discussed some issues here and elsewhere where some purists tend to want to stick with close to basic aspects of the language. In some R communities, some get upset if someone asks a question (or others supply an answer) using non-official add-ons called the tidyverse and I suspect some here don't really like discussions that focus mainly on numpy/pandas or so many other modules. Yet, the reality is, that except for students who are supposed to be learning the basics of the language and show solutions compatible with what is being taught in class, others can and should be open to simple solutions using non-standard tools that are widely available and vetted. If a student is asked to use some method to calculate a value like pi, then suggesting they use math.pi is not useful. But if the assignment is to do something in trigonometry, it seems a good thing to use as a part of a larger solution rather than either embedding a constant to N decimal places or calculating it on the fly. I think people like us who volunteer to reply should consider our choices too. I think it is fair to reply, as I saw on the tutor forum, that the code shown uses a method that is not the way the replier would do it but nonetheless offer some thoughts on particular python coding errors. I am talking about someone who wanted to implement a binary tree using a numpy array or something with minimal explanation and demanded a fix. They never supplied enough info and I think the few who replied backed away. As you mention, they seemed resistant to starting over and using data structures that are perhaps more amenable, and in any case, the code shown seemed mostly focused on how to make random and non-redundant names. I will end with a comment. I have heard of interview techniques for a job where they deliberately supply a problem in which the goal is not so much to be easy to solve in front of them in real time but to watch how the person looking for a job responds to the uncertainties and asks follow-up questions or verbalizes things like, if it is like this, I might use this technique but if you also need that then ... So, I shudder to think what happens if someone being interviewed turns around and asks us and further confuses things with changes to make it harder to recognize they are asking for outside help. The answer expected may well be to NOT use say the older versions of PASCAL to do something but switch to something better suited (and for that matter available.) I would not want to program the DES encryption/decryption method in Pascal again! And these days, it seems much better to just find a module or package that meets such needs. Avi -----Original Message----- From: Python-list On Behalf Of dn via Python-list Sent: Saturday, February 3, 2024 5:02 PM To: python-list at python.org Subject: Re: Extract lines from file, add to new files Every trainer, in any field, has to deal with these problems - all the time, and over-and-over. On 4/02/24 06:58, Thomas Passin via Python-list wrote: > In my view this whole thread became murky and complicated because the OP > did not write down the requirements for the program. Requirements are > needed to communicate with other people. An individual may not need to > actually write down the requirements - depending on their complexity - > but they always exist even if only vaguely in a person's mind. The > requirements may include what tools or languages the person wants to use > and why. > > If you are asking for help, you need to communicate the requirements to > the people you are asking for help from. > > The OP may have thought the original post(s) contained enough of the > requirements but as we know by now, they didn't. There is another possible interpretation in such situations (not necessarily this one): that the person is fixated on a particular solution (and unable/unwilling to adjust his/her thinking to consider more widely). Thus, the question is not: 'here's an entire problem, how can it be solved', but more: 'I have a solution, and want help to implement it (and only it) just-so'. The latter is an interesting psychology: 1 an experienced person who is trying to translate from one tool to another (Python), but discovers that a word-for-word solution is difficult because of the artificial-constraints they've placed on the situation. 2 a beginner who doesn't know what (s)he doesn't know and comes-up with an idea, but fails to appreciate that there is likely more than one path to the goal. > The person asking for help may not realize they don't know enough to > write down all the requirements; an effort to do so may bring that lack > to visibility. In the case of 'Beginners' this should probably be taken-as-read! Which is why we will always find ourselves asking questions or 'please give more information'... However, there are other reasons, eg corporate concerns or personality; why people don't want to give more information. The former is reasonable (have suffered from same myself). The latter may reveal that the person is 'difficult to deal with'... > Mailing lists like these have a drawback that it's hard to impossible > for someone not involved in a thread to learn anything general from it. > We can write over and over again to please state clearly what you want > to do and where the sticking points are, but newcomers post new > questions without ever reading these pleas. Then good-hearted people > who want to be helpful end up spending a lot of time trying to guess > what is actually being asked for, and maybe never find out with enough > clarity. Others take a guess and then spend time working up a solution > that may or may not be on target. > > So please! before posting a request for help, write down the > requirements as best you can figure them out, and then make sure that > they are expressed such that the readers can understand. Unfortunately, if the person doesn't understand the problem (leave-aside any ideas of solution), then (s)he will not be able to clearly communicate same to us, in any way, shape, or form... Which brings one to the question: if a person cannot express the problem clearly and completely, is (s)he suited to development work? If the problem is not understood, could 'the solution' ever be more than an exercise in hope? (prototyping and experimentation aside) Yes, it is frustrating to invest time and effort in helping someone, only for same to disappear 'into a black hole'. The lack of response seems to indicate a lack of respect or appreciation. Is this perhaps part of today's "consumer" life-style, where so few are contributors or creators? On the other side of that coin: do the people who make assumptions and (kindly) blaze-ahead with 'a solution', actually help the conversation? If the assumptions are correct, yes! What if they are not? ...and don't get me started on folk who want us to do their training-assignments or build some application, for them! As a slight aside: on one training-course DiscussionList/BulletinBoard set-up, if a trainee asked a question without a descriptive title/SubjectLine, eg "Python not working" or "Urgent: please help"; I asked them to re-post with a title that would help others in a similar situation find the topic - and closed the original thread. Some found it "brutal" - probably skewing towards those who felt "Urgent" because they'd left things too close to deadline. Others joined the (later) thread because they could identify the topic and realise their interest in learning or contributing to the conversation... Time pressures lead to a multitude of evils! There's a quotation that goes something like "the poor will be with your always"? (?possibly Biblical) Whether we (here) are talking about 'poor' manners, 'poor' understanding, 'poor' communication skills, 'poor' Python knowledge, or whatever; isn't such one of the rationales for this DiscussionList? That said, we're all volunteering our (valuable) time! -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list From janburse at fastmail.fm Fri Feb 2 18:45:18 2024 From: janburse at fastmail.fm (Mild Shock) Date: Sat, 3 Feb 2024 00:45:18 +0100 Subject: Await expressions (Posting On Python-List Prohibited) In-Reply-To: References: Message-ID: I am still waiting for async files in the style of nodejs that works on windows and is bundled with the main python distribution. I am not very fond on doing something like adding listeners to a file descriptor, in nodejs async files are based on callbacks not on listeners. Whats the roadmap here? Lawrence D'Oliveiro schrieb: > On 2 Feb 2024 09:12:06 GMT, Stefan Ram wrote: > >> |The IO part of the event loop is built upon a single crucial >> |function called "select". > > select(2) has limitations. Better to use poll(2). Depending on *nix > variant, other more advanced alternatives may also be available > . > From janburse at fastmail.fm Fri Feb 2 18:50:25 2024 From: janburse at fastmail.fm (Mild Shock) Date: Sat, 3 Feb 2024 00:50:25 +0100 Subject: Await expressions (Posting On Python-List Prohibited) In-Reply-To: References: Message-ID: And whats the roadmap for an asyncified module loader, is this on the radar of Python? Mild Shock schrieb: > > I am still waiting for async files in the > style of nodejs that works on windows and > > is bundled with the main python distribution. > I am not very? fond on doing something > > like adding listeners to a file descriptor, > in nodejs async files are based on callbacks > > not on listeners. Whats the roadmap here? > > Lawrence D'Oliveiro schrieb: >> On 2 Feb 2024 09:12:06 GMT, Stefan Ram wrote: >> >>> |The IO part of the event loop is built upon a single crucial >>> |function called "select". >> >> select(2) has limitations. Better to use poll(2). Depending on *nix >> variant, other more advanced alternatives may also be available >> . >> > From janburse at fastmail.fm Sat Feb 3 04:03:34 2024 From: janburse at fastmail.fm (Mild Shock) Date: Sat, 3 Feb 2024 10:03:34 +0100 Subject: Await expressions (Posting On Python-List Prohibited) In-Reply-To: References: Message-ID: The docu tells me: Windows loop.add_reader() and loop.add_writer() only accept socket handles (e.g. pipe file descriptors are not supported). https://docs.python.org/3/library/asyncio-platforms.html Alternatives are aiofiles and anyio and maybe more, but not sure whether they span all platforms, i.e. unix, windows and mac or whether they have similar restrictions. Theoretically on Windows IOCP should also cover file handles: https://en.wikipedia.org/wiki/Input/output_completion_port Its use by libuv the basis for node.js. Lawrence D'Oliveiro schrieb: > On Sat, 3 Feb 2024 00:45:18 +0100, Mild Shock wrote: > >> ... that works on windows ... > > You lost me there. > From janburse at fastmail.fm Sat Feb 3 04:15:44 2024 From: janburse at fastmail.fm (Mild Shock) Date: Sat, 3 Feb 2024 10:15:44 +0100 Subject: Await expressions (Posting On Python-List Prohibited) In-Reply-To: References: Message-ID: Funny source code tells me IOCP is used; proactor is only implemented on Windows with IOCP. https://github.com/python/cpython/blob/3.12/Lib/asyncio/proactor_events.py But maybe the focus is more on networking than file system. But it has sock_sendfile() that might avoid copying data to userspace. Mild Shock schrieb: > The docu tells me: > > Windows > loop.add_reader() and loop.add_writer() only accept > socket handles (e.g. pipe file descriptors are not supported). > https://docs.python.org/3/library/asyncio-platforms.html > > Alternatives are aiofiles and anyio and maybe more, > but not sure whether they span all platforms, i.e. unix, > windows and mac or whether they have similar restrictions. > > Theoretically on Windows IOCP should also cover file handles: > https://en.wikipedia.org/wiki/Input/output_completion_port > > Its use by libuv the basis for node.js. > > Lawrence D'Oliveiro schrieb: >> On Sat, 3 Feb 2024 00:45:18 +0100, Mild Shock wrote: >> >>> ... that works on windows ... >> >> You lost me there. >> > From gelukt at hotmail.com Sat Feb 3 18:02:05 2024 From: gelukt at hotmail.com (gelukt gelukt) Date: Sat, 3 Feb 2024 23:02:05 +0000 Subject: Error pd.set_option('display.width', 10000) In-Reply-To: References: Message-ID: Dear, While running a code, I get the error below: What does this error mean? How can I fix this error? C:\Users\brech\Desktop\Crypto\venv\Scripts\python.exe "C:/Users/brech/Desktop/Crypto/Project/aaa Arbitrage.py" Traceback (most recent call last): File "C:\Users\brech\Desktop\Crypto\Project\aaa Arbitrage.py", line 458, in methode() File "C:\Users\brech\Desktop\Crypto\Project\aaa Arbitrage.py", line 49, in methode wb.sheets[website]['A' + str(1+a)].value = inputString[startIndex:startIndex + 30000] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\main.py", line 2411, in value conversion.write(data, self, self._options) File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\conversion\__init__.py", line 102, in write pipeline(ctx) File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\conversion\framework.py", line 79, in __call__ stage(*args, **kwargs) File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\conversion\standard.py", line 75, in __call__ self._write_value(ctx.range, ctx.value, scalar) File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\conversion\standard.py", line 63, in _write_value rng.raw_value = value ^^^^^^^^^^^^^ File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\main.py", line 1973, in raw_value self.impl.raw_value = data ^^^^^^^^^^^^^^^^^^^ File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\_xlwindows.py", line 1209, in raw_value self.xl.Value = data ^^^^^^^^^^^^^ File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\_xlwindows.py", line 161, in __setattr__ return setattr(self._inner, key, value) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\win32com\client\__init__.py", line 597, in __setattr__ self._oleobj_.Invoke(*(args + (value,) + defArgs)) pywintypes.com_error: (-2147352567, 'Er is een uitzondering opgetreden.', (0, None, None, None, 0, -2147024882), None) Process finished with exit code 1 Kind regards Gelukt From python at mrabarnett.plus.com Sat Feb 3 22:50:32 2024 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 4 Feb 2024 03:50:32 +0000 Subject: Error pd.set_option('display.width', 10000) In-Reply-To: References: Message-ID: <59413b10-0b5c-4c82-9410-1fca1561677f@mrabarnett.plus.com> On 2024-02-03 23:02, gelukt gelukt via Python-list wrote: > Dear, > > While running a code, I get the error below: > What does this error mean? How can I fix this error? > > C:\Users\brech\Desktop\Crypto\venv\Scripts\python.exe "C:/Users/brech/Desktop/Crypto/Project/aaa Arbitrage.py" > Traceback (most recent call last): > File "C:\Users\brech\Desktop\Crypto\Project\aaa Arbitrage.py", line 458, in > methode() > File "C:\Users\brech\Desktop\Crypto\Project\aaa Arbitrage.py", line 49, in methode > wb.sheets[website]['A' + str(1+a)].value = inputString[startIndex:startIndex + 30000] > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\main.py", line 2411, in value > conversion.write(data, self, self._options) > File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\conversion\__init__.py", line 102, in write > pipeline(ctx) > File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\conversion\framework.py", line 79, in __call__ > stage(*args, **kwargs) > File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\conversion\standard.py", line 75, in __call__ > self._write_value(ctx.range, ctx.value, scalar) > File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\conversion\standard.py", line 63, in _write_value > rng.raw_value = value > ^^^^^^^^^^^^^ > File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\main.py", line 1973, in raw_value > self.impl.raw_value = data > ^^^^^^^^^^^^^^^^^^^ > File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\_xlwindows.py", line 1209, in raw_value > self.xl.Value = data > ^^^^^^^^^^^^^ > File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\xlwings\_xlwindows.py", line 161, in __setattr__ > return setattr(self._inner, key, value) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "C:\Users\brech\Desktop\Crypto\venv\Lib\site-packages\win32com\client\__init__.py", line 597, in __setattr__ > self._oleobj_.Invoke(*(args + (value,) + defArgs)) > pywintypes.com_error: (-2147352567, 'Er is een uitzondering opgetreden.', (0, None, None, None, 0, -2147024882), None) > > Process finished with exit code 1 > There's a question on StackOverflow that looks similar: https://stackoverflow.com/questions/72223654/pywintypes-com-error-2147352567-exception-occured-0-none-none-none-0 Something to do with the cell format. Check which cell it i, what value it's trying to put there, and whether the format of the cell and the value are compatible. From fabiofz at gmail.com Sun Feb 4 06:04:19 2024 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Sun, 4 Feb 2024 08:04:19 -0300 Subject: PyDev 12.0.0 Released Message-ID: PyDev 12.0.0 Release Highlights - *Debugger* - *sys.monitoring* is now used in Python 3.12 (and it's *much* faster than any previous version). - A new setting was added in the *Preferences > PyDev > Debug* to debug *just my code* (meaning that when stepping it will just step into files under PyDev source folders). - Improved the step into function (activated with *Ctrl+Alt* then *Click function* to step into). - Support for Python 3.6 and 3.7 was dropped (only Python 3.8 onwards is now supported). - *Ruff* - Ruff can now be used as a code formatter. - The latest ruff (*0.1.x*) is now supported (as it broke backward compatibility in its *0.1.0* version). - *Code Analysis* - Fixes in semantic analysis to better determine if strings in annotations should be checked for symbols or not. Note: *Only Python 3.8 onwards is now supported* * *Python 3.6* and *3.7* support is now *dropped* (please use *PyDev 11.0.3* if you still use it). About PyDev PyDev is an open-source Python IDE on top of Eclipse for Python (also available for Python on Visual Studio Code). It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. It is also available as a standalone through LiClipse with goodies such as multiple cursors, theming and support for many other languages, such as Django Templates, Jinja2, Html, JavaScript, etc. Links: PyDev: http://pydev.org PyDev Blog: http://pydev.blogspot.com PyDev on VSCode: http://pydev.org/vscode LiClipse: http://www.liclipse.com PyVmMonitor - Python Profiler: http://www.pyvmmonitor.com/ Cheers, Fabio Zadrozny From PythonList at DancesWithMice.info Sun Feb 4 17:01:00 2024 From: PythonList at DancesWithMice.info (dn) Date: Mon, 5 Feb 2024 11:01:00 +1300 Subject: Extract lines from file, add to new files In-Reply-To: <010401da56ff$ef5ab780$ce102680$@gmail.com> References: <2a5eef2d-3d66-8cea-64eb-602ea5aff946@appl-ecosys.com> <9028bd96-dbc8-fbc1-8584-a965ef7def5d@appl-ecosys.com> <5cea1ab2-1848-41bd-8e5b-323fe55ba8c9@tompassin.net> <478e3bbe-db95-9533-595b-7a19a5e2cf@appl-ecosys.com> <004c01da53fd$9273b9e0$b75b2da0$@gmail.com> <17769063-0f0d-49ef-9599-88157690cefd@tompassin.net> <007701da56be$b4ae7cc0$1e0b7640$@gmail.com> <1edcbbc8-f785-4b72-aed3-d6131794989b@tompassin.net> <1c43f539-ec95-4421-8809-e057b19b0bfa@DancesWithMice.info> <010401da56ff$ef5ab780$ce102680$@gmail.com> Message-ID: <7cb9ed62-80ea-4e44-b639-a176ae1032df@DancesWithMice.info> On 4/02/24 13:20, avi.e.gross at gmail.com wrote: > Dave, > > You and I have had some experience in teaching or tutoring others and I think it fair to say our motivation is closer to teaching someone how they can fish for themselves rather than just handing them a fully-cooked fish. Which may push the debate 'up' a level, in that there are two pertinent Python Discussion Lists (amongst the many): Tutor which is expressly for learners (and tutors), and this one which is to discuss Python. Accordingly, one might suggest that people 'here' are looking for a direct answer - the fish (having tried to fish for themselves), but learners (seeking to learn to fish) should be asking elsewhere. This would sort-out the type/level of questions that OPs may have. As well as indicating an appropriate approach to 'answers'. However, there's no rule which says one has to ask in one place or the other (nor am I suggesting such, although...). Then again, might the lack of forethought evident in some questions and the forum-used, indicate a type of person who wouldn't investigate to see which is the best place for his/her enquiries anyway? Tutor List: https://mail.python.org/mailman/listinfo/tutor Lists Overview: https://mail.python.org/mailman/listinfo > My favorite kinds of questions, thus, include someone who explains what they are trying to do and shows some code along with indications of what it produced (including error messages) and what it should produce. Then the question should not be a request to just FIX THIS or WRITE IT FOR ME but asking if someone can show what they did wrong with some idea where it went wrong. > > This may not be so common but it allows faster and easier help. +1 ... > I will end with a comment. I have heard of interview techniques for a job where they deliberately supply a problem in which the goal is not so much to be easy to solve in front of them in real time but to watch how the person looking for a job responds to the uncertainties and asks follow-up questions or verbalizes things like, if it is like this, I might use this technique but if you also need that then ... > > So, I shudder to think what happens if someone being interviewed turns around and asks us and further confuses things with changes to make it harder to recognize they are asking for outside help. The answer expected may well be to NOT use say the older versions of PASCAL to do something but switch to something better suited (and for that matter available.) I would not want to program the DES encryption/decryption method in Pascal again! And these days, it seems much better to just find a module or package that meets such needs. As you know, I investigate Cognitive Psychology. Accordingly, such is interesting to me. In many cases, I'll interview for motivation, not just particular skills - but perhaps that's another can-of-worms. How about "when is 1 + 1 not 2?". This is a bit of a mind-bender, but leads towards debugging ability* - what if your code was showing some unbelievable result like this? The answer is (or rather, "could be") 10, ie we're looking at binary cf decimal, coding. Do I hear some groans? Yes, fair-enough! There was absolutely no "context" to the question - whereas when coding/debugging we would expect to have some 'framing' of our thinking. At the same time, 'fixed mode thinking' will prevent many people from even considering such possibilities - whether as-asked or in a dev.env... * In the ?good old days, career progression was thought to be: (mainframe) Computer Operator, to Computer Programmer, to Systems Analyst, etc. However, as I pointed-out (to an IBM 'big-wig' who took an instant dislike as a result) the valued skills of an Analyst are that (s)he can see 'patterns' - whereas the skills of debugging involve realising why an expected pattern doesn't work (as-expected). Another analysis might be to decide if the job requires a 'lateral thinker' or a more single-minded approach. (us lateral thinkers tend to ask (loads of) questions, and thus can be quite 'annoying' individuals). Then there is the main-stay of many job-adverts: "attention to detail" and the question of whether someone who can't [be bothered to] write an half-decent email-message (with spell-checker likely built-in) is going to be productive when communicating with a pedantic compiler? Again, some people are suited to this business (or specific jobs within), and some (?many) are not - but many are (perhaps reluctantly) programming to get some other job done... -- Regards, =dn From thomas at python.org Wed Feb 7 10:15:12 2024 From: thomas at python.org (Thomas Wouters) Date: Wed, 7 Feb 2024 16:15:12 +0100 Subject: [RELEASE] Python 3.12.2 and 3.11.8 now available. Message-ID: *Python 3.12.2 and 3.11.8 are here! *In addition to all the usual bugfixes, these releases contain a small security fix: hidden .pth files are no longer automatically read and executed as part of Python startup. (New releases of 3.8, 3.9 and 3.10 containing the same fix are expected next week.) Python 3.12.2 https://www.python.org/downloads/release/python-3122/ Python 3.12?s second bugfix release. In addition to the mentioned security fix and the usual slew of bug fixes, build changes and documentation updates (more than 350 commits), this is also the first release to include a Software Bill-of-Materials for the source packages (Python-3.12.2.tgz and Python-3.12.2.tar.xz). Full changelog . Python 3.11.8 https://www.python.org/downloads/release/python-3118/ More than 300 commits of bug fixes, build changes and documentation updates. Full changelog . We hope you 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 contributions to the Python Software Foundation or CPython itself . Thomas Wouters @thomas on behalf of your release team, Ned Deily Steve Dower Pablo Galindo Salgado ?ukasz Langa From mexine at pacbell.net Tue Feb 6 22:46:05 2024 From: mexine at pacbell.net (Jim) Date: Tue, 6 Feb 2024 21:46:05 -0600 Subject: Python misbehavior References: <3EB88723-DDCB-40DB-BF03-892AB5E5BD10.ref@pacbell.net> Message-ID: <3EB88723-DDCB-40DB-BF03-892AB5E5BD10@pacbell.net> Friends, Please forgive me if this is not the proper forum for dealing with an issue of mine, but I am at a loss in finding a fix for a python problem in the program ClipGrab. The program allows one to download videos or audios from YouTube and other media sites. My limited understanding of the process suggests that python facilitates the transfer of data from YouTube to ClipGrab. As of recently, I am unable to use the ClipGrab program and the issue at fault has something to do with python. In an "about" screen within ClipGrab my (now) incapable python script reads: youtube-dlp: (C:\Program Files (x86)\ClipGrab\python\python.exe: can't find '_main_' module in " ) Python: C:/Program Files (x86)/ClipGrab/python/python.exe (Python 3.8.9) Since this problem began I downloaded ClipGrab on to another desktop computer and it runs perfectly without a problem. The script on the "about" page does not indicate anything about "can't find -main- module" etc. Is there any advice you can offer to overcome this and recover my downloading connections to YouTube? Or, if this is the wrong group to handle such issues, could you please pass my message on to a better choice? Gratefully, Jim Haas Sent from my iPhone From Richard at Damon-Family.org Thu Feb 8 07:52:13 2024 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 8 Feb 2024 07:52:13 -0500 Subject: Python misbehavior In-Reply-To: <3EB88723-DDCB-40DB-BF03-892AB5E5BD10@pacbell.net> References: <3EB88723-DDCB-40DB-BF03-892AB5E5BD10.ref@pacbell.net> <3EB88723-DDCB-40DB-BF03-892AB5E5BD10@pacbell.net> Message-ID: <339c49bf-5585-4524-9330-2b5fd98df662@Damon-Family.org> On 2/6/24 10:46 PM, Jim via Python-list wrote: > Friends, > Please forgive me if this is not the proper forum for dealing with an issue of mine, but I am at a loss in finding a fix for a python problem in the program ClipGrab. The program allows one to download videos or audios from YouTube and other media sites. My limited understanding of the process suggests that python facilitates the transfer of data from YouTube to ClipGrab. As of recently, I am unable to use the ClipGrab program and the issue at fault has something to do with python. In an "about" screen within ClipGrab my (now) incapable python script reads: > > youtube-dlp: (C:\Program Files (x86)\ClipGrab\python\python.exe: can't find '_main_' module in " ) Python: C:/Program Files (x86)/ClipGrab/python/python.exe (Python 3.8.9) > > Since this problem began I downloaded ClipGrab on to another desktop computer and it runs perfectly without a problem. The script on the "about" page does not indicate anything about "can't find -main- module" etc. Is there any advice you can offer to overcome this and recover my downloading connections to YouTube? Or, if this is the wrong group to handle such issues, could you please pass my message on to a better choice? > > Gratefully, > Jim Haas > > Sent from my iPhone Python itself doesn't have any code to do this, but does have some support libraries that help. It looks like your "ClipGrab" program is using the python module "youtube-dlp" to get the data (that module probabaly has the details of how to do the operation), but somehow ClipGrab hasn't packaged the module into itself properly. You probably should seek help with the support for the ClipGrab program from the people that make it. If you look up the documentation for youtube-dlp, you may find that you can use that module directly, and not need the ClipGrab wrapper at all (though it may provide some benefits if you can get it working again). -- Richard Damon From tony.flury at btinternet.com Thu Feb 8 07:21:20 2024 From: tony.flury at btinternet.com (Tony Flury) Date: Thu, 8 Feb 2024 12:21:20 +0000 Subject: Is there a way to implement the ** operator on a custom object Message-ID: I know that mappings by default support the ** operator, to unpack the mapping into key word arguments. Has it been considered implementing a dunder method for the ** operator so you could unpack an object into a key word argument, and the developer could choose which keywords would be generated (or could even generate 'virtual' attributes). -- Anthony Flury email : anthony.flury at btinternet.com From cs at cskk.id.au Fri Feb 9 00:50:21 2024 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 9 Feb 2024 16:50:21 +1100 Subject: Is there a way to implement the ** operator on a custom object In-Reply-To: References: Message-ID: On 08Feb2024 12:21, tony.flury at btinternet.com wrote: >I know that mappings by default support the ** operator, to unpack the >mapping into key word arguments. > >Has it been considered implementing a dunder method for the ** >operator so you could unpack an object into a key word argument, and >the developer could choose which keywords would be generated (or could >even generate 'virtual' attributes). Can you show us why you think that would look like in code? Note that Python already has `a ** b` to raise `a` to the power of `b`, and it has a bunder method `__pow__` which you can define. From rosuav at gmail.com Fri Feb 9 01:06:42 2024 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Feb 2024 17:06:42 +1100 Subject: Is there a way to implement the ** operator on a custom object In-Reply-To: References: Message-ID: On Fri, 9 Feb 2024 at 17:03, Cameron Simpson via Python-list wrote: > > On 08Feb2024 12:21, tony.flury at btinternet.com wrote: > >I know that mappings by default support the ** operator, to unpack the > >mapping into key word arguments. > > > >Has it been considered implementing a dunder method for the ** > >operator so you could unpack an object into a key word argument, and > >the developer could choose which keywords would be generated (or could > >even generate 'virtual' attributes). > > Can you show us why you think that would look like in code? > > Note that Python already has `a ** b` to raise `a` to the power of `b`, > and it has a bunder method `__pow__` which you can define. I presume this is more like: obj = SomeObject() func(**obj) ie making the object behave in a dict-like way. I can't remember how this is implemented, but you can create the necessary methods to have your object produce whatever it likes. ChrisA From alan at csail.mit.edu Fri Feb 9 01:26:16 2024 From: alan at csail.mit.edu (Alan Bawden) Date: Fri, 09 Feb 2024 01:26:16 -0500 Subject: Is there a way to implement the ** operator on a custom object References: Message-ID: <86plx6qhkn.fsf@williamsburg.bawden.org> Chris Angelico writes: > On 08Feb2024 12:21, tony.flury at btinternet.com wrote: > >I know that mappings by default support the ** operator, to unpack the > >mapping into key word arguments. > > > >Has it been considered implementing a dunder method for the ** > >operator so you could unpack an object into a key word argument, and > >the developer could choose which keywords would be generated (or could > >even generate 'virtual' attributes). I presume this is more like: obj = SomeObject() func(**obj) ie making the object behave in a dict-like way. I can't remember how this is implemented, but you can create the necessary methods to have your object produce whatever it likes. All you need to do is subclass collections.abc.Mapping, and implement __len__, __iter__, and __getitem__. Pretty easy. - Alan From olegsivokon at gmail.com Fri Feb 9 11:09:54 2024 From: olegsivokon at gmail.com (Left Right) Date: Fri, 9 Feb 2024 17:09:54 +0100 Subject: Is there a way to implement the ** operator on a custom object In-Reply-To: References: Message-ID: In order for the "splat" operator to work, the type of the object must populate slot `tp_as_mapping` with a struct of this type: https://docs.python.org/3/c-api/typeobj.html#c.PyMappingMethods and have some non-null implementations of the methods this struct is supposed to contain. I can do this in C, but I cannot think of a way to do this in Python proper. Defining all the methods mentioned in PyMappingMethods doesn't seem to do it. You could try to research this further, and if, indeed defining all the methods of PyMappingMethods on the Python side doesn't produce an object that behaves like a proper mapping, you could probably file a bug report for that. From roel at roelschroeven.net Fri Feb 9 12:03:04 2024 From: roel at roelschroeven.net (Roel Schroeven) Date: Fri, 9 Feb 2024 18:03:04 +0100 Subject: Is there a way to implement the ** operator on a custom object In-Reply-To: References: Message-ID: Left Right via Python-list schreef op 9/02/2024 om 17:09: > In order for the "splat" operator to work, the type of the object must > populate slot `tp_as_mapping` with a struct of this type: > https://docs.python.org/3/c-api/typeobj.html#c.PyMappingMethods and > have some non-null implementations of the methods this struct is > supposed to contain. > > I can do this in C, but I cannot think of a way to do this in Python > proper. Looks like it can simply be done in Python, no tp_as_mapping needed. I tried it like Alan Bawden suggested (sibling post of yours): import random # just as an example import time?? # just as an example from collections.abc import Mapping class VirtualKwargs(Mapping): ??? def __init__(self): ??????? self.fncs = { ??????????? # Simple examples of functions with varying return values to be ??????????? # called for each lookup, instead of fixed values. ??????????? 'time': time.time, ??????????? 'random': random.random, ??????? } ??? def __len__(self): ??????? return len(self.fncs) ??? def __iter__(self): ??????? return iter(self.fncs) ??? def __getitem__(self, key): ??????? return self.fncs[key]() def func(**kwargs): ??? for k, v in kwargs.items(): ??????? print(f'{k}: {v}') obj = VirtualKwargs() func(**obj) Output (obviously changes every run): time: 1707497521.175763 random: 0.6765831287385126 -- "Man had always assumed that he was more intelligent than dolphins because he had achieved so much ? the wheel, New York, wars and so on ? whilst all the dolphins had ever done was muck about in the water having a good time. But conversely, the dolphins had always believed that they were far more intelligent than man ? for precisely the same reasons." -- Douglas Adams From olegsivokon at gmail.com Fri Feb 9 12:56:17 2024 From: olegsivokon at gmail.com (Left Right) Date: Fri, 9 Feb 2024 18:56:17 +0100 Subject: Is there a way to implement the ** operator on a custom object In-Reply-To: References: Message-ID: > Looks like it can simply be done in Python, no tp_as_mapping needed. It's not that it isn't needed. You've just shown a way to add it using Python code. But, more to the point: extending collections.abc.Mapping may or may not be possible in OP's case. Also, if you are doing this through inheritance, this seems really convoluted: why not just inherit from dict? -- less methods to implement, less stuff to import etc. From cs at cskk.id.au Fri Feb 9 16:13:23 2024 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 10 Feb 2024 08:13:23 +1100 Subject: Is there a way to implement the ** operator on a custom object In-Reply-To: References: Message-ID: On 09Feb2024 18:56, Left Right wrote: >But, more to the point: extending collections.abc.Mapping may or may >not be possible in OP's case. We don't yet know if that's what the OP had in mind yet, anyway. >Also, if you are doing this through inheritance, this seems really >convoluted: why not just inherit from dict? -- less methods to >implement, less stuff to import etc. There's a rule of thumb that we _tend_ not to subclass the builtins; it certainly has its pitfalls to do with object creation/initialisation. That said, I have some classes which subclass dict, int, str and namedtuple. Cheers, Cameron Simpson From aurzenligl at gmail.com Sun Feb 11 19:59:35 2024 From: aurzenligl at gmail.com (Krzysztof Laskowski) Date: Mon, 12 Feb 2024 01:59:35 +0100 Subject: pytest-logger 1.0.0 released In-Reply-To: <633c1150-3ba7-483f-b7ca-c3289e9b248f@gmail.com> References: <633c1150-3ba7-483f-b7ca-c3289e9b248f@gmail.com> Message-ID: <06c0c0cb-bb75-4150-ae39-93e73e746030@gmail.com> Hi All, pytest-logger is pytest plugin for putting stdlib logging logs to files or terminal: pypi: https://pypi.python.org/pypi/pytest-logger/1.0.0 repo: https://github.com/aurzenligl/pytest-logger docs: http://pytest-logger.readthedocs.io Best Regards, Krzysztof Laskowski From thomas at python.org Thu Feb 15 16:13:22 2024 From: thomas at python.org (Thomas Wouters) Date: Thu, 15 Feb 2024 22:13:22 +0100 Subject: [RELEASE] Python 3.13.0a4 is now available Message-ID: It?s time for Python 3.13.0 alpha 4 (now with SPDX SBOM OMG!): https://www.python.org/downloads/release/python-3130a4/ *This is an early developer preview of Python 3.13* Major new features of the 3.13 series, compared to 3.12 Python 3.13 is still in development. This release, 3.13.0a4, is the fourth of six planned alpha releases. Alpha releases are intended to make it easier to test the current state of new features and bug fixes and to test the release process. During the alpha phase, features may be added up until the start of the beta phase (2024-05-07) and, if necessary, may be modified or deleted up until the release candidate phase (2024-07-30). Please keep in mind that this is a preview release and its use is *not* recommended for production environments. Many new features for Python 3.13 are still being planned and written. Work continues apace on both the work to remove the Global Interpeter Lock , and to improve Python performance. The most notable changes so far: - In the interactive interpreter, exception tracebacks are now colorized by default . - A preliminary, *experimental* JIT was added , providing the ground work for significant performance improvements. - Docstrings now have their leading indentation stripped , reducing memory use and the size of .pyc files. (Most tools handling docstrings already strip leading indentation.) - 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. - New deprecations , most of which are scheduled for removal from Python 3.15 or 3.16. - C API removals and deprecations . (Some removals present in alpha 1 have been reverted in alpha 2, as the removals were deemed too disruptive at this time.) (Hey, *fellow core developer,* if a feature you find important is missing from this list, let Thomas know .) The next pre-release of Python 3.13 will be 3.13.0a5, currently scheduled for 2023-03-12. 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 dusky Amsterdam, Your release team, Thomas Wouters Ned Deily Steve Dower ?ukasz Langa -- Thomas Wouters From edgrsprj at ix.netcom.com Thu Feb 15 16:15:58 2024 From: edgrsprj at ix.netcom.com (E.D.G.) Date: Thu, 15 Feb 2024 15:15:58 -0600 Subject: test-ignore Message-ID: Test - ignore February 15, 2024 Test post to see if my Newsgroup post program is working. From ScienceResearch01 at earthlink.net Thu Feb 15 17:30:27 2024 From: ScienceResearch01 at earthlink.net (Science Researcher) Date: Thu, 15 Feb 2024 16:30:27 -0600 Subject: test ignore Message-ID: This is a test message - just ignore it From ScienceResearch01 at earthlink.net Thu Feb 15 17:33:07 2024 From: ScienceResearch01 at earthlink.net (Science Researcher) Date: Thu, 15 Feb 2024 16:33:07 -0600 Subject: test ignore In-Reply-To: References: Message-ID: "Science Researcher" wrote in message news:FH2dnWrca5oeDVP4nZ2dnZfqnPWdnZ2d at earthlink.com... This is a test message - just ignore it That post worked as intended. From guinness.tony at gmail.com Thu Feb 15 19:02:50 2024 From: guinness.tony at gmail.com (Tony Oliver) Date: Thu, 15 Feb 2024 16:02:50 -0800 (PST) Subject: test-ignore In-Reply-To: References: Message-ID: <5c1dc9ff-9f09-4320-855a-3290b720a59bn@googlegroups.com> On Thursday 15 February 2024 at 21:16:22 UTC, E.D.G. wrote: > Test - ignore February 15, 2024 > > Test post to see if my Newsgroup post program is working. Aim your test messages at alt.test, please. From skip.montanaro at gmail.com Thu Feb 15 19:29:42 2024 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 15 Feb 2024 18:29:42 -0600 Subject: test-ignore In-Reply-To: <5c1dc9ff-9f09-4320-855a-3290b720a59bn@googlegroups.com> References: <5c1dc9ff-9f09-4320-855a-3290b720a59bn@googlegroups.com> Message-ID: > > > Test post to see if my Newsgroup post program is working. > > Aim your test messages at alt.test, please. > I agree that basic Usenet connectivity messages should go to alt.test. It's not clear from the original post, but if the poster's aim was to see if posts to comp.lang.python traverse the gateway and show up on this list, then alt.test won't help. Skip > From PythonList at DancesWithMice.info Thu Feb 15 19:37:32 2024 From: PythonList at DancesWithMice.info (dn) Date: Fri, 16 Feb 2024 13:37:32 +1300 Subject: test-ignore In-Reply-To: References: <5c1dc9ff-9f09-4320-855a-3290b720a59bn@googlegroups.com> Message-ID: On 16/02/24 13:29, Skip Montanaro via Python-list wrote: >> >>> Test post to see if my Newsgroup post program is working. >> >> Aim your test messages at alt.test, please. >> > > I agree that basic Usenet connectivity messages should go to alt.test. It's > not clear from the original post, but if the poster's aim was to see if > posts to comp.lang.python traverse the gateway and show up on this list, > then alt.test won't help. Coincidentally (I hope), today have received a couple of poorly-executed spam/phishing messages purporting to be from this list or "Tutor". -- Regards, =dn From python at mrabarnett.plus.com Thu Feb 15 19:49:25 2024 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Feb 2024 00:49:25 +0000 Subject: test-ignore In-Reply-To: References: <5c1dc9ff-9f09-4320-855a-3290b720a59bn@googlegroups.com> Message-ID: <73a7aa17-bed3-4bd9-8cf1-506e3d860775@mrabarnett.plus.com> On 2024-02-16 00:29, Skip Montanaro via Python-list wrote: >> >> > Test post to see if my Newsgroup post program is working. >> >> Aim your test messages at alt.test, please. >> > > I agree that basic Usenet connectivity messages should go to alt.test. It's > not clear from the original post, but if the poster's aim was to see if > posts to comp.lang.python traverse the gateway and show up on this list, > then alt.test won't help. > True, but did the poster really need to send another one to say "yes, that worked"? From skip.montanaro at gmail.com Thu Feb 15 20:40:07 2024 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 15 Feb 2024 19:40:07 -0600 Subject: test-ignore In-Reply-To: <73a7aa17-bed3-4bd9-8cf1-506e3d860775@mrabarnett.plus.com> References: <5c1dc9ff-9f09-4320-855a-3290b720a59bn@googlegroups.com> <73a7aa17-bed3-4bd9-8cf1-506e3d860775@mrabarnett.plus.com> Message-ID: > > True, but did the poster really need to send another one to say "yes, > that worked"? > Maybe to test the bidirectionality of the gateway? ? If the messages stop I think we can let it die. It's not like this sort of activity is a regular occurrence. (A bigger problem for me was always Usenet posters who used fake email addresses.) Skip From RealGrizzlyAdams at vivaldi.net Fri Feb 16 05:43:12 2024 From: RealGrizzlyAdams at vivaldi.net (Grizzy Adams) Date: Fri, 16 Feb 2024 10:43:12 -0000 Subject: test-ignore In-Reply-To: <5c1dc9ff-9f09-4320-855a-3290b720a59bn@googlegroups.com> References: , <5c1dc9ff-9f09-4320-855a-3290b720a59bn@googlegroups.com> Message-ID: <65CF3C40.24373.17DC46@RealGrizzlyAdams.vivaldi.net> Thursday, February 15, 2024 at 16:02, Tony Oliver via Python-list wrote: Re: test-ignore (at least in part) >On Thursday 15 February 2024 at 21:16:22 UTC, E.D.G. wrote: >> Test - ignore February 15, 2024 >> >> Test post to see if my Newsgroup post program is working. > >Aim your test messages at alt.test, please. or alt.test.ignore From urbangabo at gmail.com Fri Feb 16 15:07:24 2024 From: urbangabo at gmail.com (Gabor Urban) Date: Fri, 16 Feb 2024 21:07:24 +0100 Subject: A question about import Message-ID: Hi guys, I need something about modules to be clarified. Suppose I have written a module eg: ModuleA which imports an other module, let us say the datetime. If I import ModuleA in a script, will be datetime imported automatically? Thanks in advance, -- Urb?n G?bor Linux is like a wigwam: no Gates, no Windows and an Apache inside. From python at mrabarnett.plus.com Fri Feb 16 15:32:05 2024 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Feb 2024 20:32:05 +0000 Subject: A question about import In-Reply-To: References: Message-ID: On 2024-02-16 20:07, Gabor Urban via Python-list wrote: > Hi guys, > > I need something about modules to be clarified. > > Suppose I have written a module eg: ModuleA which imports an other > module, let us say the datetime. > > If I import ModuleA in a script, will be datetime imported automatically? > Yes. When a module is imported it can import other modules. From cs at cskk.id.au Fri Feb 16 16:13:50 2024 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 17 Feb 2024 08:13:50 +1100 Subject: A question about import In-Reply-To: References: Message-ID: On 16Feb2024 20:32, MRAB wrote: >On 2024-02-16 20:07, Gabor Urban via Python-list wrote: >>I need something about modules to be clarified. >> >>Suppose I have written a module eg: ModuleA which imports an other >>module, let us say the datetime. >> >>If I import ModuleA in a script, will be datetime imported automatically? >> >Yes. When a module is imported it can import other modules. But note that `datetime` does not magicly get put in the script's namespace. Module A: import datetime Script: import A In the code in module A the name datetime is known and can be used. In the code in the script the name A is known and can be used. Importing A does not magicly set the name datetime in the script's namespace - imagine the the pollution! You _can_ access it as A.datetime because it is in the A module's namespace. But really if you just wanted datetime for direct use in the script you would import it there too: import datetime import A Note that the datetime module is only actually loaded once. The import binds the name into your local namespace like any other variable. Cheers, Cameron Simpson From cl at isbd.net Fri Feb 16 17:12:33 2024 From: cl at isbd.net (Chris Green) Date: Fri, 16 Feb 2024 22:12:33 +0000 Subject: Can one output something other than 'nan' for not a number values? Message-ID: I'm looking for a simple way to make NaN values output as something like '-' or even just a space instead of the string 'nan'. This would then make it much easier to handle outputting values from sensors when not all sensors are present. So, for example, my battery monitoring program outputs:- Battery Voltages and Currents Leisure Battery - 12.42 volts -0.52 Amps Starter Battery - 12.34 volts -0.01 Amps If the starter battery sensor has failed, or is disconnected, I see:- Battery Voltages and Currents Leisure Battery - 12.42 volts -0.52 Amps Starter Battery - nan volts nan Amps What I would like is for those 'nan' strings to be just a '-' or something similar. Obviously I can write conditional code to check for float('nan') values but is there a neater way with any sort of formatting string or other sort of cleverness? -- Chris Green ? From cs at cskk.id.au Sat Feb 17 00:05:52 2024 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 17 Feb 2024 16:05:52 +1100 Subject: Can one output something other than 'nan' for not a number values? In-Reply-To: References: Message-ID: On 16Feb2024 22:12, Chris Green wrote: >I'm looking for a simple way to make NaN values output as something >like '-' or even just a space instead of the string 'nan'. This would >then make it much easier to handle outputting values from sensors when >not all sensors are present. > >So, for example, my battery monitoring program outputs:- > > Battery Voltages and Currents > Leisure Battery - 12.42 volts -0.52 Amps > Starter Battery - 12.34 volts -0.01 Amps > >If the starter battery sensor has failed, or is disconnected, I see:- > > Battery Voltages and Currents > Leisure Battery - 12.42 volts -0.52 Amps > Starter Battery - nan volts nan Amps > > >What I would like is for those 'nan' strings to be just a '-' or >something similar. > >Obviously I can write conditional code to check for float('nan') >values but is there a neater way with any sort of formatting string or >other sort of cleverness? The simplest thing is probably just a function writing it how you want it: def float_s(f): if isnan(f): return "-" return str(f) and then use eg: print(f'value is {float_s(value)}') or whatever fits your code. Cheers, Cameron Simpson From jgossage at gmail.com Sat Feb 17 17:35:21 2024 From: jgossage at gmail.com (Jonathan Gossage) Date: Sat, 17 Feb 2024 17:35:21 -0500 Subject: Using __new__ Message-ID: I am attempting to use the __new__ method in the following code: class SingletonExample(object): _instance = None def __new__(cls, **kwargs): if cls._instance is None: cls._instance = super().__new__(cls, **kwargs) return cls._instance def __init__(self, **kwargs) -> None: our_attributes = ('h', 'x') if kwargs is not None: for k, v in kwargs.items(): if k in our_attributes: setattr(self, k, v) a = SingletonExample(h=1) and I get the following result: (PRV) jonathan at jfgdev:/PR$ python -m Library.Testing.test2 Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/mnt/ProgrammingRenaissance/Library/Testing/test2.py", line 16, in a = SingletonExample(h=1) ^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ProgrammingRenaissance/Library/Testing/test2.py", line 6, in __new__ cls._instance = super().__new__(cls, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: object.__new__() takes exactly one argument (the type to instantiate) I am quite puzzled as it looks as if this code will not work if the super-class is 'object'. Any suggestions on how to proceed? -- Jonathan Gossage From python at mrabarnett.plus.com Sat Feb 17 18:08:57 2024 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 17 Feb 2024 23:08:57 +0000 Subject: Using __new__ In-Reply-To: References: Message-ID: <692bffe8-0b64-48a8-8c7b-fb343c830b35@mrabarnett.plus.com> On 2024-02-17 22:35, Jonathan Gossage via Python-list wrote: > I am attempting to use the __new__ method in the following code: > class SingletonExample(object): > > _instance = None > > def __new__(cls, **kwargs): > if cls._instance is None: > cls._instance = super().__new__(cls, **kwargs) > return cls._instance > > def __init__(self, **kwargs) -> None: > our_attributes = ('h', 'x') > if kwargs is not None: > for k, v in kwargs.items(): > if k in our_attributes: > setattr(self, k, v) > > a = SingletonExample(h=1) > > and I get the following result: > > (PRV) jonathan at jfgdev:/PR$ python -m Library.Testing.test2 > Traceback (most recent call last): > File "", line 198, in _run_module_as_main > File "", line 88, in _run_code > File "/mnt/ProgrammingRenaissance/Library/Testing/test2.py", line 16, in > > a = SingletonExample(h=1) > ^^^^^^^^^^^^^^^^^^^^^ > File "/mnt/ProgrammingRenaissance/Library/Testing/test2.py", line 6, in > __new__ > cls._instance = super().__new__(cls, **kwargs) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > TypeError: object.__new__() takes exactly one argument (the type to > instantiate) > > I am quite puzzled as it looks as if this code will not work if the > super-class is 'object'. Any suggestions on how to proceed? > Don't pass kwargs to object.__new__ because it doesn't expect it. Incidentally, kwargs will never be None, and there's no point in giving a return type for __init__ because it can only ever return None. From PythonList at DancesWithMice.info Sat Feb 17 18:31:39 2024 From: PythonList at DancesWithMice.info (dn) Date: Sun, 18 Feb 2024 12:31:39 +1300 Subject: Using __new__ In-Reply-To: References: Message-ID: <9bbab6fa-efb4-462b-8818-ccdc04ebac75@DancesWithMice.info> On 18/02/24 11:35, Jonathan Gossage via Python-list wrote: > I am attempting to use the __new__ method in the following code: > class SingletonExample(object): > > _instance = None > > def __new__(cls, **kwargs): > if cls._instance is None: > cls._instance = super().__new__(cls, **kwargs) > return cls._instance > > def __init__(self, **kwargs) -> None: > our_attributes = ('h', 'x') > if kwargs is not None: > for k, v in kwargs.items(): > if k in our_attributes: > setattr(self, k, v) > > a = SingletonExample(h=1) > > and I get the following result: > > (PRV) jonathan at jfgdev:/PR$ python -m Library.Testing.test2 > Traceback (most recent call last): > File "", line 198, in _run_module_as_main > File "", line 88, in _run_code > File "/mnt/ProgrammingRenaissance/Library/Testing/test2.py", line 16, in > > a = SingletonExample(h=1) > ^^^^^^^^^^^^^^^^^^^^^ > File "/mnt/ProgrammingRenaissance/Library/Testing/test2.py", line 6, in > __new__ > cls._instance = super().__new__(cls, **kwargs) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > TypeError: object.__new__() takes exactly one argument (the type to > instantiate) > > I am quite puzzled as it looks as if this code will not work if the > super-class is 'object'. Any suggestions on how to proceed? Don't be puzzled. Read the error-message. Change the super-call to: cls._instance = super().__new__(cls) and happiness will follow... That said, mystifications - not sure if this meets the/your definition* of "singleton", because: - it can be aliased, eg a = SingletonExample(h=1) b = SingletonExample(x=2) - when it is, the effect is an accumulation of attributes and values a = SingletonExample(h=1) b = SingletonExample(h=2) print( a.__dict__, b.__dict__, ) - it can be re-created with a different value, eg a = SingletonExample(h=1) a = SingletonExample(h=2) - and can be 'regenerated': a = SingletonExample(h=1) a = SingletonExample(x=2) - all failures are silent * noting "Nowadays, the Singleton pattern has become so popular that people may call something a singleton even if it solves just one of the listed problems." (https://refactoring.guru/design-patterns/singleton) YMMV! -- Regards, =dn From PythonList at DancesWithMice.info Sat Feb 17 19:05:54 2024 From: PythonList at DancesWithMice.info (dn) Date: Sun, 18 Feb 2024 13:05:54 +1300 Subject: Using __new__ In-Reply-To: References: <9bbab6fa-efb4-462b-8818-ccdc04ebac75@DancesWithMice.info> Message-ID: <3e576001-175a-4bc9-96d4-65dc0fa17487@DancesWithMice.info> On 18/02/24 12:48, Jonathan Gossage wrote: > The problem that I am facing is that when the superclass is not > 'object', the?__init__ method may well need arguments. I do not know how > to determine if the superclass is 'object'. For what it is worth, any > attempt?to use this with different arguments?should return the initial > singleton and ignore further attempts to create a second instance. 1 "object" don't understand. Perhaps give us a broader description of the problem? Remember also ABCs (Abstract Base Classes). 2 arguments yes, must accommodate arguments in __new__() if some/same are needed in __init__() However, when using the default "object", the super() does not need, use, or want, any arguments to be passed. 3 singleton don't think that is happening! PS please reply to the list - there may be others who can learn from, or contribute to, this conversation! -- Regards, =dn From PythonList at DancesWithMice.info Sat Feb 17 21:24:09 2024 From: PythonList at DancesWithMice.info (dn) Date: Sun, 18 Feb 2024 15:24:09 +1300 Subject: Using __new__ In-Reply-To: References: <9bbab6fa-efb4-462b-8818-ccdc04ebac75@DancesWithMice.info> <3e576001-175a-4bc9-96d4-65dc0fa17487@DancesWithMice.info> Message-ID: On 18/02/24 13:21, Jonathan Gossage wrote: > The problem is that if you are dealing with a library class, you may > have?times when the superclass is 'object' while at other times, with a > different inheritance hierarchy, the superclass may need arguments. My > thought is that the object class __new__ method should not choke on > arguments, just ignore them. All true. So, what you're looking for is one mechanism to rule them all? Not going to happen: for exactly the reasons you've stated. If you really want to get right 'down into the weeds' with a __new__() constructor, then you're well into customisation-territory. I think it would be 'going nuts' but... If it 'absolutely, positively, ...' then perhaps introspect the super-class and modify the call based-upon whether it is 'something' or "object"? (in similar fashion to the singleton's if-statement attempting to make sure it is unique) - perhaps someone knows a better/proper way to do this? Suggested research: custom classes, ABCs, and meta-classes... See also recent improvements to Python which have made it easier for sub-classes (and Descriptors - __set_name__() ) to identify who/how/where to 'phone home', in case (also) applicable... > When I talk about 'object', I am talking about the ultimate base class > of any inheritance hierarchy.? have seen the class named 'object' called > that. Correct. The earlier comment was that class S( object ): is 'tradition', and synonymous with: class S: (not disputing the concept of "object" as the base class) Not correct. Please see last paragraph from previous message: > On Sat, Feb 17, 2024 at 7:06?PM dn via Python-list > > wrote: ... > PS please reply to the list - there may be others who can learn > from, or > contribute to, this conversation! ... -- Regards, =dn From mats at wichmann.us Sun Feb 18 10:52:12 2024 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 18 Feb 2024 08:52:12 -0700 Subject: Using __new__ In-Reply-To: References: <9bbab6fa-efb4-462b-8818-ccdc04ebac75@DancesWithMice.info> <3e576001-175a-4bc9-96d4-65dc0fa17487@DancesWithMice.info> Message-ID: <7d93ac88-2a7a-4d68-8903-e7c54f33f6fe@wichmann.us> On 2/17/24 19:24, dn via Python-list wrote: > On 18/02/24 13:21, Jonathan Gossage wrote: > - perhaps someone knows a better/proper way to do this? > > Suggested research: custom classes, ABCs, and meta-classes... Cure the old "what do you want to accomplish" question. If it's to channel access to a resource to a single place, many folks seem to advocate just putting that code in a module, and not trying to use a class for that - Python already treats modules as a form of singleton (if you squint a bit). It's not Java, after all, everything doesn't _have_ to be a class. I'd also second the idea of looking at metaclasses for an implementation. Most simpler class-based singleton approaches turn out not to be thread-safe... you can get closer to solving that with a metaclass with a lock taken in the dunder-call method. From grant.b.edwards at gmail.com Sat Feb 17 15:47:09 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 17 Feb 2024 15:47:09 -0500 (EST) Subject: Can one output something other than 'nan' for not a number values? References: Message-ID: <4TcgpP4sdFznVFX@mail.python.org> On 2024-02-16, Chris Green via Python-list wrote: > I'm looking for a simple way to make NaN values output as something > like '-' or even just a space instead of the string 'nan'. It would probably help if you told us how you're "outputting" them now (the Python feaatures/functions used, not the actual output format). Are you using f-strings, the % operator, str.format(), or ?? I would be tempted to try monkey-patching the float class to override the __format__ method. I have no idea what side effects that might have, or if it's even used by the various formatting mechanisms, so you might end up scraping bits off the walls... -- Grant From grant.b.edwards at gmail.com Sat Feb 17 15:53:26 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 17 Feb 2024 15:53:26 -0500 (EST) Subject: Can one output something other than 'nan' for not a number values? References: Message-ID: <4Tcgxf47LSznVDn@mail.python.org> On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. >>[...] >> >> Battery Voltages and Currents >> Leisure Battery - 12.42 volts -0.52 Amps >> Starter Battery - nan volts nan Amps >> >>What I would like is for those 'nan' strings to be just a '-' or >>something similar. > The simplest thing is probably just a function writing it how you want > it: > > def float_s(f): > if isnan(f): > return "-" > return str(f) > > and then use eg: > > print(f'value is {float_s(value)}') > > or whatever fits your code. Except he's obviously using some sort of formatting to control the number of columns and decimal places, so 'str(f)' is not going to cut it. Is the basic floating point number formatting functionality seen when using f-strings or '%' operator part of the float type or is it part of the f-string and % operator? -- Grant From grant.b.edwards at gmail.com Sat Feb 17 17:55:49 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 17 Feb 2024 17:55:49 -0500 (EST) Subject: Can one output something other than 'nan' for not a number values? References: Message-ID: <4Tckfs6hPgznVFQ@mail.python.org> On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. [...] >> >> Battery Voltages and Currents >> Leisure Battery - 12.42 volts -0.52 Amps >> Starter Battery - nan volts nan Amps >> >>What I would like is for those 'nan' strings to be just a '-' or >>something similar. > > The simplest thing is probably just a function writing it how you want > it: > > def float_s(f): > if isnan(f): > return "-" > return str(f) He's obviouisly using a formatting feature to control columns and decimal places, so I doubt that 'str(f)' is going to meet the need. I tried monkey-patching the __format__ method of the 'float' type, but it's immutable -- so that didn't work. Is float.__format__() what's used by f-strings, the % operator, etc.? -- Grant From grant.b.edwards at gmail.com Sat Feb 17 18:10:07 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 17 Feb 2024 18:10:07 -0500 (EST) Subject: Can one output something other than 'nan' for not a number values? References: Message-ID: <4TckzM4qNdznVDY@mail.python.org> On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. [...] >> >> Battery Voltages and Currents >> Leisure Battery - 12.42 volts -0.52 Amps >> Starter Battery - 12.34 volts -0.01 Amps > The simplest thing is probably just a function writing it how you > want it: > > def float_s(f): > if isnan(f): > return "-" > return str(f) Since he's obviously using one of the float formatting mechanisms to control the number of columsn and decimal places, I doubt str(f) will meet the need. I tried monkey-patching the float type's __format__ method, but it's immutable. Is float.__format__() what's used by f-strings, the '%' operator, etc.? -- Grant From grante at panix.com Sat Feb 17 18:24:14 2024 From: grante at panix.com (Grant Edwards) Date: Sat, 17 Feb 2024 18:24:14 -0500 (EST) Subject: Can one output something other than 'nan' for not a number values? References: Message-ID: <4TclHf04YLznVCN@mail.python.org> On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. [...] >> >> Battery Voltages and Currents >> Leisure Battery - 12.42 volts -0.52 Amps >> Starter Battery - 12.34 volts -0.01 Amps > The simplest thing is probably just a function writing it how you > want it: > > def float_s(f): > if isnan(f): > return "-" > return str(f) Since he's obviously using one of the float formatting mechanisms to control the number of columsn and decimal places, I doubt str(f) will meet the need. I tried monkey-patching the float type's __format__ method, but it's immutable. Is float.__format__() what's used by f-strings, the '%' operator, etc.? -- Grant From grant.b.edwards at gmail.com Sat Feb 17 18:32:00 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 17 Feb 2024 17:32:00 -0600 Subject: Can one output something other than 'nan' for not a number values? Message-ID: [I've been trying all afternoon to post via slrn, but nothing is showing up on the list. Forgive me if multiple posts eventually show up.] On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. [...] >> >> Battery Voltages and Currents >> Leisure Battery - 12.42 volts -0.52 Amps >> Starter Battery - 12.34 volts -0.01 Amps > The simplest thing is probably just a function writing it how you > want it: > > def float_s(f): > if isnan(f): > return "-" > return str(f) Since he's obviously using one of the float formatting mechanisms to control the number of columsn and decimal places, I doubt str(f) will meet the need. I tried monkey-patching the float type's __format__ method, but it's immutable. Is float.__format__() what's used by f-strings, the '%' operator, etc.? -- Grant From grante at panix.com Sat Feb 17 18:39:33 2024 From: grante at panix.com (Grant Edwards) Date: Sat, 17 Feb 2024 17:39:33 -0600 Subject: Can one output something other than 'nan' for not a number values? Message-ID: <947c66d6be579fdf4f7751dee837c01f@panix.com> [Posts via slrn and my GMail account aren't showing up, so I guess I'll try subscribing from a different e-mail address.] On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >> I'm looking for a simple way to make NaN values output as something >> like '-' or even just a space instead of the string 'nan'. [...] >> >> Battery Voltages and Currents >> Leisure Battery - 12.42 volts -0.52 Amps >> Starter Battery - 12.34 volts -0.01 Amps > The simplest thing is probably just a function writing it how you > want it: > > def float_s(f): > if isnan(f): > return "-" > return str(f) Since he's obviously using one of the float formatting mechanisms to control the number of columsn and decimal places, I doubt str(f) will meet the need. I tried monkey-patching the float type's __format__ method, but it's immutable. Is float.__format__() what's used by f-strings, the '%' operator, etc.? -- Grant From grant.b.edwards at gmail.com Sat Feb 17 19:38:04 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 17 Feb 2024 19:38:04 -0500 (EST) Subject: Testing (sorry) Message-ID: <4Tcmwr61P9znVDY@mail.python.org> Today I noticed that nothing I've posted to python-list in past 3 weeks has shown up on the list. I don't know how to troubleshoot this other than sending test messages. Obviously, if this shows up on the list, then I've gotten it to work... -- Grant From grant.b.edwards at gmail.com Sat Feb 17 19:41:42 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 17 Feb 2024 19:41:42 -0500 (EST) Subject: Testing - 2 (sorry) Message-ID: <4Tcn123HMJznV37@mail.python.org> Today I noticed that nothing I've posted to python-list in past 3 weeks has shown up on the list. I don't know how to troubleshoot this other than sending test messages. Obviously, if this shows up on the list, then I've gotten it to work... -- Grant From grant.b.edwards at gmail.com Sat Feb 17 19:45:09 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 17 Feb 2024 18:45:09 -0600 Subject: Testing (sorry) Message-ID: Today I noticed that nothing I've posted to python-list in the past 3 weeks has shown up on the list. I don't know how to troubleshoot this other than by sending test messages. Obviously, if this shows up on the list, then I'm making progress... [message 3] -- Grant From grante at panix.com Sat Feb 17 19:54:01 2024 From: grante at panix.com (Grant Edwards) Date: Sat, 17 Feb 2024 18:54:01 -0600 Subject: Testing (sorry) Message-ID: <0c10ec3d92f6284c28402419c2b34e00@panix.com> Today I noticed that nothing I've posted to python-list in past 3 weeks has shown up on the list. I don't know how to troubleshoot this other than sending test messages. Obviously, if this shows up on the list, then I'm making progress. [message 4] -- Grant From ScienceResearch01 at earthlink.net Sat Feb 17 18:00:59 2024 From: ScienceResearch01 at earthlink.net (Science Researcher) Date: Sat, 17 Feb 2024 17:00:59 -0600 Subject: Yes - But it had to be specially installed - Feb. 17, 2024 In-Reply-To: References: Message-ID: "Lawrence D'Oliveiro" wrote in message news:uqmbp3$3hsa6$1 at dont-email.me... On Thu, 15 Feb 2024 15:15:58 -0600, E.D.G. wrote: > X-Newsreader: Microsoft Windows Live Mail 15.4.3508.1109 Does that still exist? "Microsoft Windows Live Mail" did still exist when I installed it several years ago on my latest Windows Operating System. If I remember correctly, I had to get the installation program from a third party site. It might have been the Microsoft site. Or it might have been SourceForge.net. You would need to look around the Internet for valid copies of Windows Live Mail if you are interested in the program. Regards to all From invalid at invalid.invalid Sat Feb 17 18:52:09 2024 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 17 Feb 2024 23:52:09 -0000 (UTC) Subject: Can one output something other than 'nan' for not a number values? References: Message-ID: On 2024-02-16, Chris Green wrote: > I'm looking for a simple way to make NaN values output as something > like '-' or even just a space instead of the string 'nan'. I tried monkey-patching the __format__ method of float, but it's immutable, so that didnt' work. Is float.__format__ what's used by f-strings, the % operator, etc.? -- Grant From ScienceResearch01 at earthlink.net Sat Feb 17 21:27:36 2024 From: ScienceResearch01 at earthlink.net (Science Researcher) Date: Sat, 17 Feb 2024 20:27:36 -0600 Subject: Proposed Python Computer Program - Feb. 17, 2024 Message-ID: PROPOSED PYTHON COMPUTER LANGUAGE PROGRAM - Posted on February 17, 2024 TOPICS Some Background Information Test Post Newsgroups Adding Posting Dates To Newsgroup Notes E-mail Address Other Internet Security Steps Personal Opinion Statements SOME BACKGROUND INFORMATION A fair amount of detail has been included with this Newsgroup post because now that I finally have my Newsgroup posting program running again, I am planning to soon start recommending that Python programmers around the world consider working on the creation of a very important python computer language program that I believe will be of great value to international disaster management efforts and to quite a few scientists around the world. The overall programming effort might best be run by university and government python programming personnel. But the computer program would have so many different uses that individual programmers would likely be able to make improvements and submit them for consideration by the university and government groups. A perl computer language version of the program has been running for years. A long time ago, code for an early version was formally copyrighted in the United States. Program code was also made available for free use under a GNU license. The version of perl that I am using processes computer program code in a very slow manner. The present perl program contains more than 13,000 line of code and has to generate png picture files by sending information to a gnuplot program. Compiled python programs would run much faster and be of greater value to scientists. Gnuplot, for example, would no longer be needed. I expect that once a python version of the program became available to scientists, the program would evolve with tremendous speed. It should have the ability to tell scientists how to make improvements to its own math routines. They would improve the program's data generation accuracy and its value. One of my specialty areas in science involves disaster management where I believe I am considered to be an "Expert." I have several degrees in the physical sciences. I do a fair amount of computer programming but would not be considered a python computer programming "Expert" or even a "Novice." So it would be difficult for me to translate the present perl and gnuplot routines to python. In the past, one programming problem resulted from the fact that I developed the original perl program with the help of a retired U.S. government computer programmer. He could work with gnuplot and TrueBasic but was unable to work with either perl or python. A number of compromises had to be made. One involved using gnuplot to generate picture files. TEST POST NEWSGROUPS Several response posts to my original test posts discussed sending them to some test Newsgroup before posting them to the comp.lang.python Newsgroup. I did post one or more of my original tests posts to the test.ignore Newsgroup. There were two problems that I was having was with my E-mail computer program - Windows Live Mail - that also creates my Newsgroup posts. First - It worked fine for E-mail after I installed it on my computer. But it would not work for Newsgroup posts. I called my E-mail server personnel about the problem. But they seemed to have no idea regarding what I was talking about and could not answer my questions. Second - my Newsgroup post program would not use the return E-mail address that I wanted it to use when it created Newsgroup posts. Solutions - The solutions for both problems were to just reset everything with my E-mail server and my E-mail and Newsgroup message creation program. Then the Newsgroup posting part of "Windows Live Mail" started working. ADDING POSTING DATES TO NEWSGROUP NOTES The contents of my Newsgroup posts are at times sent to people by E-mail or are posted to Internet forums. So, I usually add the posting date to my Newsgroup posts so that people receiving the E-mails or reading the forum posts know when the original Newsgroup message was posted. The E-mails etc. would just contain text information. People reading them would not be able to determine from the header information when the original Newsgroup note was posted. E-MAIL ADDRESS The response E-mail address attached to this Newsgroup post is a real E-mail address. It has a special form so that the address can be easily changed when spam robots start sending E-mails to that address. Over the years I have found that spam robots can create a variety of problems once they get hold of an E-mail address. Making a minor change in the E-mail address seems to take care of the problem. It appears that even a simple change can confuse most or all of the spam robots. For a while, they likely continue to send E-mails to an address that no longer exists and probably eventually abandon their efforts. OTHER INTERNET SECURITY STEPS Over the decades, I have sent a considerable amount of information to various world governments. They have at times made good use of my recommendations. With each election, people running different governments, especially the U.S. government, can change their opinions regarding what they believe is and is not important. As a consequence, people running the U.S. government, for example, might presently like what a person states in a Newsgroup post. But 4 or 8 years from now, a new group of people running the government might not like what someone said 4 or 8 years in the past. To be on the safe side, since various governments might be using my information regarding subjects such as "Renewable Energy," I don't add personal names to my Newsgroup posts or even to my E-mail messages. Instead, some neutral name such as "Science Researcher" is used. Most government officials would probably not be able to easily determine who "Science Researcher," for example, is. Except in unusual circumstances, they likely won't attempt to check the header information associated with a Newsgroup post or an E-mail letter. If you add a personal name to a Newsgroup post, an E-mail, an Internet forum post, or your own Web site you are making it easy for possibly unfriendly future government officials to determine whom you might be and then get revenge on you for proposing that "Renewable Energy" is good! PERSONAL OPINION STATEMENTS "These are statements of personal opinion." It is likely important to at times add the above "Personal Opinion" statement to Newsgroup posts when they contain specific words, phrases, or information etc. such as "Windows Live Mail" that might be copyrighted. Most people would probably not want to have the Microsoft corporation getting angry with them. I also don't want my E-mail server personnel to become angry because I stated that they were unable to answer some simple questions regarding posting notes to Newsgroups. Regards to all. Science Researcher From ScienceResearch01 at earthlink.net Sun Feb 18 00:17:14 2024 From: ScienceResearch01 at earthlink.net (Science Researcher) Date: Sat, 17 Feb 2024 23:17:14 -0600 Subject: test-ignore In-Reply-To: References: Message-ID: "Lawrence D'Oliveiro" wrote in message news:uqrik4$lrc1$1 at dont-email.me... On Sat, 17 Feb 2024 17:00:59 -0600, Science Researcher wrote: > "Lawrence D'Oliveiro" wrote in message > news:uqmbp3$3hsa6$1 at dont-email.me... > > If I remember correctly, I had to get the installation program > from a third party site. I?m sure that was a perfectly trustworthy site, no doubt ... Comment: My moderately expensive computer virus program can be instructed to check the contents of downloaded EXE programs and other types of programs or ZIP files. It appears to do a fairly good job with that. But, you are correct. People should be careful regarding what they download. From ScienceResearch01 at earthlink.net Sun Feb 18 04:35:40 2024 From: ScienceResearch01 at earthlink.net (Science Researcher) Date: Sun, 18 Feb 2024 03:35:40 -0600 Subject: =?UTF-8?Q?Python_Stampede_Time=3F_=E2=80=93_Feb._18=2C?= =?UTF-8?Q?_2024?= In-Reply-To: References: Message-ID: "Science Researcher" wrote in message news:z4acnQBO6MKF9kz4nZ2dnZfqn_ednZ2d at earthlink.com... PROPOSED PYTHON COMPUTER LANGUAGE PROGRAM - Posted on February 17, 2024 PYTHON STAMPEDE TIME ? ? Posted on February 18, 2024 Before discussing this specific topic in detail I am going to mention another Internet security practice. That practice applies to this particular posting. WEB SITE ADDRESSES It can pose some risks for a person to post a note to any Newsgroup or for him or her to even circulate an E-mail letter that contains his or her exact Web site address. One of the reasons for this is the fact that many hackers around the world can probably gain access to files that contain Web site addresses. They can then change something in an address. When people click on that address they can then be fooled and transported to the hacker?s own Web site where there could be some malicious software. Generally, what I myself do is point people to major Internet search engines where they can find links to my personal Web site. I expect that it can be difficult for hackers to effectively trick major Internet search engines such as Yahoo or Google into providing people with inaccurate Web site addresses. The hackers might trick the search engines for short periods of time. But recovery for the search engines should be fairly rapid. PYTHON COMPUTER LANGUAGE PROGRAMMERS Over the years, I have worked with personnel involved with quite a few governments and organizations such as the United Nations. Some python Newsgroup readers might think that I am making up the following: Without any doubt and quite surprisingly, the most cooperative people whom I have ever encountered are the people who post notes to the python Newsgroup. My best guess is that they (some of you) do a certain amount of computer programming because it is simply interesting and fun. It is unlikely that anyone is paying you to post notes here. I hope that this spirit of cooperation will continue. Responses to this present post should indicate if that will remain the case. PYTHON STAMPEDE TIME ? What I discovered long ago is the fact that perhaps the best way to get other scientists around the world to do something, or even anything, is to create a ?Science Stampede.? Most scientists like fame and fortune, especially the fame part. They like to publish scientific papers and see their publications get discussed in the international news. They DON?T like to feel like they are getting left behind in some area of science where they believe they might be experts. A ?Science Stampede? involves circulating information that demonstrates that some important scientific discovery has been made. It proposes to scientists that their participation in some effort might get them some credit, or money, or both, with their employers or with international news service personnel. If the scientists believe that the circulated information is credible they are likely to try to get involved with the subject matter. They might ask their employers to pay them to work on the project being discussed. This sequence of events can quickly result in a ?Science Stampede.? Everyone rushes to get a piece of the action. HOW TO CREATE A PYTHON COMPUTER PROGRAM STAMPEDE I am going to guess that the following should work. I hope that it will. MY WEB SITE Anyone who wants to visit my Web site can go to any major Internet search engine and type in the following line: earthquake research index.html Data.html My Earthquake Forecasting Web site address should be at or near the top of the returned list. If it is not, then try a different search engine. Near the top of the index.html Web page there is a link for one of my Web pages called ?Humanitarian Projects.? If you click on that link you will find a discussion of a number of proposed python computer programming efforts. One is already running though I was not involved with the effort. It involves using python code to translate and compile programs written using other languages. One called PC BASIC was I believe created using that approach. Also near the top of the index.html Web page there is a link for one of my Web pages called ?Energy Islands.? I believe that the ?Energy Islands? discussed on my Web page represent a look into the future for some Renewable Energy projects. I am presently trying to get governments and scientific organization to take an interest in doing some research on those proposed ?Inventions.? So far, I have never seen anything like them discussed anywhere. EARTHQUAKE RELATED PYTHON COMPUTER PROGRAMS My already existing perl language programs can do a number of things that are important for earthquake science. 1. They can generate data related to the locations of the sun and the moon in the sky relative to the surface of the Earth. Those data are in good agreement with the U.S. Navy?s MICA computer program. There is a TrueBasic EXE computer program called SunGP that is available through my Web site. It generates those sun and moon location data plus some important data associated with an effect that scientists refer to as the ?Tide Generating Force.? That is not a true force but rather a math representation that explains how the sun and moon gravities affect ocean tides and the ?Solid Earth Tide.? It took a combined effort lasting about 6 months for a retired U.S. government computer programmer and me to create the SunGP computer program. Not being a math expert it was a nightmarish effort for me to try to picture how sun and moon gravity forces needed to be added together in 3 dimensions so that the needed data could be generated. People whom I talked with in a math Newsgroup stated to me that there was no simpler way to add the gravity forces together in 3 dimensions than the equations that I had developed. However, I think that they were probably wrong. There must be an easier way. Anyway, the equations that I developed do work as needed. A python computer program could easily do what the existing TrueBasic SunGP.exe computer program does. 2. The sun and moon data can be used by researchers to tell why many of our powerful earthquake are occurring at the exact times that they are occurring. It is somewhat astonishing to me that after all of these centuries, I was likely the first scientist on the planet to clearly demonstrate that those earthquake triggering sun and moon gravity effects can be easily shown to exist. At least one scientific paper was published based on my data. 3. When the right type of earthquake precursor data are entered into my perl language computer program it becomes possible to predict when at least some of our powerful earthquakes are going to occur. 4. Using the right type of earthquake precursor data, the perl program can do an absolutely extraordinary job with predicting earthquake aftershocks. This is because we already know WHERE an aftershock is going to occur. We only need to determine WHEN one will occur. 5. My perl language program will run with the ancient Windows XP operating system, off a flash drive, and even using a read/write CD compact disk. I don?t recommend that anyone try running the program using a read/write CD. I tried doing that. Snails move faster. Trees grow faster. 6. The entire program can be easily moved from one computer to another by copying the necessary directories and the 5.1 version of perl that the program uses. 7. EXE versions of the perl program can be created. But what they do is simply bundle the program code with the entire perl compiler. The resultant EXE program will run on a Windows computer. But it is both enormous and slow. 8. The perl language program has a feature that makes it possible to get the program running, then temporarily jump out of the program and change the code, and then tell the perl compiler to restart using the new code. That feature was developed because when the program runs, it creates a variety of data arrays. They take a while to create. If the data arrays had to be recreated each time the program was restarted like that, nothing would ever get done. But with that routine, the arrays remain active in the computer. I understand that python can also do that. 9. Even I find it to be a nightmare to work with my perl language code. They were created over a long period of time using layers of program code and subroutines that jump from one location to another using If Then GoTo commands. That 5.1 ancient version of perl seems to be perfectly happy to jump out of a subroutine and go to another program location. It isn?t necessary to formally close the subroutine. However, you can?t simply jump INTO a subroutine and expect it to work. It has to be formally called. It can literally take me days to add new features to the perl program because it is so complex. It is moderately well documented. But even then it can be difficult for me to determine exactly where some change needs to be made. That is partly because the perl program needs to interact with gnuplot. One perl language expert who saw an EXE version of my program stated that it was the worst computer program he had ever seen. He was likely correct with his opinion. But, not being a professional computer programmer, my attitude is that if a computer program runs and does what you want it to do, who cares if its code are a little (or a lot) ugly looking! A python version of the program would be properly documented and actually look like it was written by professional computer programmers. MY PERSONAL INTERESTS WITH THIS PROPOSED COMPUTER PROGRAM Obviously, it is nice to be able to save some lives with an Earthquake Forecasting computer program that actually works. However, there is a personal financial consideration that I feel is important. Over the years it probably cost me a million dollars U.S. worth of my research time to develop that perl language computer program. It presently costs me perhaps $20,000 worth of my research time per year to keep it running. It would save me a lot of time and money to simply get rid of the program development and usage efforts. Geology is not one of my specialty areas of science. Geologists around the world can have the program for free with my full blessing. Two of them already published a technical paper that was based on data that my computer programs generated. So, they like the general subject matter. THE PROPOSED PYTHON COMPUTER PROGRAM, CASH, AND RESEARCH GRANTS Scientists and their governments and other employers already know how to generate sun and moon location data. But, I have never heard of any free or even costly software that can generate the ?Tide Generating Force? types of data that my already existing free SunGP computer program can generate. And, SunGP is just a very basic routine in the far more complex perl language program. It might be difficult to believe, but there are no scientists or governments anywhere that I have ever heard of that can generate the earthquake triggering types of data that my perl language computer program can generate. Scientists and their government would really LIKE to be able to do that. But even though my perl language computer code have been available to them for years for free through a GNU license, as far as I am aware, no one else has ever tried to use or duplicate those program code. It is my opinion that if a reasonable looking python version of the computer program is created, many scientists around the world will quickly get involved in a ?Science Stampede? as they attempt to get some credit, publications, or even cash by making improvements to the program. Earthquake science should then progress faster than almost any science anyone has ever heard about. Python computer programmers should become the proverbial ?Kings of the hill!? I personally have no intention of becoming an expert python programmer. BASIC has always been my favorite programming language, not perl. The earliest versions of my perl program were developed using GWBasic. However, it had extreme limitations that quickly forced me to move to perl. Back then, python was I believe still in its early stages of development. Now it appears to me to be the language of choice. As stated earlier, python Newsgroup users seem to also be a lot friendly than perl Newsgroup users were way back then. However, I really couldn?t blame the perl Newsgroup users for not liking my program. Its code WOULD BE pretty ugly looking to a professional computer programmer. These are statements of personal opinion. Regards to all, Science Researcher From piergiorgio.sartor.this.should.not.be.used at nexgo.REMOVETHIS.de Sun Feb 18 09:03:51 2024 From: piergiorgio.sartor.this.should.not.be.used at nexgo.REMOVETHIS.de (Piergiorgio Sartor) Date: Sun, 18 Feb 2024 15:03:51 +0100 Subject: Can one output something other than 'nan' for not a number values? In-Reply-To: References: Message-ID: <7bf9ak-8m5.ln1@lazy.lzy> On 16/02/2024 23.12, Chris Green wrote: > I'm looking for a simple way to make NaN values output as something > like '-' or even just a space instead of the string 'nan'. This would > then make it much easier to handle outputting values from sensors when > not all sensors are present. > > So, for example, my battery monitoring program outputs:- > > Battery Voltages and Currents > Leisure Battery - 12.42 volts -0.52 Amps > Starter Battery - 12.34 volts -0.01 Amps > > If the starter battery sensor has failed, or is disconnected, I see:- > > Battery Voltages and Currents > Leisure Battery - 12.42 volts -0.52 Amps > Starter Battery - nan volts nan Amps > > > What I would like is for those 'nan' strings to be just a '-' or > something similar. > > Obviously I can write conditional code to check for float('nan') > values but is there a neater way with any sort of formatting string or > other sort of cleverness? Uhm, I cannot see how to avoid conditional code. Somewhere, function, class, method, there should be an "if isnan(x)". You can hide that, but you cannot avoid, I suspect. bye, -- piergiorgio From lsvalgaard at gmail.com Sun Feb 18 13:40:38 2024 From: lsvalgaard at gmail.com (Leif Svalgaard) Date: Sun, 18 Feb 2024 10:40:38 -0800 Subject: Matplotlib warning [error?] message Message-ID: The latest[?] version of Matplotlib cannot show a figure. I get the annoying error message: "Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure" I'm using Spyder python 3.11 on Windows 11. What to do? -- Leif Svalgaard leif at leif.org From rosuav at gmail.com Sun Feb 18 14:50:21 2024 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 Feb 2024 06:50:21 +1100 Subject: Can one output something other than 'nan' for not a number values? In-Reply-To: <4TcgpP4sdFznVFX@mail.python.org> References: <4TcgpP4sdFznVFX@mail.python.org> Message-ID: On Mon, 19 Feb 2024 at 06:47, Grant Edwards via Python-list wrote: > I would be tempted to try monkey-patching the float class to override > the __format__ method. I have no idea what side effects that might > have, or if it's even used by the various formatting mechanisms, so > you might end up scraping bits off the walls... > You can try, but you'd have to do it in C - the float type is immutable in Python. ChrisA From hjp-python at hjp.at Sun Feb 18 16:30:34 2024 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 18 Feb 2024 22:30:34 +0100 Subject: Testing (sorry) In-Reply-To: <4Tcmwr61P9znVDY@mail.python.org> References: <4Tcmwr61P9znVDY@mail.python.org> Message-ID: <20240218213034.n4hjfnunabsslwbq@hjp.at> [Replying to the list *and* Grant] On 2024-02-17 19:38:04 -0500, Grant Edwards via Python-list wrote: > Today I noticed that nothing I've posted to python-list in past 3 > weeks has shown up on the list. January 29th, AFAICS. And end of december before that. > I don't know how to troubleshoot this other than sending test > messages. Obviously, if this shows up on the list, then I've gotten > it to work... This did show up and 3 other test messages with very similar text as well. Also there was a whole flurry of almost but not quite identical messages from you in the "nan" thread. 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 PythonList at DancesWithMice.info Sun Feb 18 16:44:41 2024 From: PythonList at DancesWithMice.info (dn) Date: Mon, 19 Feb 2024 10:44:41 +1300 Subject: Can one output something other than 'nan' for not a number values? In-Reply-To: <4Tcgxf47LSznVDn@mail.python.org> References: <4Tcgxf47LSznVDn@mail.python.org> Message-ID: On 18/02/24 09:53, Grant Edwards via Python-list wrote: > On 2024-02-17, Cameron Simpson via Python-list wrote: >> On 16Feb2024 22:12, Chris Green wrote: >>> I'm looking for a simple way to make NaN values output as something >>> like '-' or even just a space instead of the string 'nan'. >>> [...] >>> >>> Battery Voltages and Currents >>> Leisure Battery - 12.42 volts -0.52 Amps >>> Starter Battery - nan volts nan Amps >>> >>> What I would like is for those 'nan' strings to be just a '-' or >>> something similar. > >> The simplest thing is probably just a function writing it how you want >> it: >> >> def float_s(f): >> if isnan(f): >> return "-" >> return str(f) >> >> and then use eg: >> >> print(f'value is {float_s(value)}') >> >> or whatever fits your code. > > Except he's obviously using some sort of formatting to control the > number of columns and decimal places, so 'str(f)' is not going to cut > it. Is the basic floating point number formatting functionality seen > when using f-strings or '%' operator part of the float type or is it > part of the f-string and % operator? It's part of the PSL's string library: "Format Specification Mini-Language" https://docs.python.org/3/library/string.html#format-specification-mini-language Has the OP stated if we're talking 'Python' or numpy, pandas, ...? -- Regards, =dn From mystirk at gmail.com Sun Feb 18 16:55:44 2024 From: mystirk at gmail.com (Alex Kaye) Date: Sun, 18 Feb 2024 14:55:44 -0700 Subject: Testing (sorry) In-Reply-To: <20240218213034.n4hjfnunabsslwbq@hjp.at> References: <4Tcmwr61P9znVDY@mail.python.org> <20240218213034.n4hjfnunabsslwbq@hjp.at> Message-ID: We see you Peter AK On Sun, Feb 18, 2024 at 2:41?PM Peter J. Holzer via Python-list < python-list at python.org> wrote: > [Replying to the list *and* Grant] > > On 2024-02-17 19:38:04 -0500, Grant Edwards via Python-list wrote: > > Today I noticed that nothing I've posted to python-list in past 3 > > weeks has shown up on the list. > > January 29th, AFAICS. And end of december before that. > > > I don't know how to troubleshoot this other than sending test > > messages. Obviously, if this shows up on the list, then I've gotten > > it to work... > > This did show up and 3 other test messages with very similar text > as well. > > Also there was a whole flurry of almost but not quite identical messages > from you in the "nan" thread. > > hp > > -- > _ | Peter J. Holzer | Story must make more sense than reality. > |_|_) | | > | | | hjp at hjp.at | -- Charles Stross, "Creative writing > __/ | http://www.hjp.at/ | challenge!" > -- > https://mail.python.org/mailman/listinfo/python-list > From grant.b.edwards at gmail.com Sun Feb 18 18:09:26 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 18 Feb 2024 18:09:26 -0500 (EST) Subject: Testing (sorry) References: <4Tcmwr61P9znVDY@mail.python.org> <20240218213034.n4hjfnunabsslwbq@hjp.at> Message-ID: <4TdLw65nrQznVFn@mail.python.org> On 2024-02-18, Peter J. Holzer via Python-list wrote: > [Replying to the list *and* Grant] > > On 2024-02-17 19:38:04 -0500, Grant Edwards via Python-list wrote: >> Today I noticed that nothing I've posted to python-list in past 3 >> weeks has shown up on the list. > > January 29th, AFAICS. And end of december before that. > >> I don't know how to troubleshoot this other than sending test >> messages. Obviously, if this shows up on the list, then I've gotten >> it to work... > > This did show up and 3 other test messages with very similar text > as well. > > Also there was a whole flurry of almost but not quite identical messages > from you in the "nan" thread. Sorry about that. All of those were posted at various times throughout the day yesterday using two different accounts, two different mail servers, and three different methods for submitting the e-mails. I finally gave up and switched to using comp.lang.python via Usenet. Then, about 24 hours later, all those messages finally showed up. At one point about half way through that process yesterday, I unsusbscribed and then re-subscribed both e-mail addresses. I got confirmation and welcome messages on both accounts. Sending "help" requests to the list server produced the expected results. I enabled the sending of confirmation messages from the list server. But posts to the list still seemed to vanish into the ether while emails from both accounts reached other destinations without delay, During this process a number of posts from other users did appear in the list archive and at at _one_ of the two e-mail addresses which I had subscribed. But no sign of any of my posts. About 24 hours later, all of my posts (and the confirmation e-mails) all showed up in a burst at the same time on two different unrelated e-mail accounts. I still have no clue what was going on... -- Grant From PythonList at DancesWithMice.info Sun Feb 18 18:30:04 2024 From: PythonList at DancesWithMice.info (dn) Date: Mon, 19 Feb 2024 12:30:04 +1300 Subject: Testing (sorry) In-Reply-To: <4TdLw65nrQznVFn@mail.python.org> References: <4Tcmwr61P9znVDY@mail.python.org> <20240218213034.n4hjfnunabsslwbq@hjp.at> <4TdLw65nrQznVFn@mail.python.org> Message-ID: On 19/02/24 12:09, Grant Edwards via Python-list wrote: ... > But posts to the list still seemed to vanish into the ether while > emails from both accounts reached other destinations without delay, > > During this process a number of posts from other users did appear in > the list archive and at at _one_ of the two e-mail addresses which I > had subscribed. > > But no sign of any of my posts. > > About 24 hours later, all of my posts (and the confirmation e-mails) > all showed up in a burst at the same time on two different unrelated > e-mail accounts. > > I still have no clue what was going on... Looking at the email-headers, there are sometimes considerable delays between messages submitted to the List-reflector, and their outward transmission (to me). Interestingly, there's something strange about the queuing. Instead of FIFO it seems some messages arrive ahead of others, ie out-of-sequence. (wonder if explained by submission via email or Usenet?) I've noted long delays too. Perhaps (also) to do with time-of-day? Always feel slightly embarrassed if 'repeat' an answer* that someone else had previously submitted, eg __new__ thread and @MRAB. However, if the reflector 'holds onto' the earlier message, then how should I/anyone know? * yes, repetition improves learning, slightly different words may help comprehension; but doubt I can express anything better than the aforementioned does/did/can. -- Regards, =dn From skip.montanaro at gmail.com Sun Feb 18 20:04:02 2024 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 18 Feb 2024 19:04:02 -0600 Subject: Testing (sorry) In-Reply-To: References: <4Tcmwr61P9znVDY@mail.python.org> <20240218213034.n4hjfnunabsslwbq@hjp.at> <4TdLw65nrQznVFn@mail.python.org> Message-ID: I can't explain the delays, but will note that the gate-news program on the server runs every 5 minutes via cron. There are multiple moving parts in the overall system. You'll probably get a more useful answer from postmaster at python.org. Skip From list1 at tompassin.net Sun Feb 18 21:34:54 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 18 Feb 2024 21:34:54 -0500 Subject: Testing (sorry) In-Reply-To: <4TdLw65nrQznVFn@mail.python.org> References: <4Tcmwr61P9znVDY@mail.python.org> <20240218213034.n4hjfnunabsslwbq@hjp.at> <4TdLw65nrQznVFn@mail.python.org> Message-ID: <92274913-49a6-43d8-8300-a195c07f8d6b@tompassin.net> On 2/18/2024 6:09 PM, Grant Edwards via Python-list wrote: > On 2024-02-18, Peter J. Holzer via Python-list wrote: >> [Replying to the list *and* Grant] >> >> On 2024-02-17 19:38:04 -0500, Grant Edwards via Python-list wrote: >>> Today I noticed that nothing I've posted to python-list in past 3 >>> weeks has shown up on the list. >> >> January 29th, AFAICS. And end of december before that. >> >>> I don't know how to troubleshoot this other than sending test >>> messages. Obviously, if this shows up on the list, then I've gotten >>> it to work... >> >> This did show up and 3 other test messages with very similar text >> as well. >> >> Also there was a whole flurry of almost but not quite identical messages >> from you in the "nan" thread. > > Sorry about that. > > All of those were posted at various times throughout the day yesterday > using two different accounts, two different mail servers, and three > different methods for submitting the e-mails. I finally gave up and > switched to using comp.lang.python via Usenet. > > Then, about 24 hours later, all those messages finally showed up. > > At one point about half way through that process yesterday, I > unsusbscribed and then re-subscribed both e-mail addresses. I got > confirmation and welcome messages on both accounts. Sending "help" > requests to the list server produced the expected results. I enabled > the sending of confirmation messages from the list server. > > But posts to the list still seemed to vanish into the ether while > emails from both accounts reached other destinations without delay, > > During this process a number of posts from other users did appear in > the list archive and at at _one_ of the two e-mail addresses which I > had subscribed. > > But no sign of any of my posts. > > About 24 hours later, all of my posts (and the confirmation e-mails) > all showed up in a burst at the same time on two different unrelated > e-mail accounts. > > I still have no clue what was going on... Sometimes a post of mine will not show up for hours or even half a day. They are all addressed directly to the list. Sometimes my email provider sends me a notice that the message bounced. Those notices say that the address wasn't available when the transmission was tried. From zahraazirjawi at gmail.com Sun Feb 18 15:17:19 2024 From: zahraazirjawi at gmail.com (Zahraa Fadhil) Date: Sun, 18 Feb 2024 12:17:19 -0800 (PST) Subject: Matplotlib warning [error?] message In-Reply-To: References: Message-ID: <06359a6b-96f5-474b-ba1d-e58369654228n@googlegroups.com> On Sunday, February 18, 2024 at 10:48:29?PM UTC+3, Leif Svalgaard wrote: > The latest[?] version of Matplotlib cannot show a figure. I get the > annoying error message: "Matplotlib is currently using agg, which is a > non-GUI backend, so cannot show the figure" > I'm using Spyder python 3.11 on Windows 11. > What to do? > > -- > Leif Svalgaard > I have the same problem try this 1) add this line first %matplotlib inline import matplotlib import matplotlib.pyplot as plt 2) delete this line from your cod.....matplotlib.use('Agg') 3) save the result into png file plt.savefig('D:\data\mygraph.png') another solution https://www.w3schools.com/python/trypandas.asp?filename=demo_ml_dtree4 import sys import matplotlib matplotlib.use('Agg') .... import matplotlib.pyplot as plt .... #Two lines to make compiler able to draw: plt.savefig(sys.stdout.buffer) sys.stdout.flush() From soyeomul at doraji.xyz Sun Feb 18 20:11:36 2024 From: soyeomul at doraji.xyz (Byunghee HWANG) Date: Mon, 19 Feb 2024 10:11:36 +0900 Subject: Testing (sorry) In-Reply-To: <0c10ec3d92f6284c28402419c2b34e00@panix.com> References: <0c10ec3d92f6284c28402419c2b34e00@panix.com> Message-ID: <92dab30def4bfa6b465327c1f00987ef1180f52c.camel@doraji.xyz> Hellow Grant, On Sat, 2024-02-17 at 18:54 -0600, Grant Edwards via Python-list wrote: > > Today I noticed that nothing I've posted to python-list in past 3 > weeks has shown up on the list. I don't know how to troubleshoot this > other than sending test messages.? Obviously, if this shows up on the > list, then I'm making progress. > > [message 4] > -- > Grant Do not worry. Sending email is harder than coding in Python. Anyway, your email arrived safely in my mailbox. Congratulations! Thanks, Byunghee from South Korea -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: This is a digitally signed message part URL: From cl at isbd.net Mon Feb 19 07:04:44 2024 From: cl at isbd.net (Chris Green) Date: Mon, 19 Feb 2024 12:04:44 +0000 Subject: Can one output something other than 'nan' for not a number values? References: <4Tcgxf47LSznVDn@mail.python.org> Message-ID: dn wrote: > On 18/02/24 09:53, Grant Edwards via Python-list wrote: > > On 2024-02-17, Cameron Simpson via Python-list wrote: > >> On 16Feb2024 22:12, Chris Green wrote: > >>> I'm looking for a simple way to make NaN values output as something > >>> like '-' or even just a space instead of the string 'nan'. > >>> [...] > >>> > >>> Battery Voltages and Currents > >>> Leisure Battery - 12.42 volts -0.52 Amps > >>> Starter Battery - nan volts nan Amps > >>> > >>> What I would like is for those 'nan' strings to be just a '-' or > >>> something similar. > > > >> The simplest thing is probably just a function writing it how you want > >> it: > >> > >> def float_s(f): > >> if isnan(f): > >> return "-" > >> return str(f) > >> > >> and then use eg: > >> > >> print(f'value is {float_s(value)}') > >> > >> or whatever fits your code. > > > > Except he's obviously using some sort of formatting to control the > > number of columns and decimal places, so 'str(f)' is not going to cut > > it. Is the basic floating point number formatting functionality seen > > when using f-strings or '%' operator part of the float type or is it > > part of the f-string and % operator? > > It's part of the PSL's string library: "Format Specification > Mini-Language" > https://docs.python.org/3/library/string.html#format-specification-mini-language > > Has the OP stated if we're talking 'Python' or numpy, pandas, ...? > Just python, on a Raspberry Pi, so currently Python 3.9.2. -- Chris Green ? From cl at isbd.net Mon Feb 19 07:08:00 2024 From: cl at isbd.net (Chris Green) Date: Mon, 19 Feb 2024 12:08:00 +0000 Subject: Can one output something other than 'nan' for not a number values? References: <4TcgpP4sdFznVFX@mail.python.org> Message-ID: <0usbak-7d7.ln1@esprimo.zbmc.eu> Grant Edwards wrote: > On 2024-02-16, Chris Green via Python-list wrote: > > > I'm looking for a simple way to make NaN values output as something > > like '-' or even just a space instead of the string 'nan'. > > It would probably help if you told us how you're "outputting" them now > (the Python feaatures/functions used, not the actual output format). > > Are you using f-strings, the % operator, str.format(), or ?? > > I would be tempted to try monkey-patching the float class to override > the __format__ method. I have no idea what side effects that might > have, or if it's even used by the various formatting mechanisms, so > you might end up scraping bits off the walls... > It's using f'{...}' at the moment. -- Chris Green ? From invalid at invalid.invalid Mon Feb 19 09:17:39 2024 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 19 Feb 2024 14:17:39 -0000 (UTC) Subject: Testing (sorry) References: <4Tcmwr61P9znVDY@mail.python.org> <20240218213034.n4hjfnunabsslwbq@hjp.at> <4TdLw65nrQznVFn@mail.python.org> <92274913-49a6-43d8-8300-a195c07f8d6b@tompassin.net> Message-ID: On 2024-02-19, Thomas Passin wrote: >> About 24 hours later, all of my posts (and the confirmation e-mails) >> all showed up in a burst at the same time on two different unrelated >> e-mail accounts. >> >> I still have no clue what was going on... > > Sometimes a post of mine will not show up for hours or even half a day. > They are all addressed directly to the list. Sometimes my email > provider sends me a notice that the message bounced. Those notices say > that the address wasn't available when the transmission was tried. I guess that in future I'll wait a couple days before I assume something is broken. -- Grant From list1 at tompassin.net Mon Feb 19 11:38:54 2024 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 19 Feb 2024 11:38:54 -0500 Subject: Testing (sorry) In-Reply-To: References: <4Tcmwr61P9znVDY@mail.python.org> <20240218213034.n4hjfnunabsslwbq@hjp.at> <4TdLw65nrQznVFn@mail.python.org> <92274913-49a6-43d8-8300-a195c07f8d6b@tompassin.net> Message-ID: <43513ae2-8180-4fe9-ad12-c45e1840989f@tompassin.net> On 2/19/2024 9:17 AM, Grant Edwards via Python-list wrote: > On 2024-02-19, Thomas Passin wrote: > >>> About 24 hours later, all of my posts (and the confirmation e-mails) >>> all showed up in a burst at the same time on two different unrelated >>> e-mail accounts. >>> >>> I still have no clue what was going on... >> >> Sometimes a post of mine will not show up for hours or even half a day. >> They are all addressed directly to the list. Sometimes my email >> provider sends me a notice that the message bounced. Those notices say >> that the address wasn't available when the transmission was tried. Here is a typical bounce message that I get: : host mail.python.org[188.166.95.178] said: 450-4.3.2 Service currently unavailable 450 4.3.2 Some time after I get one of these messages I re-send the post. Usually it gets through then. > I guess that in future I'll wait a couple days before I assume > something is broken. > > -- > Grant > From skip.montanaro at gmail.com Mon Feb 19 11:55:46 2024 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 19 Feb 2024 10:55:46 -0600 Subject: Testing (sorry) In-Reply-To: <43513ae2-8180-4fe9-ad12-c45e1840989f@tompassin.net> References: <4Tcmwr61P9znVDY@mail.python.org> <20240218213034.n4hjfnunabsslwbq@hjp.at> <4TdLw65nrQznVFn@mail.python.org> <92274913-49a6-43d8-8300-a195c07f8d6b@tompassin.net> <43513ae2-8180-4fe9-ad12-c45e1840989f@tompassin.net> Message-ID: > > Here is a typical bounce message that I get: > > : host mail.python.org[188.166.95.178] said: > 450-4.3.2 > Service currently unavailable 450 4.3.2 > > Some time after I get one of these messages I re-send the post. Usually > it gets through then. > Looks kinda like greylisting to me. I'm pretty sure that's one of the tool in the mail.python.org chain. Skip > From grant.b.edwards at gmail.com Mon Feb 19 11:58:31 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 19 Feb 2024 11:58:31 -0500 (EST) Subject: Can one output something other than 'nan' for not a number values? References: <4TcgpP4sdFznVFX@mail.python.org> <0usbak-7d7.ln1@esprimo.zbmc.eu> Message-ID: <4Tdpdg40RQznVGQ@mail.python.org> On 2024-02-19, Chris Green via Python-list wrote: > It's using f'{...}' at the moment. Here's a demonstration of how to hook custom code into the f-string formatting engine. It's brilliantly depraved. https://stackoverflow.com/questions/55876683/hook-into-the-builtin-python-f-string-format-machinery >From the above: You can, but only if you write evil code that probably should never end up in production software. So let's get started! I'm not going to integrate it into your library, but I will show you how to hook into the behavior of f-strings. This is roughly how it'll work: 1. Write a function that manipulates the bytecode instructions of code objects to replace FORMAT_VALUE instructions with calls to a hook function; 2. Customize the import mechanism to make sure that the bytecode of every module and package (except standard library modules and site-packages) is modified with that function. Final code is here: https://github.com/mivdnber/formathack From lsvalgaard at gmail.com Mon Feb 19 12:39:16 2024 From: lsvalgaard at gmail.com (Leif Svalgaard) Date: Mon, 19 Feb 2024 09:39:16 -0800 Subject: Matplotlib warning [error?] message Message-ID: now I get: File e:\getmodpot.py:40 fig,ax = initPlot() File E:\mystuff.py:272 in initPlot fig,ax = plt.subplots(figsize=(xs,ys)) File ~\anaconda3\Lib\site-packages\matplotlib\pyplot.py:1501 in subplots fig = figure(**fig_kw) File ~\anaconda3\Lib\site-packages\matplotlib\_api\deprecation.py:454 in wrapper return func(*args, **kwargs) File ~\anaconda3\Lib\site-packages\matplotlib\pyplot.py:840 in figure manager = new_figure_manager( File ~\anaconda3\Lib\site-packages\matplotlib\pyplot.py:384 in new_figure_manager return _get_backend_mod().new_figure_manager(*args, **kwargs) File ~\anaconda3\Lib\site-packages\matplotlib\backend_bases.py:3573 in new_figure_manager File ~\anaconda3\Lib\site-packages\matplotlib\_api\deprecation.py:454 in wrapper return func(*args, **kwargs) File ~\anaconda3\Lib\site-packages\matplotlib\figure.py:2505 in __init__ "The Figure parameters 'layout' and 'constrained_layout' " File ~\anaconda3\Lib\site-packages\matplotlib\figure.py:213 in __init__ self.set(**kwargs) File ~\anaconda3\Lib\site-packages\matplotlib\artist.py:147 in cls.set = lambda self, **kwargs: Artist.set(self, **kwargs) File ~\anaconda3\Lib\site-packages\matplotlib\artist.py:1227 in set return self._internal_update(cbook.normalize_kwargs(kwargs, self)) File ~\anaconda3\Lib\site-packages\matplotlib\cbook\__init__.py:1771 in normalize_kwargs for canonical, alias_list in alias_mapping.items() AttributeError: 'Figure' object has no attribute 'items' -- Leif Svalgaard leif at leif.org From list1 at tompassin.net Mon Feb 19 12:05:01 2024 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 19 Feb 2024 12:05:01 -0500 Subject: Testing (sorry) In-Reply-To: References: <4Tcmwr61P9znVDY@mail.python.org> <20240218213034.n4hjfnunabsslwbq@hjp.at> <4TdLw65nrQznVFn@mail.python.org> <92274913-49a6-43d8-8300-a195c07f8d6b@tompassin.net> <43513ae2-8180-4fe9-ad12-c45e1840989f@tompassin.net> Message-ID: <893b8044-9ecf-44f6-ba88-57451790e7b1@tompassin.net> On 2/19/2024 11:55 AM, Skip Montanaro wrote: > Here is a typical bounce message that I get: > > >: host > mail.python.org [188.166.95.178] said: > 450-4.3.2 > ? ? ?Service currently unavailable 450 4.3.2 > > Some time after I get one of these messages I re-send the post. > Usually > it gets through then. > > > Looks kinda like greylisting to me. I'm pretty sure that's one of the > tool in the mail.python.org chain. I don't see it as greylisting. A repeat post will succeed, before there would be time for my email provider (Dreamhost) to do anything about it. From PythonList at DancesWithMice.info Mon Feb 19 15:11:31 2024 From: PythonList at DancesWithMice.info (dn) Date: Tue, 20 Feb 2024 09:11:31 +1300 Subject: Can one output something other than 'nan' for not a number values? In-Reply-To: <4Tdpdg40RQznVGQ@mail.python.org> References: <4TcgpP4sdFznVFX@mail.python.org> <0usbak-7d7.ln1@esprimo.zbmc.eu> <4Tdpdg40RQznVGQ@mail.python.org> Message-ID: <883e3bdb-d6ca-47e3-97f2-6a0dd8720161@DancesWithMice.info> On 20/02/24 05:58, Grant Edwards via Python-list wrote: > Here's a demonstration of how to hook custom code into the f-string > formatting engine. It's brilliantly depraved. > > https://stackoverflow.com/questions/55876683/hook-into-the-builtin-python-f-string-format-machinery > > From the above: > > You can, but only if you write evil code that probably should > never end up in production software. So let's get started! > > I'm not going to integrate it into your library, but I will show > you how to hook into the behavior of f-strings. This is roughly > how it'll work: > > 1. Write a function that manipulates the bytecode instructions of > code objects to replace FORMAT_VALUE instructions with calls > to a hook function; > > 2. Customize the import mechanism to make sure that the bytecode > of every module and package (except standard library modules > and site-packages) is modified with that function. > > Final code is here: > > https://github.com/mivdnber/formathack Some of this (Expression components inside f-strings) newly available in v3.12 (PEP-701) - which can be used in production... -- Regards, =dn From PythonList at DancesWithMice.info Mon Feb 19 15:17:10 2024 From: PythonList at DancesWithMice.info (dn) Date: Tue, 20 Feb 2024 09:17:10 +1300 Subject: Can one output something other than 'nan' for not a number values? In-Reply-To: References: <4Tcgxf47LSznVDn@mail.python.org> Message-ID: <907fcf20-1181-4fae-8479-487bf4cd3f2b@DancesWithMice.info> On 20/02/24 01:04, Chris Green via Python-list wrote: > dn wrote: >> On 18/02/24 09:53, Grant Edwards via Python-list wrote: >>> On 2024-02-17, Cameron Simpson via Python-list wrote: >>>> On 16Feb2024 22:12, Chris Green wrote: >>>>> I'm looking for a simple way to make NaN values output as something >>>>> like '-' or even just a space instead of the string 'nan'. >>>>> [...] >>>>> >>>>> Battery Voltages and Currents >>>>> Leisure Battery - 12.42 volts -0.52 Amps >>>>> Starter Battery - nan volts nan Amps >>>>> >>>>> What I would like is for those 'nan' strings to be just a '-' or >>>>> something similar. >>> >>>> The simplest thing is probably just a function writing it how you want >>>> it: >>>> >>>> def float_s(f): >>>> if isnan(f): >>>> return "-" >>>> return str(f) >>>> >>>> and then use eg: >>>> >>>> print(f'value is {float_s(value)}') >>>> >>>> or whatever fits your code. >>> >>> Except he's obviously using some sort of formatting to control the >>> number of columns and decimal places, so 'str(f)' is not going to cut >>> it. Is the basic floating point number formatting functionality seen >>> when using f-strings or '%' operator part of the float type or is it >>> part of the f-string and % operator? >> >> It's part of the PSL's string library: "Format Specification >> Mini-Language" >> https://docs.python.org/3/library/string.html#format-specification-mini-language >> >> Has the OP stated if we're talking 'Python' or numpy, pandas, ...? >> > Just python, on a Raspberry Pi, so currently Python 3.9.2. Concur with earlier advice (and assuming is only a consideration during output) - use if. Alternately, encode appropriately during the data-capture phase. -- Regards, =dn From hjp-python at hjp.at Tue Feb 20 16:27:55 2024 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 20 Feb 2024 22:27:55 +0100 Subject: Testing (sorry) In-Reply-To: <43513ae2-8180-4fe9-ad12-c45e1840989f@tompassin.net> References: <4Tcmwr61P9znVDY@mail.python.org> <20240218213034.n4hjfnunabsslwbq@hjp.at> <4TdLw65nrQznVFn@mail.python.org> <92274913-49a6-43d8-8300-a195c07f8d6b@tompassin.net> <43513ae2-8180-4fe9-ad12-c45e1840989f@tompassin.net> Message-ID: <20240220212755.t2vlyfym7xvd3wc7@hjp.at> On 2024-02-19 11:38:54 -0500, Thomas Passin via Python-list wrote: > On 2/19/2024 9:17 AM, Grant Edwards via Python-list wrote: > > On 2024-02-19, Thomas Passin wrote: > > > > About 24 hours later, all of my posts (and the confirmation e-mails) > > > > all showed up in a burst at the same time on two different unrelated > > > > e-mail accounts. > > > > > > > > I still have no clue what was going on... > > > > > > Sometimes a post of mine will not show up for hours or even half a day. > > > They are all addressed directly to the list. Sometimes my email > > > provider sends me a notice that the message bounced. Those notices say > > > that the address wasn't available when the transmission was tried. > > Here is a typical bounce message that I get: > > : host mail.python.org[188.166.95.178] said: > 450-4.3.2 > Service currently unavailable 450 4.3.2 This is a *temporary* error. Your provider's server should retry delivering the message for a decent amount of time (3 to 7 days is customary). Your provider's server may send you a notification that the mail cannot currently be delivered and that it will keep trying. Such notifications are usually sent after a much shorter period (a few hours). 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 Gronicus at SGA.Ninja Fri Feb 23 20:14:00 2024 From: Gronicus at SGA.Ninja (Steve GS) Date: Fri, 23 Feb 2024 20:14:00 -0500 Subject: Problem resizing a window and button placement Message-ID: <06a301da66be$bfdc0da0$3f9428e0$@SGA.Ninja> Python, Tkinter: How do I determine if a window has been resized? I want to locate buttons vertically along the right border and need to know the new width. The buttons are to move with the change of location of the right-side border. SGA From python at mrabarnett.plus.com Fri Feb 23 21:26:43 2024 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 24 Feb 2024 02:26:43 +0000 Subject: Problem resizing a window and button placement In-Reply-To: <06a301da66be$bfdc0da0$3f9428e0$@SGA.Ninja> References: <06a301da66be$bfdc0da0$3f9428e0$@SGA.Ninja> Message-ID: <76894f6f-551c-470a-93c7-b229c28f8b58@mrabarnett.plus.com> On 2024-02-24 01:14, Steve GS via Python-list wrote: > Python, Tkinter: How do I > determine if a window has been > resized? I want to locate > buttons vertically along the > right border and need to know > the new width. The buttons are > to move with the change of > location of the right-side > border. > Bind an event handler for '': ----8<---- import tkinter as tk def on_configure(*args): print(args) root = tk.Tk() root.bind('', on_configure) root.mainloop() ----8<---- Are you placing the buttons yourself? I always use layouts and they handle such things automatically. From Gronicus at SGA.Ninja Fri Feb 23 23:33:05 2024 From: Gronicus at SGA.Ninja (Steve GS) Date: Fri, 23 Feb 2024 23:33:05 -0500 Subject: Problem resizing a window and button placement In-Reply-To: <76894f6f-551c-470a-93c7-b229c28f8b58@mrabarnett.plus.com> References: <06a301da66be$bfdc0da0$3f9428e0$@SGA.Ninja> <76894f6f-551c-470a-93c7-b229c28f8b58@mrabarnett.plus.com> Message-ID: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> How do I extract the values from args? SGA -----Original Message----- From: Python-list On Behalf Of MRAB via Python-list Sent: Friday, February 23, 2024 9:27 PM To: python-list at python.org Subject: Re: Problem resizing a window and button placement On 2024-02-24 01:14, Steve GS via Python-list wrote: > Python, Tkinter: How do I > determine if a window has been > resized? I want to locate > buttons vertically along the > right border and need to know > the new width. The buttons are > to move with the change of > location of the right-side > border. > Bind an event handler for '': ----8<---- import tkinter as tk def on_configure(*args): print(args) root = tk.Tk() root.bind('', on_configure) root.mainloop() ----8<---- Are you placing the buttons yourself? I always use layouts and they handle such things automatically. -- https://mail.python.org/mailma n/listinfo/python-list From barry at barrys-emacs.org Sat Feb 24 03:04:18 2024 From: barry at barrys-emacs.org (Barry) Date: Sat, 24 Feb 2024 08:04:18 +0000 Subject: Problem resizing a window and button placement In-Reply-To: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> Message-ID: > On 24 Feb 2024, at 04:36, Steve GS via Python-list wrote: > > How do I extract the values > from args? You can look up the args in documentation. You can run the example code MRAB provided and see what is printed to learn what is in the args. Barry From Gronicus at SGA.Ninja Sat Feb 24 03:20:47 2024 From: Gronicus at SGA.Ninja (Steve GS) Date: Sat, 24 Feb 2024 03:20:47 -0500 Subject: Problem resizing a window and button placement In-Reply-To: References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> Message-ID: <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> Yes, I ran that elegantly simple code. The print statement reports the X, Y, Height and Width values. However, I do not see how to capture the width value. I experimented with the code Vwidth = rootV.winfo_width() and it also reports the width as I resize the window. However, I cannot seem to use the variable Vwidth outside the sub routine. It is acting as if Vwidth is not global but I added that. It is reported that Vwidth is not defined when I try to use it in my code. So close...... SGA -----Original Message----- From: Barry Sent: Saturday, February 24, 2024 3:04 AM To: Steve GS Cc: MRAB ; python-list at python.org Subject: Re: Problem resizing a window and button placement > On 24 Feb 2024, at 04:36, Steve GS via Python-list wrote: > > How do I extract the values > from args? You can look up the args in documentation. You can run the example code MRAB provided and see what is printed to learn what is in the args. Barry From list1 at tompassin.net Sat Feb 24 08:39:55 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 24 Feb 2024 08:39:55 -0500 Subject: Problem resizing a window and button placement In-Reply-To: <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> Message-ID: <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> On 2/24/2024 3:20 AM, Steve GS via Python-list wrote: > Yes, I ran that elegantly > simple code. The print > statement reports the X, Y, > Height and Width values. > However, I do not see how to > capture the width value. > > I experimented with the code > Vwidth = rootV.winfo_width() > and it also reports the width > as I resize the window. > > However, I cannot seem to use > the variable Vwidth outside > the sub routine. It is acting > as if Vwidth is not global but > I added that. It is reported > that Vwidth is not defined > when I try to use it in my > code. Well, yes, in Python a variable created inside a function or method is local to that function unless you declare it global. That characteristic is called its "scope". But if you think you need it to be a global variable you should rethink your design. For one thing, before the next time you use your global variable the window size may have changed again. Instead, it would be better to have the function that responds to the resize event perform the action that you want, or call another function that does, passing the new width to it. Note that in most programming languages, variables have a scope. The rules about those scopes vary between languages. > > So close...... > SGA > > -----Original Message----- > From: Barry > > Sent: Saturday, February 24, > 2024 3:04 AM > To: Steve GS > > Cc: MRAB > ; > python-list at python.org > Subject: Re: Problem resizing > a window and button placement > > > >> On 24 Feb 2024, at 04:36, > Steve GS via Python-list > > wrote: >> >> How do I extract the values >> from args? > > You can look up the args in > documentation. > You can run the example code > MRAB provided and see what is > printed to learn what is in > the args. > > Barry > > From grant.b.edwards at gmail.com Fri Feb 23 22:28:27 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 23 Feb 2024 22:28:27 -0500 (EST) Subject: Problem resizing a window and button placement References: <06a301da66be$bfdc0da0$3f9428e0$@SGA.Ninja> <76894f6f-551c-470a-93c7-b229c28f8b58@mrabarnett.plus.com> Message-ID: <4ThXQg0JvMznVG1@mail.python.org> On 2024-02-24, MRAB via Python-list wrote: > On 2024-02-24 01:14, Steve GS via Python-list wrote: > >> Python, Tkinter: How do I determine if a window has been resized? I >> want to locate buttons vertically along the right border and need >> to know the new width. The buttons are to move with the change of >> location of the right-side border. > > Bind an event handler for '': > > ----8<---- > [...] > ----8<---- > > Are you placing the buttons yourself? I always use layouts and they > handle such things automatically. Yes, definitely what he said: use a layout manager. I hope this doesn't sound rude, but if you're calculating button positions based on window size, you're doing it wrong and will end up wasting a lot of time to produce something that won't work right. Use a layout manager: https://tkinterpython.top/layout/#:~:text=Tkinter%20has%20three%20built%2Din,%2C%20grid%20%2C%20and%20place%20managers. https://www.pythonguis.com/tutorials/create-ui-with-tkinter-pack-layout-manager/ https://www.pythonguis.com/tutorials/use-tkinter-to-design-gui-layout/ You'll have to spend a little time learning how they work, but in the end you'll get done sooner and have better results. -- Grant From Gronicus at SGA.Ninja Sat Feb 24 19:33:52 2024 From: Gronicus at SGA.Ninja (Steve GS) Date: Sat, 24 Feb 2024 19:33:52 -0500 Subject: Problem resizing a window and button placement In-Reply-To: <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> Message-ID: <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> "Well, yes, in Python a variable created inside a function or method is local to that function unless you declare it global." Yes, I knew that. I tried to global it both before the function call and within it. Same for when I created the variable. If I try to use it in the rest of the code, it keeps coming up as not declared. In other functions, I can 'return' the variable but that apparently would not work for this function. Is this type of function any different that that which I have been using? SGA -----Original Message----- From: Python-list On Behalf Of Thomas Passin via Python-list Sent: Saturday, February 24, 2024 8:40 AM To: python-list at python.org Subject: Re: Problem resizing a window and button placement On 2/24/2024 3:20 AM, Steve GS via Python-list wrote: > Yes, I ran that elegantly > simple code. The print > statement reports the X, Y, > Height and Width values. > However, I do not see how to > capture the width value. > > I experimented with the code > Vwidth = rootV.winfo_width() > and it also reports the width > as I resize the window. > > However, I cannot seem to use > the variable Vwidth outside > the sub routine. It is acting > as if Vwidth is not global but > I added that. It is reported > that Vwidth is not defined > when I try to use it in my > code. Well, yes, in Python a variable created inside a function or method is local to that function unless you declare it global. That characteristic is called its "scope". But if you think you need it to be a global variable you should rethink your design. For one thing, before the next time you use your global variable the window size may have changed again. Instead, it would be better to have the function that responds to the resize event perform the action that you want, or call another function that does, passing the new width to it. Note that in most programming languages, variables have a scope. The rules about those scopes vary between languages. > > So close...... > SGA > > -----Original Message----- > From: Barry > > Sent: Saturday, February 24, > 2024 3:04 AM > To: Steve GS > > Cc: MRAB > ; > python-list at python.org > Subject: Re: Problem resizing > a window and button placement > > > >> On 24 Feb 2024, at 04:36, > Steve GS via Python-list > > wrote: >> >> How do I extract the values >> from args? > > You can look up the args in > documentation. > You can run the example code > MRAB provided and see what is > printed to learn what is in > the args. > > Barry > > -- https://mail.python.org/mailma n/listinfo/python-list From python at mrabarnett.plus.com Sat Feb 24 19:49:16 2024 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 25 Feb 2024 00:49:16 +0000 Subject: Problem resizing a window and button placement In-Reply-To: <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> Message-ID: <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> On 2024-02-25 00:33, Steve GS via Python-list wrote: > "Well, yes, in Python a > variable created inside a > function or method is local to > that function unless you > declare it global." > > Yes, I knew that. I tried to > global it both before the > function call and within it. > Same for when I created the > variable. If I try to use it > in the rest of the code, it > keeps coming up as not > declared. In other functions, > I can 'return' the variable > but that apparently would not > work for this function. > > Is this type of function any > different that that which I > have been using? > Please post a short example that shows the problem. From Gronicus at SGA.Ninja Sat Feb 24 21:51:54 2024 From: Gronicus at SGA.Ninja (Steve GS) Date: Sat, 24 Feb 2024 21:51:54 -0500 Subject: Problem resizing a window and button placement In-Reply-To: <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> Message-ID: <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> import tkinter as tk #global Ww Neither global helps def on_configure(*args): # print(args) #global Ww Neither global helps Ww = root.winfo_width() print("WwInside = <" + str(Ww) + ">") root = tk.Tk() root.bind('', on_configure) print("WwOutside = <" + str(Ww) + ">") #NameError: name 'Ww' is not defined root.mainloop() SGA -----Original Message----- From: Python-list On Behalf Of MRAB via Python-list Sent: Saturday, February 24, 2024 7:49 PM To: python-list at python.org Subject: Re: Problem resizing a window and button placement On 2024-02-25 00:33, Steve GS via Python-list wrote: > "Well, yes, in Python a > variable created inside a > function or method is local to > that function unless you > declare it global." > > Yes, I knew that. I tried to > global it both before the > function call and within it. > Same for when I created the > variable. If I try to use it > in the rest of the code, it > keeps coming up as not > declared. In other functions, > I can 'return' the variable > but that apparently would not > work for this function. > > Is this type of function any > different that that which I > have been using? > Please post a short example that shows the problem. -- https://mail.python.org/mailma n/listinfo/python-list From list1 at tompassin.net Sat Feb 24 22:38:36 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 24 Feb 2024 22:38:36 -0500 Subject: Problem resizing a window and button placement In-Reply-To: <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> Message-ID: <69d31734-4ec6-4580-bd8e-1e7ae0c301ba@tompassin.net> On 2/24/2024 9:51 PM, Steve GS via Python-list wrote: First of all, please make sure that the formatting is readable and especially the indentation. This is Python, after all. Do not use tabs; use 3 or 4 spaces instead of each tab. > import tkinter as tk > > #global Ww Neither global > helps > def on_configure(*args): > # print(args) > #global Ww Neither > global helps > Ww = root.winfo_width() > print("WwInside = <" + > str(Ww) + ">") > > root = tk.Tk() > root.bind('', > on_configure) > print("WwOutside = <" + > str(Ww) + ">") > #NameError: name 'Ww' is not > defined The function that declares Ww hasn't run yet. As I wrote earlier, the function bound to the callback should do all the work for the callback, or it should call other functions that do. That's if you don't let a layout do it all for you, as others have written. > root.mainloop() > > SGA > > -----Original Message----- > From: Python-list > sga.ninja at python.org> On > Behalf Of MRAB via Python-list > Sent: Saturday, February 24, > 2024 7:49 PM > To: python-list at python.org > Subject: Re: Problem resizing > a window and button placement > > On 2024-02-25 00:33, Steve GS > via Python-list wrote: >> "Well, yes, in Python a >> variable created inside a >> function or method is local > to >> that function unless you >> declare it global." >> >> Yes, I knew that. I tried to >> global it both before the >> function call and within it. >> Same for when I created the >> variable. If I try to use it >> in the rest of the code, it >> keeps coming up as not >> declared. In other > functions, >> I can 'return' the variable >> but that apparently would > not >> work for this function. >> >> Is this type of function any >> different that that which I >> have been using? >> > Please post a short example > that shows the problem. > From python at mrabarnett.plus.com Sat Feb 24 22:36:04 2024 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 25 Feb 2024 03:36:04 +0000 Subject: Problem resizing a window and button placement In-Reply-To: <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> Message-ID: <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> On 2024-02-25 02:51, Steve GS wrote: > import tkinter as tk > > #global Ww Neither global helps > def on_configure(*args): > # print(args) > #global Ww Neither global helps > Ww = root.winfo_width() > print("WwInside = <" + str(Ww) + ">") > > root = tk.Tk() > root.bind('', on_configure) > print("WwOutside = <" + str(Ww) + ">") > #NameError: name 'Ww' is not defined > root.mainloop() 'Ww' won't exist until 'on_configure' assigns to it, and that won't happen until `mainloop` starts. Also, 'global' works only within a function. ----8<---- import tkinter as tk def on_configure(event): ??? print(f'{event.width=}, {event.height=}') root = tk.Tk() root.bind('',on_configure) root.mainloop() ----8<---- From Gronicus at SGA.Ninja Sat Feb 24 22:53:40 2024 From: Gronicus at SGA.Ninja (Steve GS) Date: Sat, 24 Feb 2024 22:53:40 -0500 Subject: Problem resizing a window and button placement In-Reply-To: <69d31734-4ec6-4580-bd8e-1e7ae0c301ba@tompassin.net> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <69d31734-4ec6-4580-bd8e-1e7ae0c301ba@tompassin.net> Message-ID: <07c401da679e$38c94860$aa5bd920$@SGA.Ninja> The print statement in the function prints. Does that not mean that the function is being called? SGA -----Original Message----- From: Python-list On Behalf Of Thomas Passin via Python-list Sent: Saturday, February 24, 2024 10:39 PM To: python-list at python.org Subject: Re: Problem resizing a window and button placement On 2/24/2024 9:51 PM, Steve GS via Python-list wrote: First of all, please make sure that the formatting is readable and especially the indentation. This is Python, after all. Do not use tabs; use 3 or 4 spaces instead of each tab. > import tkinter as tk > > #global Ww Neither global > helps > def on_configure(*args): > # print(args) > #global Ww Neither > global helps > Ww = root.winfo_width() > print("WwInside = <" + > str(Ww) + ">") > > root = tk.Tk() > root.bind('', > on_configure) > print("WwOutside = <" + > str(Ww) + ">") > #NameError: name 'Ww' is not > defined The function that declares Ww hasn't run yet. As I wrote earlier, the function bound to the callback should do all the work for the callback, or it should call other functions that do. That's if you don't let a layout do it all for you, as others have written. > root.mainloop() > > SGA > > -----Original Message----- > From: Python-list > sga.ninja at python.org> On > Behalf Of MRAB via Python-list > Sent: Saturday, February 24, > 2024 7:49 PM > To: python-list at python.org > Subject: Re: Problem resizing > a window and button placement > > On 2024-02-25 00:33, Steve GS > via Python-list wrote: >> "Well, yes, in Python a >> variable created inside a >> function or method is local > to >> that function unless you >> declare it global." >> >> Yes, I knew that. I tried to >> global it both before the >> function call and within it. >> Same for when I created the >> variable. If I try to use it >> in the rest of the code, it >> keeps coming up as not >> declared. In other > functions, >> I can 'return' the variable >> but that apparently would > not >> work for this function. >> >> Is this type of function any >> different that that which I >> have been using? >> > Please post a short example > that shows the problem. > -- https://mail.python.org/mailma n/listinfo/python-list From Gronicus at SGA.Ninja Sat Feb 24 22:58:00 2024 From: Gronicus at SGA.Ninja (Steve GS) Date: Sat, 24 Feb 2024 22:58:00 -0500 Subject: Problem resizing a window and button placement In-Reply-To: <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> Message-ID: <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> So, how do I use the width value in my code? SGA -----Original Message----- From: Python-list On Behalf Of MRAB via Python-list Sent: Saturday, February 24, 2024 10:36 PM To: python-list at python.org Subject: Re: Problem resizing a window and button placement On 2024-02-25 02:51, Steve GS wrote: > import tkinter as tk > > #global Ww Neither global helps > def on_configure(*args): > # print(args) > #global Ww Neither global helps > Ww = root.winfo_width() > print("WwInside = <" + str(Ww) + ">") > > root = tk.Tk() > root.bind('', on_configure) print("WwOutside = <" + str(Ww) > + ">") > #NameError: name 'Ww' is not defined > root.mainloop() 'Ww' won't exist until 'on_configure' assigns to it, and that won't happen until `mainloop` starts. Also, 'global' works only within a function. ----8<---- import tkinter as tk def on_configure(event): print(f'{event.width=}, {event.height=}') root = tk.Tk() root.bind('',on_configure) root.mainloop() ----8<---- -- https://mail.python.org/mailman/listinfo/python-list From learn2program at gmail.com Sun Feb 25 12:44:05 2024 From: learn2program at gmail.com (Alan Gauld) Date: Sun, 25 Feb 2024 17:44:05 +0000 Subject: Problem resizing a window and button placement In-Reply-To: <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> Message-ID: On 25/02/2024 03:58, Steve GS via Python-list wrote: import tkinter as tk Ww = None def on_configure(*args): global Ww Ww = root.winfo_width() print("Ww Inside = <" + str(Ww) + ">") root = tk.Tk() root.bind('', on_configure) root.mainloop() print("Ww Outside = <" + str(Ww) > + ">") Produces: Ww Inside = <200> Ww Inside = <200> Ww Inside = <205> Ww Inside = <205> Ww Inside = <206> Ww Inside = <206> Ww Outside = <206> HTH -- 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 Gronicus at SGA.Ninja Sun Feb 25 16:19:57 2024 From: Gronicus at SGA.Ninja (Steve GS) Date: Sun, 25 Feb 2024 16:19:57 -0500 Subject: Problem resizing a window and button placement In-Reply-To: References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> Message-ID: <083301da6830$63224480$2966cd80$@SGA.Ninja> SOLUTION FOUND! The fix was to write the code that uses the width value and to place it into the function itself. Kluge? Maybe but it works. Mischief Managed. ======================== As for the most recent suggestion, it fails for me: Traceback (most recent call last): File "F:/___zInsulin Code A 08-02-23/WinPic/IOWw.pyw", line 14, in print("Ww Outside = <" + str(Ww) > + ">") TypeError: bad operand type for unary +: 'str' With the need to close the window, it adds an extra step and intervention to the program to use. I am not sure how this help[s. As a curio, it would be interesting to see how to use the value of a variable, created in the function used here, and make it available to the code outside the function. SGA -----Original Message----- From: Alan Gauld Sent: Sunday, February 25, 2024 12:44 PM To: Steve GS ; python-list at python.org Subject: Re: RE: Problem resizing a window and button placement On 25/02/2024 03:58, Steve GS via Python-list wrote: import tkinter as tk Ww = None def on_configure(*args): global Ww Ww = root.winfo_width() print("Ww Inside = <" + str(Ww) + ">") root = tk.Tk() root.bind('', on_configure) root.mainloop() print("Ww Outside = <" + str(Ww) > + ">") Produces: Ww Inside = <200> Ww Inside = <200> Ww Inside = <205> Ww Inside = <205> Ww Inside = <206> Ww Inside = <206> Ww Outside = <206> HTH -- 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 list1 at tompassin.net Sun Feb 25 17:55:12 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 25 Feb 2024 17:55:12 -0500 Subject: Problem resizing a window and button placement In-Reply-To: <083301da6830$63224480$2966cd80$@SGA.Ninja> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> <083301da6830$63224480$2966cd80$@SGA.Ninja> Message-ID: On 2/25/2024 4:19 PM, Steve GS via Python-list wrote: > SOLUTION FOUND! > > The fix was to write the code that uses the width value and to place it into the function itself. > Kluge? Maybe but it works. Right, just what I wrote earlier: "have the function that responds to the resize event perform the action that you want" > Mischief Managed. > > ======================== > As for the most recent suggestion, it fails for me: > > Traceback (most recent call last): > File "F:/___zInsulin Code A 08-02-23/WinPic/IOWw.pyw", line 14, in > print("Ww Outside = <" + str(Ww) > + ">") > TypeError: bad operand type for unary +: 'str' > > With the need to close the window, it adds an extra step and intervention to the program to use. I am not sure how this help[s. > > As a curio, it would be interesting to see how to use the value of a variable, created in the function used here, and make it available to the code outside the function. > > > > SGA > > -----Original Message----- > From: Alan Gauld > Sent: Sunday, February 25, 2024 12:44 PM > To: Steve GS ; python-list at python.org > Subject: Re: RE: Problem resizing a window and button placement > > On 25/02/2024 03:58, Steve GS via Python-list wrote: > import tkinter as tk > > Ww = None > > def on_configure(*args): > global Ww > Ww = root.winfo_width() > print("Ww Inside = <" + str(Ww) + ">") > > root = tk.Tk() > root.bind('', on_configure) > root.mainloop() > > print("Ww Outside = <" + str(Ww) > + ">") > > Produces: > Ww Inside = <200> > Ww Inside = <200> > Ww Inside = <205> > Ww Inside = <205> > Ww Inside = <206> > Ww Inside = <206> > Ww Outside = <206> > > HTH > From python at mrabarnett.plus.com Sun Feb 25 18:40:20 2024 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 25 Feb 2024 23:40:20 +0000 Subject: Problem resizing a window and button placement In-Reply-To: <083301da6830$63224480$2966cd80$@SGA.Ninja> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> <083301da6830$63224480$2966cd80$@SGA.Ninja> Message-ID: On 2024-02-25 21:19, Steve GS via Python-list wrote: > SOLUTION FOUND! > > The fix was to write the code that uses the width value and to place it into the function itself. > Kluge? Maybe but it works. > > Mischief Managed. > > ======================== > As for the most recent suggestion, it fails for me: > > Traceback (most recent call last): > File "F:/___zInsulin Code A 08-02-23/WinPic/IOWw.pyw", line 14, in > print("Ww Outside = <" + str(Ww) > + ">") > TypeError: bad operand type for unary +: 'str' > It fails because there's a mistake. It should be: print("Ww Outside = <" + str(Ww) + ">") > With the need to close the window, it adds an extra step and intervention to the program to use. I am not sure how this help[s. > > As a curio, it would be interesting to see how to use the value of a variable, created in the function used here, and make it available to the code outside the function. > [snip] From Gronicus at SGA.Ninja Mon Feb 26 02:56:35 2024 From: Gronicus at SGA.Ninja (Steve GS) Date: Mon, 26 Feb 2024 02:56:35 -0500 Subject: Problem resizing a window and button placement In-Reply-To: References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> <083301da6830$63224480$2966cd80$@SGA.Ninja> Message-ID: <087801da6889$52395bf0$f6ac13d0$@SGA.Ninja> Musta misstit.... I had thought of that before I started the discussion but figured it would take more code than it finally needed. I guess I was also variable-dependent thinking that I would need the result elsewhere in the code. So far, I see that I don't need the value. Then there is that discovery element: Why is my original idea not working? I still cannot pass the value back from the function. What is different about this function that others would have given me the value? SGA -----Original Message----- From: Python-list On Behalf Of Thomas Passin via Python-list Sent: Sunday, February 25, 2024 5:55 PM To: python-list at python.org Subject: Re: Problem resizing a window and button placement On 2/25/2024 4:19 PM, Steve GS via Python-list wrote: > SOLUTION FOUND! > > The fix was to write the code that uses the width value and to place it into the function itself. > Kluge? Maybe but it works. Right, just what I wrote earlier: "have the function that responds to the resize event perform the action that you want" > Mischief Managed. > > ======================== > As for the most recent suggestion, it fails for me: > > Traceback (most recent call last): > File "F:/___zInsulin Code A 08-02-23/WinPic/IOWw.pyw", line 14, in > print("Ww Outside = <" + str(Ww) > + ">") > TypeError: bad operand type for unary +: 'str' > > With the need to close the window, it adds an extra step and intervention to the program to use. I am not sure how this help[s. > > As a curio, it would be interesting to see how to use the value of a variable, created in the function used here, and make it available to the code outside the function. > > > > SGA > > -----Original Message----- > From: Alan Gauld > Sent: Sunday, February 25, 2024 12:44 PM > To: Steve GS ; python-list at python.org > Subject: Re: RE: Problem resizing a window and button placement > > On 25/02/2024 03:58, Steve GS via Python-list wrote: > import tkinter as tk > > Ww = None > > def on_configure(*args): > global Ww > Ww = root.winfo_width() > print("Ww Inside = <" + str(Ww) + ">") > > root = tk.Tk() > root.bind('', on_configure) > root.mainloop() > > print("Ww Outside = <" + str(Ww) > + ">") > > Produces: > Ww Inside = <200> > Ww Inside = <200> > Ww Inside = <205> > Ww Inside = <205> > Ww Inside = <206> > Ww Inside = <206> > Ww Outside = <206> > > HTH > -- https://mail.python.org/mailma n/listinfo/python-list From Gronicus at SGA.Ninja Mon Feb 26 02:56:35 2024 From: Gronicus at SGA.Ninja (Steve GS) Date: Mon, 26 Feb 2024 02:56:35 -0500 Subject: Problem resizing a window and button placement In-Reply-To: References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> <083301da6830$63224480$2966cd80$@SGA.Ninja> Message-ID: <087b01da6889$528c8500$f7a58f00$@SGA.Ninja> Ww Inside = <250> Ww Inside = <249> Ww Inside = <250> Ww Outside = <1770662408256on_configure> Here is my result... SGA -----Original Message----- From: Python-list On Behalf Of MRAB via Python-list Sent: Sunday, February 25, 2024 6:40 PM To: python-list at python.org Subject: Re: Problem resizing a window and button placement On 2024-02-25 21:19, Steve GS via Python-list wrote: > SOLUTION FOUND! > > The fix was to write the code that uses the width value and to place it into the function itself. > Kluge? Maybe but it works. > > Mischief Managed. > > ======================== > As for the most recent suggestion, it fails for me: > > Traceback (most recent call last): > File "F:/___zInsulin Code A 08-02-23/WinPic/IOWw.pyw", line 14, in > print("Ww Outside = <" + str(Ww) > + ">") > TypeError: bad operand type for unary +: 'str' > It fails because there's a mistake. It should be: print("Ww Outside = <" + str(Ww) + ">") > With the need to close the window, it adds an extra step and intervention to the program to use. I am not sure how this help[s. > > As a curio, it would be interesting to see how to use the value of a variable, created in the function used here, and make it available to the code outside the function. > [snip] -- https://mail.python.org/mailma n/listinfo/python-list From learn2program at gmail.com Mon Feb 26 04:03:57 2024 From: learn2program at gmail.com (Alan Gauld) Date: Mon, 26 Feb 2024 09:03:57 +0000 Subject: Problem resizing a window and button placement In-Reply-To: <087801da6889$52395bf0$f6ac13d0$@SGA.Ninja> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> <083301da6830$63224480$2966cd80$@SGA.Ninja> <087801da6889$52395bf0$f6ac13d0$@SGA.Ninja> Message-ID: <1b58d259-699f-dd89-581b-3eecbc4c3e07@yahoo.co.uk> On 26/02/2024 07:56, Steve GS via Python-list wrote: > Then there is that discovery > element: Why is my original > idea not working? I still > cannot pass the value back > from the function. What is > different about this function > that others would have given > me the value? There is nothing different, see the code below. print() is a function like any other. In this case it is called after you close the window, ie after mainloop() exits. But any other function called inside mainloop - eg any other event handler can also access it. For example, if you added a button: def printW(): print("Button Ww = ", Ww) bw = tk.Button(root, text="Print Width", command=printW) bw.pack() You would be able to print the value on demand. >> import tkinter as tk >> >> Ww = None >> >> def on_configure(*args): >> global Ww >> Ww = root.winfo_width() >> print("Ww Inside =<"+str(Ww)+">") >> >> root = tk.Tk() >> root.bind('',on_configure) >> root.mainloop() >> >> print("Ww Outside = <"+str(Ww)+">") -- 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 Gronicus at SGA.Ninja Mon Feb 26 06:02:59 2024 From: Gronicus at SGA.Ninja (Steve GS) Date: Mon, 26 Feb 2024 06:02:59 -0500 Subject: Problem resizing a window and button placement In-Reply-To: <1b58d259-699f-dd89-581b-3eecbc4c3e07@yahoo.co.uk> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> <083301da6830$63224480$2966cd80$@SGA.Ninja> <087801da6889$52395bf0$f6ac13d0$@SGA.Ninja> <1b58d259-699f-dd89-581b-3eecbc4c3e07@yahoo.co.uk> Message-ID: <000001da68a3$5cf1a830$16d4f890$@SGA.Ninja> Although your code produces the value of Ww outside the function, I do not see how I can use the value of Ww unless I close the program. import tkinter as tk Ww = None # What does this do? Why not Integer? WwZ = None def on_configure(*args): global Ww global WwZ Ww = root.winfo_width() print("9 Ww Inside =<"+str(Ww)+">") # works WwZ = Ww * 2 print("11 WwZ Inside =<"+str(WwZ)+">") # works return(Ww) #Can I use this? root = tk.Tk() root.bind('',on_configure) print("15 Ww Inside1 = <"+str(Ww)+">") #Ww2 = int(Ww) * 2 # fails print("17 WwZ Inside2 = <"+str(WwZ)+">") root.mainloop() Ww2 = int(Ww) * 2 #Works but only after the program stops print("21 Ww Outside2 = <"+str(WwZ)+">") # Can I have concentric loops? SGA -----Original Message----- From: Alan Gauld Sent: Monday, February 26, 2024 4:04 AM To: Steve GS ; python-list at python.org Subject: Re: RE: Problem resizing a window and button placement On 26/02/2024 07:56, Steve GS via Python-list wrote: > Then there is that discovery > element: Why is my original > idea not working? I still > cannot pass the value back > from the function. What is > different about this function > that others would have given > me the value? There is nothing different, see the code below. print() is a function like any other. In this case it is called after you close the window, ie after mainloop() exits. But any other function called inside mainloop - eg any other event handler can also access it. For example, if you added a button: def printW(): print("Button Ww = ", Ww) bw = tk.Button(root, text="Print Width", command=printW) bw.pack() You would be able to print the value on demand. >> import tkinter as tk >> >> Ww = None >> >> def on_configure(*args): >> global Ww >> Ww = root.winfo_width() >> print("Ww Inside =<"+str(Ww)+">") >> >> root = tk.Tk() >> root.bind('',on_configure) >> root.mainloop() >> >> print("Ww Outside = <"+str(Ww)+">") -- 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 learn2program at gmail.com Mon Feb 26 07:04:26 2024 From: learn2program at gmail.com (Alan Gauld) Date: Mon, 26 Feb 2024 12:04:26 +0000 Subject: Problem resizing a window and button placement In-Reply-To: <000001da68a3$5cf1a830$16d4f890$@SGA.Ninja> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> <083301da6830$63224480$2966cd80$@SGA.Ninja> <087801da6889$52395bf0$f6ac13d0$@SGA.Ninja> <1b58d259-699f-dd89-581b-3eecbc4c3e07@yahoo.co.uk> <000001da68a3$5cf1a830$16d4f890$@SGA.Ninja> Message-ID: <40f594fc-6adc-e97b-65ad-24e548142190@yahoo.co.uk> On 26/02/2024 11:02, Steve GS via Python-list wrote: > Although your code produces the value of Ww outside the function, > I do not see how I can use the value of Ww unless I close the program. You have to use a function that operates inside the mainloop. Thats the nature of event driven programs, all activity happens inside the mainloop except initialisation and cleanup. So you need to create an event handler as I described below. Here is the complete program including the button: ########################### import tkinter as tk Ww=None def on_configure(*args): global Ww Ww = root.winfo_width() print("Ww Inside = <" + str(Ww) + ">") def printW(): print("Button Ww = ", Ww) root = tk.Tk() bw = tk.Button(root, text="Print Width", command=printW) bw.pack() root.bind('', on_configure) root.mainloop() print("Ww Outside = <" + str(Ww) + ">") ############################ Notice that the button callback picks up the latest value of Ww. -- 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 list1 at tompassin.net Mon Feb 26 08:34:19 2024 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 26 Feb 2024 08:34:19 -0500 Subject: Problem resizing a window and button placement In-Reply-To: <000001da68a3$5cf1a830$16d4f890$@SGA.Ninja> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> <083301da6830$63224480$2966cd80$@SGA.Ninja> <087801da6889$52395bf0$f6ac13d0$@SGA.Ninja> <1b58d259-699f-dd89-581b-3eecbc4c3e07@yahoo.co.uk> <000001da68a3$5cf1a830$16d4f890$@SGA.Ninja> Message-ID: <97753bba-606f-4cac-a48f-64da2db80e65@tompassin.net> On 2/26/2024 6:02 AM, Steve GS via Python-list wrote: > Although your code produces the value of Ww outside the function, I do not see how I can use the value of Ww unless I close the program. The configuration event hasn't fired at the time you include the print statement in the handler's def block, and therefore the print function inside your handler hasn't invoked. It won't be invoked until you resize the window. There is no point to saving the width and height outside your on_configure() function, because outside that function you can't know if they have been changed. There could even have been a race condition where you use one but the other changes before you get around to using it. It's better just to ask tk for the values whenever you need them, as you do inside your handler. > import tkinter as tk > > Ww = None # What does this do? Why not Integer? > WwZ = None # These could be integers, like 0, but that would not be the correct # window sizes at that point. The window is either not constructed or it # has some definite size that is not zero. > def on_configure(*args): > global Ww > global WwZ > Ww = root.winfo_width() > print("9 Ww Inside =<"+str(Ww)+">") # works > WwZ = Ww * 2 > print("11 WwZ Inside =<"+str(WwZ)+">") # works > return(Ww) #Can I use this? > > root = tk.Tk() > root.bind('',on_configure) > print("15 Ww Inside1 = <"+str(Ww)+">") > #Ww2 = int(Ww) * 2 # fails > print("17 WwZ Inside2 = <"+str(WwZ)+">") > > root.mainloop() > > Ww2 = int(Ww) * 2 #Works but only after the program stops > print("21 Ww Outside2 = <"+str(WwZ)+">") > # Can I have concentric loops? > > > SGA > > -----Original Message----- > From: Alan Gauld > Sent: Monday, February 26, 2024 4:04 AM > To: Steve GS ; python-list at python.org > Subject: Re: RE: Problem resizing a window and button placement > > On 26/02/2024 07:56, Steve GS via Python-list wrote: > >> Then there is that discovery >> element: Why is my original >> idea not working? I still >> cannot pass the value back >> from the function. What is >> different about this function >> that others would have given >> me the value? > > There is nothing different, see the code below. > print() is a function like any other. > In this case it is called after you close the window, ie after mainloop() exits. > But any other function called inside > mainloop - eg any other event handler can also access it. > > For example, if you added a button: > > def printW(): print("Button Ww = ", Ww) > > bw = tk.Button(root, text="Print Width", command=printW) > bw.pack() > > You would be able to print the value on demand. > >>> import tkinter as tk >>> >>> Ww = None >>> >>> def on_configure(*args): >>> global Ww >>> Ww = root.winfo_width() >>> print("Ww Inside =<"+str(Ww)+">") >>> >>> root = tk.Tk() >>> root.bind('',on_configure) >>> root.mainloop() >>> >>> print("Ww Outside = <"+str(Ww)+">") > > -- > 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 Gronicus at SGA.Ninja Tue Feb 27 02:13:19 2024 From: Gronicus at SGA.Ninja (Steve GS) Date: Tue, 27 Feb 2024 02:13:19 -0500 Subject: Problem resizing a window and button placement In-Reply-To: <97753bba-606f-4cac-a48f-64da2db80e65@tompassin.net> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> <083301da6830$63224480$2966cd80$@SGA.Ninja> <087801da6889$52395bf0$f6ac13d0$@SGA.Ninja> <1b58d259-699f-dd89-581b-3eecbc4c3e07@yahoo.co.uk> <000001da68a3$5cf1a830$16d4f890$@SGA.Ninja> <97753bba-606f-4cac-a48f-64da2db80e65@tompassin.net> Message-ID: <00c101da694c$71914df0$54b3e9d0$@SGA.Ninja> >> The configuration event hasn't fired at the time you include the print statement in the handler's def block, and therefore the print function inside your handler hasn't invoked. It won't be invoked until you resize the window. Exactly.... >> There is no point (really?) to saving the width and height outside your on_configure() function, because outside that function you can't know if they have been changed. There could even have been a race condition where you use one but the other changes before you get around to using it. Aside from using it to resized the window, is there no way to know the last value of the change for use in the program? I could write the value to a label and read it back later in the process but that sounds to be klugy. >> It's better just to ask tk for the values whenever you need them, as you do inside your handler. How would that be done? SGA -----Original Message----- From: Python-list On Behalf Of Thomas Passin via Python-list Sent: Monday, February 26, 2024 8:34 AM To: python-list at python.org Subject: Re: Problem resizing a window and button placement On 2/26/2024 6:02 AM, Steve GS via Python-list wrote: > Although your code produces the value of Ww outside the function, I do not see how I can use the value of Ww unless I close the program. The configuration event hasn't fired at the time you include the print statement in the handler's def block, and therefore the print function inside your handler hasn't invoked. It won't be invoked until you resize the window. There is no point to saving the width and height outside your on_configure() function, because outside that function you can't know if they have been changed. There could even have been a race condition where you use one but the other changes before you get around to using it. It's better just to ask tk for the values whenever you need them, as you do inside your handler. > import tkinter as tk > > Ww = None # What does this do? Why not Integer? > WwZ = None # These could be integers, like 0, but that would not be the correct # window sizes at that point. The window is either not constructed or it # has some definite size that is not zero. > def on_configure(*args): > global Ww > global WwZ > Ww = root.winfo_width() > print("9 Ww Inside =<"+str(Ww)+">") # works > WwZ = Ww * 2 > print("11 WwZ Inside =<"+str(WwZ)+">") # works > return(Ww) #Can I use this? > > root = tk.Tk() > root.bind('',on_con figure) > print("15 Ww Inside1 = <"+str(Ww)+">") > #Ww2 = int(Ww) * 2 # fails > print("17 WwZ Inside2 = <"+str(WwZ)+">") > > root.mainloop() > > Ww2 = int(Ww) * 2 #Works but only after the program stops > print("21 Ww Outside2 = <"+str(WwZ)+">") # Can I have concentric > loops? > > > SGA > > -----Original Message----- > From: Alan Gauld > Sent: Monday, February 26, 2024 4:04 AM > To: Steve GS ; python-list at python.org > Subject: Re: RE: Problem resizing a window and button placement > > On 26/02/2024 07:56, Steve GS via Python-list wrote: > >> Then there is that discovery >> element: Why is my original >> idea not working? I still >> cannot pass the value back >> from the function. What is >> different about this function >> that others would have given >> me the value? > > There is nothing different, see the code below. > print() is a function like any other. > In this case it is called after you close the window, ie after mainloop() exits. > But any other function called inside > mainloop - eg any other event handler can also access it. > > For example, if you added a button: > > def printW(): print("Button Ww = ", Ww) > > bw = tk.Button(root, text="Print Width", command=printW) > bw.pack() > > You would be able to print the value on demand. > >>> import tkinter as tk >>> >>> Ww = None >>> >>> def on_configure(*args): >>> global Ww >>> Ww = root.winfo_width() >>> print("Ww Inside =<"+str(Ww)+">") >>> >>> root = tk.Tk() >>> root.bind('',on_con figure) >>> root.mainloop() >>> >>> print("Ww Outside = <"+str(Ww)+">") > > -- > Alan G > Author of the Learn to Program web site http://www.alan-g.me.uk/ > http://www.amazon.com/author/a lan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/a langauldphotos > > -- https://mail.python.org/mailma n/listinfo/python-list From learn2program at gmail.com Tue Feb 27 07:15:14 2024 From: learn2program at gmail.com (Alan Gauld) Date: Tue, 27 Feb 2024 12:15:14 +0000 Subject: Problem resizing a window and button placement In-Reply-To: <00c101da694c$71914df0$54b3e9d0$@SGA.Ninja> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> <083301da6830$63224480$2966cd80$@SGA.Ninja> <087801da6889$52395bf0$f6ac13d0$@SGA.Ninja> <1b58d259-699f-dd89-581b-3eecbc4c3e07@yahoo.co.uk> <000001da68a3$5cf1a830$16d4f890$@SGA.Ninja> <97753bba-606f-4cac-a48f-64da2db80e65@tompassin.net> <00c101da694c$71914df0$54b3e9d0$@SGA.Ninja> Message-ID: <69c809f5-e30c-10f5-5fa1-a623f9647ec5@yahoo.co.uk> On 27/02/2024 07:13, Steve GS via Python-list wrote: > Aside from using it to resized > the window, is there no way to > know the last value of the > change for use in the program? The last value would be the current width. And you know how to get that as shown in your configure function: Ww = root.winfo_width() > I could write the value to a > label and read it back later That's no different to writing it to global Ww and accessing that as demonstrated in my last code post (with button). >>> It's better just to ask tk > for the values whenever you > need them, as you do inside > your handler. > > How would that be done? Ww = root.winfo_width() Provided you can access the root widget (which is (nearly?) always true) you can get the width of the main window. But can I ask if you have a particular use-case in mind for this? We started out talking about relocating some widgets when the window was resized. We established that the best place to do that was inside the configure event handler, with no need to store the width. (assuming you aren't using a dynamic layout manager(grid/pack/form) which would be better still!) We've now moved on to the more general issue of communicating values between event handlers (although still using the width as our exemplar). Is this just academic interest or do you have a specific need for this? If we know the need we might be able to suggest a specific (and possibly better?)solution. -- 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 greg.ewing at canterbury.ac.nz Tue Feb 27 23:29:54 2024 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 28 Feb 2024 17:29:54 +1300 Subject: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought In-Reply-To: References: Message-ID: On 26/02/24 12:45 pm, Lawrence D'Oliveiro wrote: > def score(candidate, answer) : > return \ > ( > sum(a == b for a, b in zip(candidate, answer)), > sum > ( > i != j and a == b > for i, a in enumerate(candidate) > for j, b in enumerate(answer) > ) > ) This is not correct. score((1,1,1), (1,1,2)) gives (2,4). According to the usual rules of Mastermind, it should be (2, 0). -- Greg From Gronicus at SGA.Ninja Wed Feb 28 03:01:21 2024 From: Gronicus at SGA.Ninja (Steve GS) Date: Wed, 28 Feb 2024 03:01:21 -0500 Subject: Transparent label background? In-Reply-To: <00c101da694c$71914df0$54b3e9d0$@SGA.Ninja> References: <06f101da66da$902357f0$b06a07d0$@SGA.Ninja> <070d01da66fa$5faea870$1f0bf950$@SGA.Ninja> <31caf694-99fd-41ca-a98c-cb0d5d4a758e@tompassin.net> <077801da6782$4f6046d0$ee20d470$@SGA.Ninja> <13edcbad-1914-424c-97aa-3679eaf77fd8@mrabarnett.plus.com> <07b101da6795$97d57df0$c78079d0$@SGA.Ninja> <5d93173f-b172-408a-a052-c670214581b2@mrabarnett.plus.com> <07c701da679e$d3a8a6f0$7af9f4d0$@SGA.Ninja> <083301da6830$63224480$2966cd80$@SGA.Ninja> <087801da6889$52395bf0$f6ac13d0$@SGA.Ninja> <1b58d259-699f-dd89-581b-3eecbc4c3e07@yahoo.co.uk> <000001da68a3$5cf1a830$16d4f890$@SGA.Ninja> <97753bba-606f-4cac-a48f-64da2db80e65@tompassin.net> <00c101da694c$71914df0$54b3e9d0$@SGA.Ninja> Message-ID: <000c01da6a1c$518b6790$f4a236b0$@SGA.Ninja> My window is to have a label over an image. How do I place a label that has a transparent background so as to not have the square of the label look so obnoxious? SGA From phd at phdru.name Wed Feb 28 10:40:08 2024 From: phd at phdru.name (Oleg Broytman) Date: Wed, 28 Feb 2024 18:40:08 +0300 Subject: Cheetah 3.3.3.post1 Message-ID: Hello! I'm pleased to announce version 3.3.3.post1, the first post-release of release 3.3.3 of branch 3.3 of CheetahTemplate3. What's new in CheetahTemplate3 ============================== CI: - GHActions: Build and publish wheels on Linux/aarch64. What is CheetahTemplate3 ======================== Cheetah3 is a free and open source (MIT) Python template engine. It's a fork of the original CheetahTemplate library. Python 2.7 or 3.4+ is required. Where is CheetahTemplate3 ========================= Site: https://cheetahtemplate.org/ Download: https://pypi.org/project/CT3/3.3.3.post1 News and changes: https://cheetahtemplate.org/news.html StackOverflow: https://stackoverflow.com/questions/tagged/cheetah Mailing lists: https://sourceforge.net/p/cheetahtemplate/mailman/ Development: https://github.com/CheetahTemplate3 Developer Guide: https://cheetahtemplate.org/dev_guide/ Example ======= Install:: $ pip install CT3 # (or even "ct3") Below is a simple example of some Cheetah code, as you can see it's practically Python. You can import, inherit and define methods just like in a regular Python module, since that's what your Cheetah templates are compiled to :) :: #from Cheetah.Template import Template #extends Template #set $people = [{'name' : 'Tom', 'mood' : 'Happy'}, {'name' : 'Dick', 'mood' : 'Sad'}, {'name' : 'Harry', 'mood' : 'Hairy'}] How are you feeling?
    #for $person in $people
  • $person['name'] is $person['mood']
  • #end for
Oleg. -- Oleg Broytman https://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN.