From simon+python at bleah.co.uk Wed Mar 1 05:55:09 2023 From: simon+python at bleah.co.uk (Simon Ward) Date: Wed, 1 Mar 2023 10:55:09 +0000 Subject: Python 3.10 Fizzbuzz In-Reply-To: <00ef01d94bb8$5d71e030$1855a090$@gmail.com> References: <87v8qaxyna.fsf@nightsong.com> <749b4375-9dd4-99e1-19bc-dbc90fc068bc@btinternet.com> <14355d71-81af-422b-9d80-68768cd9bb2e@DancesWithMice.info> <00ef01d94bb8$5d71e030$1855a090$@gmail.com> Message-ID: <20230301105509.GA24525@bleah.co.uk> On Tue, Feb 28, 2023 at 04:05:19PM -0500, avi.e.gross at gmail.com wrote: >Is it rude to name something "black" to make it hard for some of us to >remind them of the rules or claim that our personal style is so often >the opposite that it should be called "white" or at least shade of >gray? > >The usual kidding aside, I have no idea what it was called black but in >all seriousness this is not a black and white issue. Opinions may >differ when a language provides many valid options on how to write >code. If someone wants to standardize and impose some decisions, fine. >But other may choose their own variant and take their chances. https://pypi.org/project/grey/ https://pypi.org/project/white/ https://pypi.org/project/blue/ https://pypi.org/project/oitnb/ :o It amuses me that opinionated formatter, with very little configurability by design, in the face of differing opinions just results in forks or wrappers that modify the behaviours that might otherwise have been configuration options. Simon From jon+usenet at unequivocal.eu Wed Mar 1 06:47:32 2023 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 1 Mar 2023 11:47:32 -0000 (UTC) Subject: Python 3.10 Fizzbuzz References: <87v8qaxyna.fsf@nightsong.com> <749b4375-9dd4-99e1-19bc-dbc90fc068bc@btinternet.com> <14355d71-81af-422b-9d80-68768cd9bb2e@DancesWithMice.info> <00ef01d94bb8$5d71e030$1855a090$@gmail.com> <20230301105509.GA24525@bleah.co.uk> Message-ID: On 2023-03-01, Simon Ward wrote: > On Tue, Feb 28, 2023 at 04:05:19PM -0500, avi.e.gross at gmail.com wrote: >>Is it rude to name something "black" to make it hard for some of us to >>remind them of the rules or claim that our personal style is so often >>the opposite that it should be called "white" or at least shade of >>gray? >> >>The usual kidding aside, I have no idea what it was called black but in >>all seriousness this is not a black and white issue. Opinions may >>differ when a language provides many valid options on how to write >>code. If someone wants to standardize and impose some decisions, fine. >>But other may choose their own variant and take their chances. > > https://pypi.org/project/grey/ > https://pypi.org/project/white/ > https://pypi.org/project/blue/ > https://pypi.org/project/oitnb/ > >:o > > It amuses me that opinionated formatter, with very little > configurability by design, in the face of differing opinions just > results in forks or wrappers that modify the behaviours that might > otherwise have been configuration options. The mysterious bit is that two of the above projects do nothing except change the default of the one configuration option that *does* exist (line length). I mean, "black"'s line-length choice of 88 is insane, but I don't see the point of creating new pypi projects that do nothing except run another project with a single option set! From bowman at montana.com Wed Mar 1 08:58:33 2023 From: bowman at montana.com (rbowman) Date: 1 Mar 2023 13:58:33 GMT Subject: Python 3.10 Fizzbuzz References: <87v8qaxyna.fsf@nightsong.com> <749b4375-9dd4-99e1-19bc-dbc90fc068bc@btinternet.com> <14355d71-81af-422b-9d80-68768cd9bb2e@DancesWithMice.info> <00ef01d94bb8$5d71e030$1855a090$@gmail.com> <20230301105509.GA24525@bleah.co.uk> Message-ID: On 1 Mar 2023 11:28:12 GMT, Stefan Ram wrote: > IIRC, I've heard of professional video monitors which are set to > standard values for color saturation, contrast, and brightness. They > have no way to adjust these values, although they are more expensive > than normal screens. Probably a good thing. In the early days of color TV the color values were user adjustable. A generation grew up thinking Lorne Greene (Bonanza) had a slightly green complexion to match his name. From serignan.famille29 at gmail.com Wed Mar 1 11:05:47 2023 From: serignan.famille29 at gmail.com (Tom) Date: Wed, 1 Mar 2023 17:05:47 +0100 Subject: pls donate acces Message-ID: <23F52E96-938D-4451-907C-BB33D619FBF4@hxcore.ol> I need make an scrpit to impressive my friends ? Envoy? ? partir de [1]Courrier pour Windows ? References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From grant.b.edwards at gmail.com Wed Mar 1 12:04:08 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 01 Mar 2023 09:04:08 -0800 (PST) Subject: How to escape strings for re.finditer? References: Message-ID: <63ff8588.6b0a0220.a52ed.772a@mx.google.com> On 2023-02-28, Cameron Simpson wrote: > Regexps are: > - cryptic and error prone (you can make them more readable, but the > notation is deliberately both terse and powerful, which means that > small changes can have large effects in behaviour); the "error prone" > part does not mean that a regexp is unreliable, but that writing one > which is _correct_ for your task can be difficult, The nasty thing is that writing one that _appears_ to be correct for your task is often fairly easy. It will work as you expect for the test cases you throw at it, but then fail in confusing ways when released into the "real world". If you're lucky, it fails frequently and obviously enough that you notice it right away. If you're not lucky, it will fail infrequently and subtly for many years to come. My rule: never use an RE if you can use the normal string methods (even if it takes a a few lines of code using them to replace a single RE). -- Grant From list1 at tompassin.net Wed Mar 1 12:48:27 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 1 Mar 2023 12:48:27 -0500 Subject: How to escape strings for re.finditer? In-Reply-To: <63ff8588.6b0a0220.a52ed.772a@mx.google.com> References: <63ff8588.6b0a0220.a52ed.772a@mx.google.com> Message-ID: On 3/1/2023 12:04 PM, Grant Edwards wrote: > On 2023-02-28, Cameron Simpson wrote: > >> Regexps are: >> - cryptic and error prone (you can make them more readable, but the >> notation is deliberately both terse and powerful, which means that >> small changes can have large effects in behaviour); the "error prone" >> part does not mean that a regexp is unreliable, but that writing one >> which is _correct_ for your task can be difficult, > > The nasty thing is that writing one that _appears_ to be correct for > your task is often fairly easy. It will work as you expect for the > test cases you throw at it, but then fail in confusing ways when > released into the "real world". If you're lucky, it fails frequently > and obviously enough that you notice it right away. If you're not > lucky, it will fail infrequently and subtly for many years to come. > > My rule: never use an RE if you can use the normal string methods > (even if it takes a a few lines of code using them to replace a single > RE). A corollary is that once you get a working regex, don't mess with it if you do not absolutely have to. From avi.e.gross at gmail.com Wed Mar 1 12:48:34 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 1 Mar 2023 12:48:34 -0500 Subject: Python 3.10 Fizzbuzz In-Reply-To: References: <87v8qaxyna.fsf@nightsong.com> <749b4375-9dd4-99e1-19bc-dbc90fc068bc@btinternet.com> <14355d71-81af-422b-9d80-68768cd9bb2e@DancesWithMice.info> <00ef01d94bb8$5d71e030$1855a090$@gmail.com> <20230301105509.GA24525@bleah.co.uk> Message-ID: <004401d94c66$0b8b1620$22a14260$@gmail.com> This discussion has veered a bit, as it often does, but does raise interesting points about programming in general and also in python. We seem to be able to easily cite examples where a group of things is lumped for convenience and people end up using them but then tweaking them. S an example, the ggplot2 package in R (a version is available in python) does graphics with some defaults and you can add-in themes that set internal aspects of the object including many that allow you to see what the background of the graph looks like. One common need was to remove color for printing in a black/white situation so someone created a theme_bw() you could call that sets the parameters deemed appropriate. The background can include many things including crosshatchings that can be tweaked independently. Some people thought the theme_bw() was not pleasing and figured out how to tweak a few things after calling it and next thing we know, someone packages a new set and calls it theme_gray(), theme_minimal(), theme_dark(), theme_void() and, of course, theme_classic(). But using more than one of these in a row can be both wasteful and puzzling. The last one is selectively over-riding a data-structure in parts with some changes to the same spot the previous one created or modified and some not. So we have what I consider layers of bundling and abstraction, as is common in many object-oriented programs and quite subtle bugs that can happen when you cannot see inside a black box, or don't know you need to. I often created a graph where I tweaked a few things by myself and got the nice graph I wanted. Then I was asked to not make that nice colorful graph because they could not see it as nicely when printed without color. Simple enough, I added theme_bw() or something at the end of a sort of pipeline and indeed it drained all the color out but did more than I wanted. It also happened to reset something I had crafted that did not really have anything to do with color. To get it to work, I had to rearrange my pipeline and place my changes after theme_bw(). This does not mean the people who created a sort of "standard" were wrong. It means using their standard carelessly can have unanticipated results. Examples like this are quite common but the key is that use of these things is not mandated and you can roll your own if you wish. When you look at our discussion of the computer program called "black" it seems the fault, if any, is in the organization that makes use of it mandatory and inflexible, and even has it change your code for you without any easy way to ... I am guessing that quite a few "black" options chosen are nearly universally agreed upon. A few may be vehemently opposed. And some seem random like the 88 columns one. The standard computer terminals in days of yore (does anyone still use them?) did often have exactly 80 columns frequently. But as the years rolled on, we had windowed machines with no fixed sizes for windows and even often support for different font sizes. We have scroll abilities often built in so often long lines do not wrap but you can scroll to see the rest. And much of our software no longer uses constant fixed length buffers and can adapt the moment a window is resized and much more. And dare I mention we are now getting programs written that no human is expected to read and often is written by a program and eventually more like by an AI. Have you tried to read the HTML with embedded compressed JavaScript in a browser window that is not formatted for human consumption but uses less resources to transmit? I am trying to imagine the output from something like evaluating a complex Regular Expression if written down as code in python rather than a sort of compiled form mainly using C. Is there any reason it would not sometimes dive deeply into something line many nested layers of IF statements. By Python rules, every level has to be indented a minimal amount. If black insisted on say 4 spaces, you could easily exceed the ability to write anything on a line as you are already past the 88th column. I doubt black can fix something like this. It is perfectly valid to have arbitrarily nested concepts like this in many places, including something like a JSON representation of a structure. But it is no longer always reasonable to simply ask programmers to let you select your own changes and options for something like black except in limited ways. Allowing shortening line length to 80 may be harmless. Allowing it to be set to unlimited, maybe not. Aspects may interact with others in ways you are not aware of. As an experiment, this message has hat noting external copied/pasted into it. I am wondering if people who see my text oddly but only sometimes, may be seeing what happens when I copy a segment with a different hidden line ending that is maintained by my editor. Truly this illustrates why having two standards may not be optimal and result in chaos. -----Original Message----- From: Python-list On Behalf Of Jon Ribbens via Python-list Sent: Wednesday, March 1, 2023 6:48 AM To: python-list at python.org Subject: Re: Python 3.10 Fizzbuzz On 2023-03-01, Simon Ward wrote: > On Tue, Feb 28, 2023 at 04:05:19PM -0500, avi.e.gross at gmail.com wrote: >>Is it rude to name something "black" to make it hard for some of us to >>remind them of the rules or claim that our personal style is so often >>the opposite that it should be called "white" or at least shade of >>gray? >> >>The usual kidding aside, I have no idea what it was called black but >>in all seriousness this is not a black and white issue. Opinions may >>differ when a language provides many valid options on how to write >>code. If someone wants to standardize and impose some decisions, fine. >>But other may choose their own variant and take their chances. > > https://pypi.org/project/grey/ > https://pypi.org/project/white/ > https://pypi.org/project/blue/ > https://pypi.org/project/oitnb/ > >:o > > It amuses me that opinionated formatter, with very little > configurability by design, in the face of differing opinions just > results in forks or wrappers that modify the behaviours that might > otherwise have been configuration options. The mysterious bit is that two of the above projects do nothing except change the default of the one configuration option that *does* exist (line length). I mean, "black"'s line-length choice of 88 is insane, but I don't see the point of creating new pypi projects that do nothing except run another project with a single option set! -- https://mail.python.org/mailman/listinfo/python-list From mats at wichmann.us Wed Mar 1 13:26:30 2023 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 1 Mar 2023 11:26:30 -0700 Subject: How to fix this issue In-Reply-To: <47d350be-ab36-4e69-afed-13539f600665n@googlegroups.com> References: <47d350be-ab36-4e69-afed-13539f600665n@googlegroups.com> Message-ID: <72efff0b-a9fe-4f77-2d7f-38a4d3698768@wichmann.us> On 2/27/23 17:51, Arslan Mehmood wrote: > How I can remove python terminl, its again and again open during working in python. Please help me to resolve this issue. > Python 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> We have no idea what you think the "issue" is. Perhaps if you attempted a bit more of an explanation? You're working with Python, and the Python interpreter appears. On the surface, that doesn't seem horribly unusual. Have you read this? https://docs.python.org/3/using/windows.html From dieter at handshake.de Wed Mar 1 13:43:06 2023 From: dieter at handshake.de (Dieter Maurer) Date: Wed, 1 Mar 2023 19:43:06 +0100 Subject: Look free ID genertion (was: Is there a more efficient threading lock?) In-Reply-To: References: Message-ID: <25599.40122.974242.703509@ixdm.fritz.box> Chris Angelico wrote at 2023-3-1 12:58 +1100: > ... > The >atomicity would be more useful in that context as it would give >lock-free ID generation, which doesn't work in Python. I have seen `itertools.count` for that. This works because its `__next__` is implemented in "C" and therefore will not be interrupted by a thread switch. From list1 at tompassin.net Wed Mar 1 13:46:14 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 1 Mar 2023 13:46:14 -0500 Subject: How to fix this issue In-Reply-To: <72efff0b-a9fe-4f77-2d7f-38a4d3698768@wichmann.us> References: <47d350be-ab36-4e69-afed-13539f600665n@googlegroups.com> <72efff0b-a9fe-4f77-2d7f-38a4d3698768@wichmann.us> Message-ID: <4af8cad4-ea3c-86ea-ee96-eefcaa7490ff@tompassin.net> On 3/1/2023 1:26 PM, Mats Wichmann wrote: > On 2/27/23 17:51, Arslan Mehmood wrote: >> How I can remove python terminl, its again and again open during >> working in python. Please help me to resolve this issue. >> Python 3.11.1 (tags/v3.11.1:a7a450f, Dec? 6 2022, 19:58:39) [MSC >> v.1934 64 bit (AMD64)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> > > > We have no idea what you think the "issue" is. Perhaps if you attempted > a bit more of an explanation?? You're working with Python, and the > Python interpreter appears. On the surface, that doesn't seem horribly > unusual. Let me spell it out more clearly. I do not know what you mean by "remove python terminal", "again and again open", or "during working with python". It would be more helpful if you said what you did, what happened when you did it, and what messages you noticed during all this. For example: "I opened a Windows console. I started a Python interpreter session by typing "py" in the console (or "I started an ipython session", or whatever you actually did). I tried to end the session by pressing the keys but the session did not end. When I pressed , I saw a message that said KeyboardInterrupt >>>" If this is what actually happened, this particular behavior occurs because Python on Windows in a console terminates with a instead of the usual . So please say clearly what you did and what happened. Then you may be able to get some help. We understand that you may not know the terminology that would be the most helpful because you are not familiar with it yet. But please try to say clearly what you did and what happened. From avi.e.gross at gmail.com Wed Mar 1 14:35:35 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 1 Mar 2023 14:35:35 -0500 Subject: Look free ID genertion (was: Is there a more efficient threading lock?) In-Reply-To: <25599.40122.974242.703509@ixdm.fritz.box> References: <25599.40122.974242.703509@ixdm.fritz.box> Message-ID: <005801d94c74$fed66100$fc832300$@gmail.com> If a workaround like itertools.count.__next__() is used because it will not be interrupted as it is implemented in C, then I have to ask if it would make sense for Python to supply something similar in the standard library for the sole purpose of a use in locks. But realistically, this is one place the concept of an abstract python language intersects aspects of what is bundled into a sort of core at or soon after startup, as well as the reality that python can be implemented in many ways including some ways on some hardware that may not make guarantees to behave this way. Realistically, the history of computing is full of choices made that now look less useful or obvious. What would have happened if all processors had been required to have some low level instruction that effectively did something in an atomic way that allowed a way for anyone using any language running on that machine a way to do a simple thing like set a lock or check it? Of course life has also turned out to be more complex. Some architectures can now support a small number of operations and implement others as sort of streams of those operations liked together. You would need to be sure your program is very directly using the atomic operation directly. -----Original Message----- From: Python-list On Behalf Of Dieter Maurer Sent: Wednesday, March 1, 2023 1:43 PM To: Chris Angelico Cc: python-list at python.org Subject: Look free ID genertion (was: Is there a more efficient threading lock?) Chris Angelico wrote at 2023-3-1 12:58 +1100: > ... > The >atomicity would be more useful in that context as it would give >lock-free ID generation, which doesn't work in Python. I have seen `itertools.count` for that. This works because its `__next__` is implemented in "C" and therefore will not be interrupted by a thread switch. -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Mar 1 14:41:46 2023 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Mar 2023 06:41:46 +1100 Subject: Look free ID genertion (was: Is there a more efficient threading lock?) In-Reply-To: <005801d94c74$fed66100$fc832300$@gmail.com> References: <25599.40122.974242.703509@ixdm.fritz.box> <005801d94c74$fed66100$fc832300$@gmail.com> Message-ID: On Thu, 2 Mar 2023 at 06:37, wrote: > > If a workaround like itertools.count.__next__() is used because it will not > be interrupted as it is implemented in C, then I have to ask if it would > make sense for Python to supply something similar in the standard library > for the sole purpose of a use in locks. That's not lock-free :) The only way that it works is because it's locked against other threads doing the same job. Lock-free ID generation means that: 1) Two threads can request IDs simultaneously and will not block each other 2) No two "request an ID" calls will ever return the same value 3) Preferably (but not required), IDs are not wasted. PostgreSQL has ways of doing this, and there are a few other ways, but simply using a count object and relying on the GIL isn't going to achieve the first (though it'll happily achieve the other two). ChrisA From avi.e.gross at gmail.com Wed Mar 1 15:39:21 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 1 Mar 2023 15:39:21 -0500 Subject: How to escape RE In-Reply-To: <63ff8588.6b0a0220.a52ed.772a@mx.google.com> References: <63ff8588.6b0a0220.a52ed.772a@mx.google.com> Message-ID: <008b01d94c7d$e747b6c0$b5d72440$@gmail.com> Cameron, The topic is now Regular Expressions and the sin tax. This is not exclusively a Python issue as everybody and even their grandmother uses it in various forms. I remember early versions of RE were fairly simple and readable. It was a terse minilanguage that allowed fairly complex things to be done but was readable. You now encounter versions that make people struggle as countless extensions have been sloppily grafted on. Who ordered multiple uses where "?" is now used? As an example. Many places have sort of expanded the terseness and both made it more and also less legible. UNICODE made lots of older RE features not very useful as definitions of things like what whitespace can be and what a word boundary or contents might be are made so different that new constructs were added to hold them. But, if you are operating mainly on ASCII text, the base functionality is till in there and can be used fairly easily. Consider it a bit like other mini languages such as the print() variants that kept adding functionality by packing lots of info tersely so you specify you want a floating point number with so many digits and so on, and by the way, right justified in a wider field and if it is negative, so this. Great if you can still remember how to read it. I was reading a python book recently which kept using a suffix of !r and I finally looked it up. It seems to be asking print (or perhaps an f string) to use __repr__() if possible to get the representation of the object. Then I find out this is not really needed any more as the context now allows you to use something like {repr(val)) so a val!r is not the only and confusing way. These mini-languages each require you to learn their own rules and quirks and when you do, they can be powerful and intuitive, at least for the features you memorized and maybe use regularly. Now RE knowledge is the same and it ports moderately well between languages except when it doesn't. As has been noted, the people at PERL relied on it a lot and kept changing and extending it. Some Python functionality lets you specify if you want PERL style or other styles. But hiding your head in the sand is not always going to work for long. No, you do not need to use RE for simple cases. Mind you, that is when it is easiest to use it reliably. I read some books related to XML where much of the work had been done in non-UNIX land years ago and they often had other ways of doing things in their endless series of methods on validating a schema or declaring it so data is forced to match the declared objectives such as what type(s) each item can be or whether some fields must exist inside others or in a particular order, or say you can have only three of them and seeming endless other such things. And then, suddenly, someone has the idea to introduce the ability for you to specify many things using regular expressions and the oppressiveness (for me) lifts and many things can now be done trivially or that were not doable before. I had a similar experience in my SQL reading where adding the ability to do some pattern matching using a form of RE made life simpler. The fact is that the idea of complex pattern matching IS complex and any tool that lets you express it so fluidly will itself be complex. So, as some have mentioned, find a resource that helps you build a regular expression perhaps through menus, or one that verifies if one you created makes any sense or lets you enter test data and have it show you how it is matching or what to change to make it match differently. The multi-line version of RE may also be helpful as well as sometimes breaking up a bigger one into several smaller ones that your program uses in multiple phases. Python recently added new functionality called Structural Pattern Matching. You use a match statement with various cases that match patterns and if matched, execute some action. Here is one tutorial if needed: https://peps.python.org/pep-0636/ The point is that although not at all the same as a RE, we again have a bit of a mini-language that can be used fairly concisely to investigate a problem domain fairly quickly and efficiently and do things. It is an overlapping but different form of pattern matching. And, in languages that have long had similar ideas and constructs, people often cut back on using other constructs like an IF statement, and just used something like this! And consider this example as being vaguely like a bit of regular expression: match command.split(): case ["go", ("north" | "south" | "east" | "west")]: current_room = current_room.neighbor(...) Like it or not, our future in programming is likely to include more and more such aids along with headaches. Avi -----Original Message----- From: Python-list On Behalf Of Grant Edwards Sent: Wednesday, March 1, 2023 12:04 PM To: python-list at python.org Subject: Re: How to escape strings for re.finditer? On 2023-02-28, Cameron Simpson wrote: > Regexps are: > - cryptic and error prone (you can make them more readable, but the > notation is deliberately both terse and powerful, which means that > small changes can have large effects in behaviour); the "error prone" > part does not mean that a regexp is unreliable, but that writing one > which is _correct_ for your task can be difficult, The nasty thing is that writing one that _appears_ to be correct for your task is often fairly easy. It will work as you expect for the test cases you throw at it, but then fail in confusing ways when released into the "real world". If you're lucky, it fails frequently and obviously enough that you notice it right away. If you're not lucky, it will fail infrequently and subtly for many years to come. My rule: never use an RE if you can use the normal string methods (even if it takes a a few lines of code using them to replace a single RE). -- Grant -- https://mail.python.org/mailman/listinfo/python-list From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Mar 1 15:35:29 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Wed, 1 Mar 2023 15:35:29 -0500 Subject: Look free ID genertion (was: Is there a more efficient threading lock?) In-Reply-To: <005801d94c74$fed66100$fc832300$@gmail.com> References: <25599.40122.974242.703509@ixdm.fritz.box> <005801d94c74$fed66100$fc832300$@gmail.com> Message-ID: On 2023-03-01 at 14:35:35 -0500, avi.e.gross at gmail.com wrote: > What would have happened if all processors had been required to have > some low level instruction that effectively did something in an atomic > way that allowed a way for anyone using any language running on that > machine a way to do a simple thing like set a lock or check it? Have happened? I don't know about "required," but processors have indeed had such instructions for decades; e.g., the MC68000 from the early to mid 1980s (and used in the original Apple Macintosh, but I digress) has/had a Test and Set instruction. From gheskett at shentel.net Wed Mar 1 16:59:33 2023 From: gheskett at shentel.net (gene heskett) Date: Wed, 1 Mar 2023 16:59:33 -0500 Subject: Python 3.10 Fizzbuzz In-Reply-To: References: <87v8qaxyna.fsf@nightsong.com> <749b4375-9dd4-99e1-19bc-dbc90fc068bc@btinternet.com> <14355d71-81af-422b-9d80-68768cd9bb2e@DancesWithMice.info> <00ef01d94bb8$5d71e030$1855a090$@gmail.com> <20230301105509.GA24525@bleah.co.uk> Message-ID: <5da41979-c250-6614-cd84-0e13ecb459b4@shentel.net> On 3/1/23 11:41, rbowman wrote: > On 1 Mar 2023 11:28:12 GMT, Stefan Ram wrote: > > >> IIRC, I've heard of professional video monitors which are set to >> standard values for color saturation, contrast, and brightness. They >> have no way to adjust these values, although they are more expensive >> than normal screens. > > Probably a good thing. In the early days of color TV the color values were > user adjustable. A generation grew up thinking Lorne Greene (Bonanza) had > a slightly green complexion to match his name. > Chuckle. That was back in what we called Never Twice Same Color days. NTSC IOW. I'm a retired tv Chief Engineer and we as broadcasters always had a vectorscope in front of the operator so he could adjust the color if it wasn't right. Even if he was color blind! Human skin always has the same color and it makes an excellent image on the vectorscope at a certain angle. And it does not change that angle when the camera switches from my white caucasian face to the blackest basketball or football players, the difference is not the color, but the brightness. A lesson I've had to demo to every colored person we ever hired by showing him both of us on camera. Cheers, Gene Heskett. -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author, 1940) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From cs at cskk.id.au Wed Mar 1 16:33:22 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 2 Mar 2023 08:33:22 +1100 Subject: Python 3.10 Fizzbuzz In-Reply-To: References: Message-ID: On 28Feb2023 12:54, Greg Ewing wrote: >I guess this means I can't use Black. :-( Black's treatment of quotes and docstrings is one of the largest reasons why I won't let it touch my personal code. yapf is far better behaved, and can be tuned as well! Cheers, Cameron Simpson From cs at cskk.id.au Wed Mar 1 16:38:01 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 2 Mar 2023 08:38:01 +1100 Subject: Python 3.10 Fizzbuzz In-Reply-To: References: Message-ID: On 26Feb2023 13:07, Hen Hanna wrote: >is there any reason to prefer " over ' ? Not inherently. It is only important if you want to embed one of those characters in a string, eg: x = "That's silly." versus: x = 'That\'s silly.' and the converse for the other quote character. Cheers, Cameron Simpson From rob.cliffe at btinternet.com Wed Mar 1 20:23:57 2023 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Thu, 2 Mar 2023 01:23:57 +0000 Subject: How to fix this issue In-Reply-To: <4af8cad4-ea3c-86ea-ee96-eefcaa7490ff@tompassin.net> References: <47d350be-ab36-4e69-afed-13539f600665n@googlegroups.com> <72efff0b-a9fe-4f77-2d7f-38a4d3698768@wichmann.us> <4af8cad4-ea3c-86ea-ee96-eefcaa7490ff@tompassin.net> Message-ID: <33238d88-445b-3a0c-9c61-1b371b2441a6@btinternet.com> On 01/03/2023 18:46, Thomas Passin wrote: > > If this is what actually happened, this particular behavior occurs > because Python on Windows in a console terminates with a > instead of the usual . > I think you mean . From greg.ewing at canterbury.ac.nz Wed Mar 1 20:23:09 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 2 Mar 2023 14:23:09 +1300 Subject: Python 3.10 Fizzbuzz In-Reply-To: References: <87v8qaxyna.fsf@nightsong.com> <749b4375-9dd4-99e1-19bc-dbc90fc068bc@btinternet.com> <14355d71-81af-422b-9d80-68768cd9bb2e@DancesWithMice.info> <00ef01d94bb8$5d71e030$1855a090$@gmail.com> <20230301105509.GA24525@bleah.co.uk> <5da41979-c250-6614-cd84-0e13ecb459b4@shentel.net> Message-ID: On 2/03/23 10:59 am, gene heskett wrote: > Human skin always has the same color Um... no? -- Greg From rosuav at gmail.com Wed Mar 1 20:45:50 2023 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Mar 2023 12:45:50 +1100 Subject: Look free ID genertion (was: Is there a more efficient threading lock?) In-Reply-To: References: <25599.40122.974242.703509@ixdm.fritz.box> <005801d94c74$fed66100$fc832300$@gmail.com> Message-ID: On Thu, 2 Mar 2023 at 08:01, <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > > On 2023-03-01 at 14:35:35 -0500, > avi.e.gross at gmail.com wrote: > > > What would have happened if all processors had been required to have > > some low level instruction that effectively did something in an atomic > > way that allowed a way for anyone using any language running on that > > machine a way to do a simple thing like set a lock or check it? > > Have happened? I don't know about "required," but processors have > indeed had such instructions for decades; e.g., the MC68000 from the > early to mid 1980s (and used in the original Apple Macintosh, but I > digress) has/had a Test and Set instruction. As have all CPUs since; it's the only way to implement locks (push the locking all the way down to the CPU level). ChrisA From list1 at tompassin.net Wed Mar 1 20:54:10 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 1 Mar 2023 20:54:10 -0500 Subject: How to fix this issue In-Reply-To: <33238d88-445b-3a0c-9c61-1b371b2441a6@btinternet.com> References: <47d350be-ab36-4e69-afed-13539f600665n@googlegroups.com> <72efff0b-a9fe-4f77-2d7f-38a4d3698768@wichmann.us> <4af8cad4-ea3c-86ea-ee96-eefcaa7490ff@tompassin.net> <33238d88-445b-3a0c-9c61-1b371b2441a6@btinternet.com> Message-ID: <363aa8c6-3a0a-6499-55fe-fd86ea1bff98@tompassin.net> On 3/1/2023 8:23 PM, Rob Cliffe via Python-list wrote: > > > On 01/03/2023 18:46, Thomas Passin wrote: >> >> If this is what actually happened, this particular behavior occurs >> because Python on Windows in a console terminates with a >> instead of the usual . >> > I think you mean . Correct! I double checked all three of them and then typed the wrong one. I suppose I should have included that you have to also type an after the . From gweatherby at uchc.edu Wed Mar 1 21:00:56 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Thu, 2 Mar 2023 02:00:56 +0000 Subject: Look free ID genertion (was: Is there a more efficient threading lock?) In-Reply-To: References: <25599.40122.974242.703509@ixdm.fritz.box> <005801d94c74$fed66100$fc832300$@gmail.com> Message-ID: So I guess we know what would have happened. Get Outlook for iOS ________________________________ From: Python-list on behalf of Chris Angelico Sent: Wednesday, March 1, 2023 8:45:50 PM To: python-list at python.org Subject: Re: Look free ID genertion (was: Is there a more efficient threading lock?) *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** On Thu, 2 Mar 2023 at 08:01, <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > > On 2023-03-01 at 14:35:35 -0500, > avi.e.gross at gmail.com wrote: > > > What would have happened if all processors had been required to have > > some low level instruction that effectively did something in an atomic > > way that allowed a way for anyone using any language running on that > > machine a way to do a simple thing like set a lock or check it? > > Have happened? I don't know about "required," but processors have > indeed had such instructions for decades; e.g., the MC68000 from the > early to mid 1980s (and used in the original Apple Macintosh, but I > digress) has/had a Test and Set instruction. As have all CPUs since; it's the only way to implement locks (push the locking all the way down to the CPU level). ChrisA -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!g70S067RzF2oPCFUYpFFzUvPHRfS0AHIGEvVyww1Tlj7BCCrsU3DWIqCE9UBO_ex0ZVanquFLHGe1d2b$ From rosuav at gmail.com Wed Mar 1 21:16:45 2023 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Mar 2023 13:16:45 +1100 Subject: Look free ID genertion (was: Is there a more efficient threading lock?) In-Reply-To: References: <25599.40122.974242.703509@ixdm.fritz.box> <005801d94c74$fed66100$fc832300$@gmail.com> Message-ID: On Thu, 2 Mar 2023 at 13:02, Weatherby,Gerard wrote: > > So I guess we know what would have happened. > Yep. It's not what I was talking about, but it's also a very important concurrency management feature. ChrisA From jon+usenet at unequivocal.eu Wed Mar 1 21:05:18 2023 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 2 Mar 2023 02:05:18 -0000 (UTC) Subject: Look free ID genertion (was: Is there a more efficient threading lock?) References: <25599.40122.974242.703509@ixdm.fritz.box> <005801d94c74$fed66100$fc832300$@gmail.com> Message-ID: On 2023-03-02, Chris Angelico wrote: > On Thu, 2 Mar 2023 at 08:01, <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: >> On 2023-03-01 at 14:35:35 -0500, >> avi.e.gross at gmail.com wrote: >> > What would have happened if all processors had been required to have >> > some low level instruction that effectively did something in an atomic >> > way that allowed a way for anyone using any language running on that >> > machine a way to do a simple thing like set a lock or check it? >> >> Have happened? I don't know about "required," but processors have >> indeed had such instructions for decades; e.g., the MC68000 from the >> early to mid 1980s (and used in the original Apple Macintosh, but I >> digress) has/had a Test and Set instruction. > > As have all CPUs since; it's the only way to implement locks (push the > locking all the way down to the CPU level). Indeed, I remember thinking it was very fancy when they added the SWP instruction to the ARM processor. From gheskett at shentel.net Wed Mar 1 22:00:38 2023 From: gheskett at shentel.net (gene heskett) Date: Wed, 1 Mar 2023 22:00:38 -0500 Subject: Python 3.10 Fizzbuzz In-Reply-To: References: <87v8qaxyna.fsf@nightsong.com> <749b4375-9dd4-99e1-19bc-dbc90fc068bc@btinternet.com> <14355d71-81af-422b-9d80-68768cd9bb2e@DancesWithMice.info> <00ef01d94bb8$5d71e030$1855a090$@gmail.com> <20230301105509.GA24525@bleah.co.uk> <5da41979-c250-6614-cd84-0e13ecb459b4@shentel.net> Message-ID: On 3/1/23 20:28, Greg Ewing via Python-list wrote: > On 2/03/23 10:59 am, gene heskett wrote: >> Human skin always has the same color > > Um... no? > Yes, only the intensity of the color changes, the vector angle remains the same within a degree or so. Cheers, Gene Heskett. -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author, 1940) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From stephen_tucker at sil.org Thu Mar 2 06:25:49 2023 From: stephen_tucker at sil.org (Stephen Tucker) Date: Thu, 2 Mar 2023 11:25:49 +0000 Subject: Python 2.7 range Function provokes a Memory Error Message-ID: Hi, The range function in Python 2.7 (and yes, I know that it is now superseded), provokes a Memory Error when asked to deiliver a very long list of values. I assume that this is because the function produces a list which it then iterates through. 1. Does the range function in Python 3.x behave the same way? 2. Is there any equivalent way that behaves more like a for loop (that is, without producing a list)? To get round the problem I have written my own software that is used in a for loop. Stephen Tucker. From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Mar 2 06:34:24 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 2 Mar 2023 06:34:24 -0500 Subject: Python 2.7 range Function provokes a Memory Error In-Reply-To: References: Message-ID: On 2023-03-02 at 11:25:49 +0000, Stephen Tucker wrote: > The range function in Python 2.7 (and yes, I know that it is now > superseded), provokes a Memory Error when asked to deiliver a very long > list of values. > > I assume that this is because the function produces a list which it then > iterates through. > > 1. Does the range function in Python 3.x behave the same way? No. > 2. Is there any equivalent way that behaves more like a for loop (that is, > without producing a list)? Try xrange. From rosuav at gmail.com Thu Mar 2 06:43:22 2023 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Mar 2023 22:43:22 +1100 Subject: Python 2.7 range Function provokes a Memory Error In-Reply-To: References: Message-ID: On Thu, 2 Mar 2023 at 22:27, Stephen Tucker wrote: > > Hi, > > The range function in Python 2.7 (and yes, I know that it is now > superseded), provokes a Memory Error when asked to deiliver a very long > list of values. > > I assume that this is because the function produces a list which it then > iterates through. > > 1. Does the range function in Python 3.x behave the same way? No, but list(range(x)) might, for the same reason. In Py2, range returns a list, which means it needs a gigantic collection of integer objects. In Py3, a range object just defines its start/stop/step, but if you call list() on it, you get the same sort of > 2. Is there any equivalent way that behaves more like a for loop (that is, > without producing a list)? > > To get round the problem I have written my own software that is used in a > for loop. xrange is an iterator in Py2, so that's the easiest way to handle it. Obviously migrating to Py3 would be the best way, but in the meantime, xrange will probably do what you need. ChrisA From jon+usenet at unequivocal.eu Thu Mar 2 06:29:53 2023 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 2 Mar 2023 11:29:53 -0000 (UTC) Subject: Python 2.7 range Function provokes a Memory Error References: Message-ID: On 2023-03-02, Stephen Tucker wrote: > The range function in Python 2.7 (and yes, I know that it is now > superseded), provokes a Memory Error when asked to deiliver a very long > list of values. > > I assume that this is because the function produces a list which it then > iterates through. > > 1. Does the range function in Python 3.x behave the same way? No, in Python 3 it is an iterator which produces the next number in the sequence each time. > 2. Is there any equivalent way that behaves more like a for loop (that is, > without producing a list)? Yes, 'xrange' in Python 2 behaves like 'range' in Python 3. From wlfraed at ix.netcom.com Thu Mar 2 11:42:03 2023 From: wlfraed at ix.netcom.com (Dennis Lee Bieber) Date: Thu, 02 Mar 2023 11:42:03 -0500 Subject: Look free ID genertion (was: Is there a more efficient threading lock?) References: <25599.40122.974242.703509@ixdm.fritz.box> <005801d94c74$fed66100$fc832300$@gmail.com> Message-ID: On Thu, 2 Mar 2023 12:45:50 +1100, Chris Angelico declaimed the following: > >As have all CPUs since; it's the only way to implement locks (push the >locking all the way down to the CPU level). > Xerox Sigma (circa 1970): Modify and Test (byte/halfword/word) Granted, that was a "mainframe" system, not a microprocessor. Looks like Intel didn't catch the boat until 1985 and the i386. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ From rob.cliffe at btinternet.com Thu Mar 2 14:09:47 2023 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Thu, 2 Mar 2023 19:09:47 +0000 Subject: Packing Problem In-Reply-To: References: Message-ID: <6e36f542-e4b6-35f8-5530-1115360de252@btinternet.com> Slightly improved version (deals with multiple characters together instead of one at a time): # Pack.py def Pack(Words): ??? if not Words: ??????? return '' ??? # The method is to build up the result by adding letters at the beginning ??? # and working forward, and by adding letters at the end, working backwards, ??? # meanwhile shrinking the words in the list. ??? Words = list(Words) # Don't mutate the original ??? Initial = '' ??? Final = '' ??? while True: ??????? # It is safe to add an initial letter (of one or more of the words) if ??????? # EITHER??? There is no word that contains it as ??????? #???????????? a non-initial letter but not as an initial letter. ??????? #? OR?????? All words start with it. ??????? while True: ??????????? FirstLetters = set(w[0] for w in Words) ??????????? FirstLettersSafe = sorted(ch for ch in FirstLetters if ??????????????? all(w[0]==ch for w in Words) ??????????????? or not any(ch in w[1:] and w[0]!=ch for w in Words)) ??????????????? # sorted() to make the answer deterministic ??????????????? # (not dependent on set ordering) ??????????? if not FirstLettersSafe: ??????????????? break ??????????? AnyProgress = True ??????????? Initial += ''.join(FirstLettersSafe)?? # Build up the answer from the beginning ??????????? Words = [ (w[1:] if w[0] in FirstLettersSafe else w) for w in Words ] ??????????? Words = [ w for w in Words if w != ''] ??????????? if not Words: ??????????????? return Initial + Final ??????? # It is safe to add a final letter (of one or more of the words) of ??????? # EITHER??? There is no word that contains it as ??????? #???????????? a non-final letter but not as a final letter. ??????? #? OR?????? All words end with it. ??????? while True: ??????????? LastLetters = set(w[-1] for w in Words) ??????????? LastLettersSafe = sorted(ch for ch in LastLetters if ??????????????? all(w[-1]==ch for w in Words) ??????????????? or not any(ch in w[:-1] and w[-1]!=ch for w in Words)) ??????????????? # sorted() to make the answer deterministic ??????????????? # (not dependent on set ordering) ??????????? if not LastLettersSafe: ??????????????? break ??????????? Final = ''.join(LastLettersSafe) + Final?? # Build up the answer from the end ??????????? Words = [ (w[:-1] if w[-1] in LastLettersSafe else w) for w in Words ] ??????????? Words = [ w for w in Words if w != ''] ??????????? if not Words: ??????????????? return Initial + Final ??????? if not (FirstLettersSafe or LastLettersSafe): ??????????? break # stuck ??? # Try all the possibilities for the next letter to add at the beginning, ??? # with recursive calls, and pick one that gives a shortest answer: ??? BestResult = None ??? for ch in FirstLetters: ??????????? Words2 = list( (w[1:] if w[0] == ch else w) for w in Words ) ??????????? Words2 = [ w for w in Words2 if w != '' ] ??????????? res = ch + Pack(Words2) ??????????? if BestResult is None or len(res) < len(BestResult): ??????????????? BestResult = res ??? return Initial + BestResult + Final print(Pack(['APPLE', 'PIE', 'APRICOT', 'BANANA', 'CANDY'])) Rob Cliffe From jicman at gmail.com Thu Mar 2 14:22:41 2023 From: jicman at gmail.com (jose isaias cabrera) Date: Thu, 2 Mar 2023 14:22:41 -0500 Subject: Regular Expression bug? Message-ID: Greetings. For the RegExp Gurus, consider the following python3 code: import re s = "pn=align upgrade sd=2023-02-" ro = re.compile(r"pn=(.+) ") r0=ro.match(s) >>> print(r0.group(1)) align upgrade This is wrong. It should be 'align' because the group only goes up-to the space. Thoughts? Thanks. jos? -- What if eternity is real? Where will you spend it? Hmmmm... From rosuav at gmail.com Thu Mar 2 14:28:22 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Mar 2023 06:28:22 +1100 Subject: Regular Expression bug? In-Reply-To: References: Message-ID: On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera wrote: > > Greetings. > > For the RegExp Gurus, consider the following python3 code: > > import re > s = "pn=align upgrade sd=2023-02-" > ro = re.compile(r"pn=(.+) ") > r0=ro.match(s) > >>> print(r0.group(1)) > align upgrade > > > This is wrong. It should be 'align' because the group only goes up-to > the space. Thoughts? Thanks. > Not a bug. Find the longest possible match that fits this; as long as you can find a space immediately after it, everything in between goes into the .+ part. If you want to exclude spaces, either use [^ ]+ or .+?. ChrisA From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Mar 2 14:29:37 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 2 Mar 2023 14:29:37 -0500 Subject: Regular Expression bug? In-Reply-To: References: Message-ID: On 2023-03-02 at 14:22:41 -0500, jose isaias cabrera wrote: > For the RegExp Gurus, consider the following python3 code: > > import re > s = "pn=align upgrade sd=2023-02-" > ro = re.compile(r"pn=(.+) ") > r0=ro.match(s) > >>> print(r0.group(1)) > align upgrade > > > This is wrong. It should be 'align' because the group only goes up-to > the space. Thoughts? Thanks. The bug is in your regular expression; the plus modifier is greedy. If you want to match up to the first space, then you'll need something like [^ ] (i.e., everything that isn't a space) instead of that dot. From mats at wichmann.us Thu Mar 2 14:37:30 2023 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 2 Mar 2023 12:37:30 -0700 Subject: Regular Expression bug? In-Reply-To: References: Message-ID: <0556af4d-279d-8bf0-973d-54ea5e30f764@wichmann.us> On 3/2/23 12:28, Chris Angelico wrote: > On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera wrote: >> >> Greetings. >> >> For the RegExp Gurus, consider the following python3 code: >> >> import re >> s = "pn=align upgrade sd=2023-02-" >> ro = re.compile(r"pn=(.+) ") >> r0=ro.match(s) >>>>> print(r0.group(1)) >> align upgrade >> >> >> This is wrong. It should be 'align' because the group only goes up-to >> the space. Thoughts? Thanks. >> > > Not a bug. Find the longest possible match that fits this; as long as > you can find a space immediately after it, everything in between goes > into the .+ part. > > If you want to exclude spaces, either use [^ ]+ or .+?. https://docs.python.org/3/howto/regex.html#greedy-versus-non-greedy From jicman at gmail.com Thu Mar 2 14:38:27 2023 From: jicman at gmail.com (jose isaias cabrera) Date: Thu, 2 Mar 2023 14:38:27 -0500 Subject: Regular Expression bug? In-Reply-To: References: Message-ID: On Thu, Mar 2, 2023 at 2:32?PM <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > > On 2023-03-02 at 14:22:41 -0500, > jose isaias cabrera wrote: > > > For the RegExp Gurus, consider the following python3 code: > > > > import re > > s = "pn=align upgrade sd=2023-02-" > > ro = re.compile(r"pn=(.+) ") > > r0=ro.match(s) > > >>> print(r0.group(1)) > > align upgrade > > > > > > This is wrong. It should be 'align' because the group only goes up-to > > the space. Thoughts? Thanks. > > The bug is in your regular expression; the plus modifier is greedy. > > If you want to match up to the first space, then you'll need something > like [^ ] (i.e., everything that isn't a space) instead of that dot. Thanks. I appreciate your wisdom. jos? -- What if eternity is real? Where will you spend it? Hmmmm... From gweatherby at uchc.edu Thu Mar 2 14:40:11 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Thu, 2 Mar 2023 19:40:11 +0000 Subject: Packing Problem In-Reply-To: <6e36f542-e4b6-35f8-5530-1115360de252@btinternet.com> References: <6e36f542-e4b6-35f8-5530-1115360de252@btinternet.com> Message-ID: Haven?t look at it all in detail, but I?d replace the list comprehensions with a loop: CopyOfWords = list(Words) Words = [(w[1:] if w[0] == ch else w) for w in Words] Words = [w for w in Words if w != ''] nextWords = [] for w in CopyOfWords: if w[0] != ch: nextWords.append(w) elif len(w) > 1: nextWords.append(w[1:]) assert Words == nextWords From: Python-list on behalf of Rob Cliffe via Python-list Date: Thursday, March 2, 2023 at 2:12 PM To: python-list at python.org Subject: Re: Packing Problem *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Slightly improved version (deals with multiple characters together instead of one at a time): # Pack.py def Pack(Words): if not Words: return '' # The method is to build up the result by adding letters at the beginning # and working forward, and by adding letters at the end, working backwards, # meanwhile shrinking the words in the list. Words = list(Words) # Don't mutate the original Initial = '' Final = '' while True: # It is safe to add an initial letter (of one or more of the words) if # EITHER There is no word that contains it as # a non-initial letter but not as an initial letter. # OR All words start with it. while True: FirstLetters = set(w[0] for w in Words) FirstLettersSafe = sorted(ch for ch in FirstLetters if all(w[0]==ch for w in Words) or not any(ch in w[1:] and w[0]!=ch for w in Words)) # sorted() to make the answer deterministic # (not dependent on set ordering) if not FirstLettersSafe: break AnyProgress = True Initial += ''.join(FirstLettersSafe) # Build up the answer from the beginning Words = [ (w[1:] if w[0] in FirstLettersSafe else w) for w in Words ] Words = [ w for w in Words if w != ''] if not Words: return Initial + Final # It is safe to add a final letter (of one or more of the words) of # EITHER There is no word that contains it as # a non-final letter but not as a final letter. # OR All words end with it. while True: LastLetters = set(w[-1] for w in Words) LastLettersSafe = sorted(ch for ch in LastLetters if all(w[-1]==ch for w in Words) or not any(ch in w[:-1] and w[-1]!=ch for w in Words)) # sorted() to make the answer deterministic # (not dependent on set ordering) if not LastLettersSafe: break Final = ''.join(LastLettersSafe) + Final # Build up the answer from the end Words = [ (w[:-1] if w[-1] in LastLettersSafe else w) for w in Words ] Words = [ w for w in Words if w != ''] if not Words: return Initial + Final if not (FirstLettersSafe or LastLettersSafe): break # stuck # Try all the possibilities for the next letter to add at the beginning, # with recursive calls, and pick one that gives a shortest answer: BestResult = None for ch in FirstLetters: Words2 = list( (w[1:] if w[0] == ch else w) for w in Words ) Words2 = [ w for w in Words2 if w != '' ] res = ch + Pack(Words2) if BestResult is None or len(res) < len(BestResult): BestResult = res return Initial + BestResult + Final print(Pack(['APPLE', 'PIE', 'APRICOT', 'BANANA', 'CANDY'])) Rob Cliffe -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!l3ysx0BUPZBdKdwb9F8mw4BAE2UIflvNqWeZLfALY2kjEo9e4KTy6fEYoGCTileOUtYe0yp6nL18ymdOguC3TGagEA$ From hjp-python at hjp.at Thu Mar 2 15:08:35 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Thu, 2 Mar 2023 21:08:35 +0100 Subject: How to escape strings for re.finditer? In-Reply-To: <20230301000142.mvehc6lay2nhv42d@hjp.at> References: <012101d94b1a$9a743440$cf5c9cc0$@gmail.com> <00d001d94bb2$bea422b0$3bec6810$@gmail.com> <20230301000142.mvehc6lay2nhv42d@hjp.at> Message-ID: <20230302200835.fxxszp3a5ljrj5mp@hjp.at> On 2023-03-01 01:01:42 +0100, Peter J. Holzer wrote: > On 2023-02-28 15:25:05 -0500, avi.e.gross at gmail.com wrote: > > I had no doubt the code you ran was indented properly or it would not work. > > > > I am merely letting you know that somewhere in the process of copying > > the code or the transition between mailers, my version is messed up. > > The problem seems to be at your end. Jen's code looks ok here. [...] > I have no idea why it would join only some lines but not others. Actually I do have an idea now, since I noticed something similar at work today: Outlook has an option "remove additional line breaks from text-only messages" (translated from German) in the the "Email / Message Format" section. You want to make sure this is off if you are reading mails where line breaks might be important[1]. hp [1] Personally I'd say you shouldn't use Outlook if you are reading mails where line breaks (or other formatting) is important, but ... -- _ | 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 arequipeno at gmail.com Thu Mar 2 15:54:50 2023 From: arequipeno at gmail.com (Ian Pilcher) Date: Thu, 2 Mar 2023 14:54:50 -0600 Subject: Which more Pythonic - self.__class__ or type(self)? Message-ID: Seems like an FAQ, and I've found a few things on StackOverflow that discuss the technical differences in edge cases, but I haven't found anything that talks about which form is considered to be more Pythonic in those situations where there's no functional difference. Is there any consensus? -- ======================================================================== Google Where SkyNet meets Idiocracy ======================================================================== From list1 at tompassin.net Thu Mar 2 16:58:57 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 2 Mar 2023 16:58:57 -0500 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: References: Message-ID: <61bece50-9627-98d3-5014-eb122566834d@tompassin.net> On 3/2/2023 3:54 PM, Ian Pilcher wrote: > Seems like an FAQ, and I've found a few things on StackOverflow that > discuss the technical differences in edge cases, but I haven't found > anything that talks about which form is considered to be more Pythonic > in those situations where there's no functional difference. > > Is there any consensus? For what purpose do you want to get it? From avi.e.gross at gmail.com Thu Mar 2 17:40:36 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 2 Mar 2023 17:40:36 -0500 Subject: Regular Expression bug? In-Reply-To: References: Message-ID: <003c01d94d58$01a8a2b0$04f9e810$@gmail.com> Jos?, Matching can be greedy. Did it match to the last space? What you want is a pattern that matches anything except a space (or whitespace) followed b matching a space or something similar. Or use a construct that makes matching non-greedy. Avi -----Original Message----- From: Python-list On Behalf Of jose isaias cabrera Sent: Thursday, March 2, 2023 2:23 PM To: python-list at python.org Subject: Regular Expression bug? Greetings. For the RegExp Gurus, consider the following python3 code: import re s = "pn=align upgrade sd=2023-02-" ro = re.compile(r"pn=(.+) ") r0=ro.match(s) >>> print(r0.group(1)) align upgrade This is wrong. It should be 'align' because the group only goes up-to the space. Thoughts? Thanks. jos? -- What if eternity is real? Where will you spend it? Hmmmm... -- https://mail.python.org/mailman/listinfo/python-list From greg.ewing at canterbury.ac.nz Thu Mar 2 17:53:28 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 3 Mar 2023 11:53:28 +1300 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: References: Message-ID: On 3/03/23 9:54 am, Ian Pilcher wrote: > I haven't found > anything that talks about which form is considered to be more Pythonic > in those situations where there's no functional difference. In such cases I'd probably go for type(x), because it looks less ugly. x.__class__ *might* be slightly more efficient, as it avoids a global lookup and a function call. But as always, measurement would be required to be sure. -- Greg From avi.e.gross at gmail.com Thu Mar 2 18:08:36 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 2 Mar 2023 18:08:36 -0500 Subject: How to escape strings for re.finditer? In-Reply-To: <20230302200835.fxxszp3a5ljrj5mp@hjp.at> References: <012101d94b1a$9a743440$cf5c9cc0$@gmail.com> <00d001d94bb2$bea422b0$3bec6810$@gmail.com> <20230301000142.mvehc6lay2nhv42d@hjp.at> <20230302200835.fxxszp3a5ljrj5mp@hjp.at> Message-ID: <004001d94d5b$eba5bad0$c2f13070$@gmail.com> Thanks, Peter. Excellent advice, even if only for any of us using Microsoft Outlook as our mailer. I made the changes and we will see but they should mainly impact what I see. I did tweak another parameter. The problem for me was finding where they hid the options menu I needed. Then, I started translating the menus back into German until I realized I was being silly! Good practice though. LOL! The truth is I generally can handle receiving mangled code as most of the time I can re-edit it into shape, or am just reading it and not copying/pasting. What concerns me is to be able to send out the pure text content many seem to need in a way that does not introduce the anomalies people see. Something like a least-common denominator. Or. I could switch mailers. But my guess is reading/responding from the native gmail editor may also need options changes and yet still impact some readers. -----Original Message----- From: Python-list On Behalf Of Peter J. Holzer Sent: Thursday, March 2, 2023 3:09 PM To: python-list at python.org Subject: Re: How to escape strings for re.finditer? On 2023-03-01 01:01:42 +0100, Peter J. Holzer wrote: > On 2023-02-28 15:25:05 -0500, avi.e.gross at gmail.com wrote: > > I had no doubt the code you ran was indented properly or it would not work. > > > > I am merely letting you know that somewhere in the process of > > copying the code or the transition between mailers, my version is messed up. > > The problem seems to be at your end. Jen's code looks ok here. [...] > I have no idea why it would join only some lines but not others. Actually I do have an idea now, since I noticed something similar at work today: Outlook has an option "remove additional line breaks from text-only messages" (translated from German) in the the "Email / Message Format" section. You want to make sure this is off if you are reading mails where line breaks might be important[1]. hp [1] Personally I'd say you shouldn't use Outlook if you are reading mails where line breaks (or other formatting) is important, but ... -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" From grant.b.edwards at gmail.com Thu Mar 2 18:19:28 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 02 Mar 2023 15:19:28 -0800 (PST) Subject: How to escape strings for re.finditer? References: <012101d94b1a$9a743440$cf5c9cc0$@gmail.com> <00d001d94bb2$bea422b0$3bec6810$@gmail.com> <20230301000142.mvehc6lay2nhv42d@hjp.at> <20230302200835.fxxszp3a5ljrj5mp@hjp.at> Message-ID: <64012f00.050a0220.bdddc.07ed@mx.google.com> On 2023-03-02, Peter J. Holzer wrote: > [1] Personally I'd say you shouldn't use Outlook if you are reading > mails where line breaks (or other formatting) is important, but ... I'd shorten that to "You shouldn't use Outlook if mail is important." From list1 at tompassin.net Thu Mar 2 18:43:08 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 2 Mar 2023 18:43:08 -0500 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: References: Message-ID: On 3/2/2023 5:53 PM, Greg Ewing via Python-list wrote: > On 3/03/23 9:54 am, Ian Pilcher wrote: >> I haven't found >> anything that talks about which form is considered to be more Pythonic >> in those situations where there's no functional difference. > > In such cases I'd probably go for type(x), because it looks less > ugly. > > x.__class__ *might* be slightly more efficient, as it avoids a > global lookup and a function call. But as always, measurement > would be required to be sure. Except that we don't know if "efficiency" - whatever that might mean here - matters at all. From avi.e.gross at gmail.com Thu Mar 2 19:35:41 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 2 Mar 2023 19:35:41 -0500 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: References: Message-ID: <005001d94d68$155af3c0$4010db40$@gmail.com> My understanding is that python created functions like type() and len() as a general purpose way to get information and ALSO set up a protocol that classes can follow by creating dunder methods. I think the most pythonic things is to avoid directly calling the dunder methods with a few exceptions that mainly happen when you are building or extending classes. I mean some dunder methods are then called directly to avoid getting into infinite loops that would be triggered. And note in many cases, the protocol is more complex. Is a length built-in? If not, can the object be iterated and you count the results? Calling the function len() may get you more info as it can leverage such things. And it means you can sometimes leave out some methods and your code still works. Be warned that type() is a very special function in python and when called with more arguments, does many relatively beautiful but unrelated things. It has a special role in the class or type hierarchy. But used with a single argument, it harmlessly return a result you want. -----Original Message----- From: Python-list On Behalf Of Thomas Passin Sent: Thursday, March 2, 2023 6:43 PM To: python-list at python.org Subject: Re: Which more Pythonic - self.__class__ or type(self)? On 3/2/2023 5:53 PM, Greg Ewing via Python-list wrote: > On 3/03/23 9:54 am, Ian Pilcher wrote: >> I haven't found >> anything that talks about which form is considered to be more Pythonic >> in those situations where there's no functional difference. > > In such cases I'd probably go for type(x), because it looks less > ugly. > > x.__class__ *might* be slightly more efficient, as it avoids a > global lookup and a function call. But as always, measurement > would be required to be sure. Except that we don't know if "efficiency" - whatever that might mean here - matters at all. -- https://mail.python.org/mailman/listinfo/python-list From Keith.S.Thompson+u at gmail.com Thu Mar 2 19:18:18 2023 From: Keith.S.Thompson+u at gmail.com (Keith Thompson) Date: Thu, 02 Mar 2023 16:18:18 -0800 Subject: Python 3.10 Fizzbuzz References: <87v8qaxyna.fsf@nightsong.com> <749b4375-9dd4-99e1-19bc-dbc90fc068bc@btinternet.com> <14355d71-81af-422b-9d80-68768cd9bb2e@DancesWithMice.info> <00ef01d94bb8$5d71e030$1855a090$@gmail.com> <20230301105509.GA24525@bleah.co.uk> <5da41979-c250-6614-cd84-0e13ecb459b4@shentel.net> Message-ID: <87mt4un0vp.fsf@nosuchdomain.example.com> Greg Ewing writes: > On 2/03/23 10:59 am, gene heskett wrote: >> Human skin always has the same color > > Um... no? You took that out of context. The assertion was that "Human skin always has the same color" and "the difference is not the color, but the brightness". I offer no opinion on whether that's accurate. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u at gmail.com Working, but not speaking, for XCOM Labs void Void(void) { Void(); } /* The recursive call of the void */ From jicman at gmail.com Thu Mar 2 20:06:59 2023 From: jicman at gmail.com (jose isaias cabrera) Date: Thu, 2 Mar 2023 20:06:59 -0500 Subject: Regular Expression bug? In-Reply-To: <0556af4d-279d-8bf0-973d-54ea5e30f764@wichmann.us> References: <0556af4d-279d-8bf0-973d-54ea5e30f764@wichmann.us> Message-ID: On Thu, Mar 2, 2023 at 2:38?PM Mats Wichmann wrote: > > On 3/2/23 12:28, Chris Angelico wrote: > > On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera wrote: > >> > >> Greetings. > >> > >> For the RegExp Gurus, consider the following python3 code: > >> > >> import re > >> s = "pn=align upgrade sd=2023-02-" > >> ro = re.compile(r"pn=(.+) ") > >> r0=ro.match(s) > >>>>> print(r0.group(1)) > >> align upgrade > >> > >> > >> This is wrong. It should be 'align' because the group only goes up-to > >> the space. Thoughts? Thanks. > >> > > > > Not a bug. Find the longest possible match that fits this; as long as > > you can find a space immediately after it, everything in between goes > > into the .+ part. > > > > If you want to exclude spaces, either use [^ ]+ or .+?. > > https://docs.python.org/3/howto/regex.html#greedy-versus-non-greedy This re is a bit different than the one I am used. So, I am trying to match everything after 'pn=': import re s = "pm=jose pn=2017" m0 = r"pn=(.+)" r0 = re.compile(m0) s0 = r0.match(s) >>> print(s0) None Any help is appreciated. From avi.e.gross at gmail.com Thu Mar 2 20:35:12 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 2 Mar 2023 20:35:12 -0500 Subject: Regular Expression bug? In-Reply-To: References: <0556af4d-279d-8bf0-973d-54ea5e30f764@wichmann.us> Message-ID: <006401d94d70$662e0c30$328a2490$@gmail.com> It is a well-known fact, Jose, that GIGO. The letters "n" and "m" are not interchangeable. Your pattern fails because you have "pn" in one place and "pm" in the other. >>> s = "pn=jose pn=2017" ... >>> s0 = r0.match(s) >>> s0 -----Original Message----- From: Python-list On Behalf Of jose isaias cabrera Sent: Thursday, March 2, 2023 8:07 PM To: Mats Wichmann Cc: python-list at python.org Subject: Re: Regular Expression bug? On Thu, Mar 2, 2023 at 2:38?PM Mats Wichmann wrote: > > On 3/2/23 12:28, Chris Angelico wrote: > > On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera wrote: > >> > >> Greetings. > >> > >> For the RegExp Gurus, consider the following python3 code: > >> > >> import re > >> s = "pn=align upgrade sd=2023-02-" > >> ro = re.compile(r"pn=(.+) ") > >> r0=ro.match(s) > >>>>> print(r0.group(1)) > >> align upgrade > >> > >> > >> This is wrong. It should be 'align' because the group only goes up-to > >> the space. Thoughts? Thanks. > >> > > > > Not a bug. Find the longest possible match that fits this; as long as > > you can find a space immediately after it, everything in between goes > > into the .+ part. > > > > If you want to exclude spaces, either use [^ ]+ or .+?. > > https://docs.python.org/3/howto/regex.html#greedy-versus-non-greedy This re is a bit different than the one I am used. So, I am trying to match everything after 'pn=': import re s = "pm=jose pn=2017" m0 = r"pn=(.+)" r0 = re.compile(m0) s0 = r0.match(s) >>> print(s0) None Any help is appreciated. -- https://mail.python.org/mailman/listinfo/python-list From cs at cskk.id.au Thu Mar 2 20:30:45 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 3 Mar 2023 12:30:45 +1100 Subject: Regular Expression bug? In-Reply-To: References: Message-ID: On 02Mar2023 20:06, jose isaias cabrera wrote: >This re is a bit different than the one I am used. So, I am trying to >match >everything after 'pn=': > >import re >s = "pm=jose pn=2017" >m0 = r"pn=(.+)" >r0 = re.compile(m0) >s0 = r0.match(s) `match()` matches at the start of the string. You want r0.search(s). - Cameron Simpson From alan at csail.mit.edu Thu Mar 2 20:48:52 2023 From: alan at csail.mit.edu (Alan Bawden) Date: Thu, 02 Mar 2023 20:48:52 -0500 Subject: Regular Expression bug? References: <0556af4d-279d-8bf0-973d-54ea5e30f764@wichmann.us> Message-ID: <86mt4uwqnv.fsf@williamsburg.bawden.org> jose isaias cabrera writes: On Thu, Mar 2, 2023 at 2:38?PM Mats Wichmann wrote: This re is a bit different than the one I am used. So, I am trying to match everything after 'pn=': import re s = "pm=jose pn=2017" m0 = r"pn=(.+)" r0 = re.compile(m0) s0 = r0.match(s) >>> print(s0) None Assuming that you were expecting to match "pn=2017", then you probably don't want the 'match' method. Read its documentation. Then read the documentation for the _other_ methods that a Pattern supports. Then you will be enlightened. - Alan From jicman at gmail.com Thu Mar 2 22:27:13 2023 From: jicman at gmail.com (jose isaias cabrera) Date: Thu, 2 Mar 2023 22:27:13 -0500 Subject: Regular Expression bug? In-Reply-To: References: Message-ID: On Thu, Mar 2, 2023 at 8:30 PM Cameron Simpson wrote: > > On 02Mar2023 20:06, jose isaias cabrera wrote: > >This re is a bit different than the one I am used. So, I am trying to > >match > >everything after 'pn=': > > > >import re > >s = "pm=jose pn=2017" > >m0 = r"pn=(.+)" > >r0 = re.compile(m0) > >s0 = r0.match(s) > > `match()` matches at the start of the string. You want r0.search(s). > - Cameron Simpson Thanks. Darn it! I knew it was something simple. -- What if eternity is real? Where will you spend it? Hmmmm... From jicman at gmail.com Thu Mar 2 22:35:13 2023 From: jicman at gmail.com (jose isaias cabrera) Date: Thu, 2 Mar 2023 22:35:13 -0500 Subject: Regular Expression bug? In-Reply-To: <006401d94d70$662e0c30$328a2490$@gmail.com> References: <0556af4d-279d-8bf0-973d-54ea5e30f764@wichmann.us> <006401d94d70$662e0c30$328a2490$@gmail.com> Message-ID: On Thu, Mar 2, 2023 at 8:35 PM wrote: > > It is a well-known fact, Jose, that GIGO. > > The letters "n" and "m" are not interchangeable. Your pattern fails because you have "pn" in one place and "pm" in the other. It is not GIGO. pm=project manager. pn=project name. I needed search() rather than match(). > > >>> s = "pn=jose pn=2017" > ... > >>> s0 = r0.match(s) > >>> s0 > > > > > -----Original Message----- > From: Python-list On Behalf Of jose isaias cabrera > Sent: Thursday, March 2, 2023 8:07 PM > To: Mats Wichmann > Cc: python-list at python.org > Subject: Re: Regular Expression bug? > > On Thu, Mar 2, 2023 at 2:38?PM Mats Wichmann wrote: > > > > On 3/2/23 12:28, Chris Angelico wrote: > > > On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera > wrote: > > >> > > >> Greetings. > > >> > > >> For the RegExp Gurus, consider the following python3 code: > > >> > > >> import re > > >> s = "pn=align upgrade sd=2023-02-" > > >> ro = re.compile(r"pn=(.+) ") > > >> r0=ro.match(s) > > >>>>> print(r0.group(1)) > > >> align upgrade > > >> > > >> > > >> This is wrong. It should be 'align' because the group only goes up-to > > >> the space. Thoughts? Thanks. > > >> > > > > > > Not a bug. Find the longest possible match that fits this; as long as > > > you can find a space immediately after it, everything in between goes > > > into the .+ part. > > > > > > If you want to exclude spaces, either use [^ ]+ or .+?. > > > > https://docs.python.org/3/howto/regex.html#greedy-versus-non-greedy > > This re is a bit different than the one I am used. So, I am trying to match > everything after 'pn=': > > import re > s = "pm=jose pn=2017" > m0 = r"pn=(.+)" > r0 = re.compile(m0) > s0 = r0.match(s) > >>> print(s0) > None > > Any help is appreciated. > -- > https://mail.python.org/mailman/listinfo/python-list > -- What if eternity is real? Where will you spend it? Hmmmm... From jicman at gmail.com Thu Mar 2 22:36:52 2023 From: jicman at gmail.com (jose isaias cabrera) Date: Thu, 2 Mar 2023 22:36:52 -0500 Subject: Regular Expression bug? In-Reply-To: <86mt4uwqnv.fsf@williamsburg.bawden.org> References: <0556af4d-279d-8bf0-973d-54ea5e30f764@wichmann.us> <86mt4uwqnv.fsf@williamsburg.bawden.org> Message-ID: On Thu, Mar 2, 2023 at 9:56 PM Alan Bawden wrote: > > jose isaias cabrera writes: > > On Thu, Mar 2, 2023 at 2:38?PM Mats Wichmann wrote: > > This re is a bit different than the one I am used. So, I am trying to match > everything after 'pn=': > > import re > s = "pm=jose pn=2017" > m0 = r"pn=(.+)" > r0 = re.compile(m0) > s0 = r0.match(s) > >>> print(s0) > None > > Assuming that you were expecting to match "pn=2017", then you probably > don't want the 'match' method. Read its documentation. Then read the > documentation for the _other_ methods that a Pattern supports. Then you > will be enlightened. Yes. I need search. Thanks. -- What if eternity is real? Where will you spend it? Hmmmm... From learn2program at gmail.com Fri Mar 3 04:43:10 2023 From: learn2program at gmail.com (Alan Gauld) Date: Fri, 3 Mar 2023 09:43:10 +0000 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: References: Message-ID: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> On 02/03/2023 20:54, Ian Pilcher wrote: > Seems like an FAQ, and I've found a few things on StackOverflow that > discuss the technical differences in edge cases, but I haven't found > anything that talks about which form is considered to be more Pythonic > in those situations where there's no functional difference. I think avoiding dunder methods is generally considered more Pythonic. But in this specific case using isinstance() is almost always the better option. Testing for a specific class is likely to break down in the face of subclasses. And in Python testing for static types should rarely be necessary since Python uses duck typing and limiting things to a hard type seriously restricts your code. -- 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 rosuav at gmail.com Fri Mar 3 06:32:20 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Mar 2023 22:32:20 +1100 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> Message-ID: On Fri, 3 Mar 2023 at 20:44, Alan Gauld wrote: > > On 02/03/2023 20:54, Ian Pilcher wrote: > > Seems like an FAQ, and I've found a few things on StackOverflow that > > discuss the technical differences in edge cases, but I haven't found > > anything that talks about which form is considered to be more Pythonic > > in those situations where there's no functional difference. > > I think avoiding dunder methods is generally considered more Pythonic. > > But in this specific case using isinstance() is almost always > the better option. Testing for a specific class is likely to break > down in the face of subclasses. And in Python testing for static types > should rarely be necessary since Python uses duck typing > and limiting things to a hard type seriously restricts your code. > Using isinstance is very different from querying the type of an object though. They're used for different purposes. And obj.__class__ and type(obj) are different too, which is why the OP specifically narrowed this down to the situations where you know they're the same. Personally, I'd probably use type(obj) if the distinction doesn't matter, but that's nothing more than personal preference. ChrisA From guenther.sohler at gmail.com Fri Mar 3 03:22:55 2023 From: guenther.sohler at gmail.com (Guenther Sohler) Date: Fri, 3 Mar 2023 09:22:55 +0100 Subject: Python list insert iterators Message-ID: Hi Python community, I have a got an example list like 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 T T and i eventually want to insert items in the given locations (A shall go between 2 and 3, B shall go between 6 and 7) Right now i just use index numbers to define the place: A shall insert in position 2 B shall insert in position 6 However when i insert A in position 2, the index for successful insertion of B gets wrong (should now be 7 instead of 6) No, it's not an option to sort the indexes and start inserting from the back. The most elegant option is not to store indexes, but list iterators, which attach to the list element and would automatically move, especially if an element is inserted before. I could not find such functionality in python lists of [ 1,2,3 ] Does python have such functionality ? if yes, where can i find it ? From ethan at stoneleaf.us Fri Mar 3 12:50:40 2023 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 3 Mar 2023 09:50:40 -0800 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> Message-ID: On 3/3/23 03:32, Chris Angelico wrote: > On Fri, 3 Mar 2023 at 20:44, Alan Gauld wrote: >> On 02/03/2023 20:54, Ian Pilcher wrote: >>> Seems like an FAQ, and I've found a few things on StackOverflow that >>> discuss the technical differences in edge cases, but I haven't found >>> anything that talks about which form is considered to be more Pythonic >>> in those situations where there's no functional difference. >> >> I think avoiding dunder methods is generally considered more Pythonic. Outside of writing dunder methods, I tend to agree. >> But in this specific case using isinstance() is almost always >> the better option. True. IIRC, the only time I haven't used `isinstance` is in `Enum`, where a particular object has to be exactly a tuple (not a namedtuple, for example) to work correctly. > Using isinstance is very different from querying the type of an object > though. They're used for different purposes. And obj.__class__ and > type(obj) are different too, which is why the OP specifically narrowed > this down to the situations where you know they're the same. When writing classes and subclasses, I use `obj.__class__`, `isinstance` otherwise, and rarely `type(obj)` (and then mostly with `tuple`s, as they're special). ~Ethan~ From list1 at tompassin.net Fri Mar 3 13:03:35 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 3 Mar 2023 13:03:35 -0500 Subject: Python list insert iterators In-Reply-To: References: Message-ID: <608bdab8-4ea4-970a-f6ea-3aed9f905a2e@tompassin.net> On 3/3/2023 3:22 AM, Guenther Sohler wrote: > Hi Python community, > > I have a got an example list like > > 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 > T T > > and i eventually want to insert items in the given locations > (A shall go between 2 and 3, B shall go between 6 and 7) > > Right now i just use index numbers to define the place: > > A shall insert in position 2 > B shall insert in position 6 > > However when i insert A in position 2, the index for successful insertion > of B gets wrong > (should now be 7 instead of 6) > > No, it's not an option to sort the indexes and start inserting from the > back. > The most elegant option is not to store indexes, but list iterators, which > attach to the list element > and would automatically move, especially if an element is inserted before. > > I could not find such functionality in python lists of [ 1,2,3 ] > > Does python have such functionality ? > if yes, where can i find it ? You should be more clear about how to establish the desired insertion point. In your example, you first say that the insertion of B should be between 6 and 7. But after A gets inserted, you say that B's insertion point should change. How is anyone able to know what the correct insertion point should be at any time? If the rule is that B should get inserted after a particular known element, you can find out the index of that element with list.index() and insert just after that. If the rule is "There is an imaginary location that starts out after index 6 but moves depending on previous insertions", then you will probably need to capture a record of those insertions and use it to adjust the invisible insertion point. But this synchronization could be tricky to keep correct depending on what you want to do to this list. So you need to specify clearly what the rules are going to be. From avi.e.gross at gmail.com Fri Mar 3 13:51:11 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Fri, 3 Mar 2023 13:51:11 -0500 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> Message-ID: <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> Alan, I do not buy into any concept about something being pythonic or not. Python has grown too vast and innovated quite a bit, but also borrowed from others and vice versa. There generally is no universally pythonic way nor should there be. Is there a C way and then a C++ way and an R way or JavaScript or does only python a language with a philosophy of what is the pythonic way? My vague impression was that the pythonic way was somewhat of a contrast to the way a programmer did it before coming to python. So some would argue that although python allows loops, that some things are more naturally done in python using a list comprehension. Really? I suggest that NOW for some people, it is way more natural to import modules like numpy and pandas and use their tools using a more vectorized approach. Is that the new pythonic in some situations? I can also argue that if you were a contestant on Jeopardy and were in a category for computer languages and were shown some computer code and asked to name that language in 4 lines, then the most pythonic would not be one saying type(var) but the one showing a dunder method! I mean what makes some languages special is often the underlying details! On the surface, many look fairly similar. Some problems not only can be solved many ways in python, but by using combinations of different programming paradigms. It can be argued by some that the pythonic way is to use some forms of object-oriented programming and by others pushing for a more functional approach. Some seem to continue pushing for efficiency and others relish at using up CPU cycles and prefer other considerations such as what is easier for the programmer or that is more self-documenting. My answer remains, in this case, like yours. The dunder methods are generally meant to be implementation details mostly visible when creating new classes or perhaps adjusting an object. They largely implement otherwise invisible protocols by providing the hooks the protocols invoke, and do it in a somewhat reserved name space. If the user is writing code that just uses existing classes, generally no dunderheads should be seen. I think using them is not only not pythonic, but risks breaking code if some changes to python are made. As one example, the iteration protocol now has new dunder methods added to be used for asynchronous and calling the __iter__() type methods will not work well and you now need to know to call the new ones. Or, don't call them at all and use the regular functions provided. Some things may be clearly more in the spirit of the language and sometimes who cares. Consider the debate that since python allows you to fail and catch an exception, why bother using if statements such as checking for no-zero before dividing. I never understood that. Plan A works. Now you can also chose plan B. They both work. But has anyone asked some dumb questions about the data the code is working on? What if you have data full of zeroes or NA or Inf or other things make a division problematic. What is the cost of testing for something or a group of things every time versus setting up a try/catch every time? What about lots of nesting of these things. What can humans read better or make adjustments to? In my mind, if the bad thing you want to avoid is rare and the testing is costly, perhaps the exception method is best. I mean if you are working with large numbers where primes are not common, then having to test if it is a prime can be costly while catching a failure may be less so. But consider how some people act as if pythonic means you should not care about efficiency! LOL! I leave you with the question of the day. Was Voldemort pythonic? Avi -----Original Message----- From: Python-list On Behalf Of Alan Gauld Sent: Friday, March 3, 2023 4:43 AM To: python-list at python.org Subject: Re: Which more Pythonic - self.__class__ or type(self)? On 02/03/2023 20:54, Ian Pilcher wrote: > Seems like an FAQ, and I've found a few things on StackOverflow that > discuss the technical differences in edge cases, but I haven't found > anything that talks about which form is considered to be more Pythonic > in those situations where there's no functional difference. I think avoiding dunder methods is generally considered more Pythonic. But in this specific case using isinstance() is almost always the better option. Testing for a specific class is likely to break down in the face of subclasses. And in Python testing for static types should rarely be necessary since Python uses duck typing and limiting things to a hard type seriously restricts your code. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list From avi.e.gross at gmail.com Fri Mar 3 14:16:46 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Fri, 3 Mar 2023 14:16:46 -0500 Subject: Python list insert iterators In-Reply-To: <608bdab8-4ea4-970a-f6ea-3aed9f905a2e@tompassin.net> References: <608bdab8-4ea4-970a-f6ea-3aed9f905a2e@tompassin.net> Message-ID: <006501d94e04$b2f13c10$18d3b430$@gmail.com> Thomas is correct that this is a bit of an odd request unless explained better. There are a number of implicit assumptions that need to be revisited here. Python Lists are what they are. They are not in any way tagged. They are not linked lists or binary trees or dictionaries or whatever you are looking for. They are a mutable object with an order at any given time and no memory or history of an earlier status. They support not just insertion but also deletion and replacement and other things. But generally, if your time span between deciding on additions and implementing them will contain no deletions, then one simple solution is to re-order your insertion to always do the last one first. The indices will only change at and above an insertion point. Your remaining insertions will always be at an untouched region where the indices remain the same, for now. A second choice as Thomas points out is to adjust your indices. An example might be if you have a collection of proposed insertions and each contains an index number and payload. Each time you insert the next payload at the insertion point, you invoke a function that goes through your remaining Collection and finds any with an index that is higher and increments it. Obviously there are issues if dealing with adding multiple times to the same index or adding multiple items at once. The above could be encapsulated in some kind of VIEW in some languages including of course some that use pointers. I will add by pointing out a way to do a multi-insertion at once if you know all the insertions at the same time. Take your list that you want to change by adding at say positions 9, 3 and 6. Now DON"T insert anything. Forget the concept. Instead, and this is drastic, make a NEW list. The new list is loosely old[0:2] + new_at_3 + old[3:5] + new_at_6 + old[6:8] +new_at_9 + old[9:] Something carefully written like that using concatenation means you do not lose track of indices and end up with a new extended list you can feel free to save under the old name and let the prior one be garbage collected. Maybe one of the above hints at what could work for you, or others may supply a better answer, or maybe you reevaluate what you are doing or explain it some more. -----Original Message----- From: Python-list On Behalf Of Thomas Passin Sent: Friday, March 3, 2023 1:04 PM To: python-list at python.org Subject: Re: Python list insert iterators On 3/3/2023 3:22 AM, Guenther Sohler wrote: > Hi Python community, > > I have a got an example list like > > 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 > T T > > and i eventually want to insert items in the given locations > (A shall go between 2 and 3, B shall go between 6 and 7) > > Right now i just use index numbers to define the place: > > A shall insert in position 2 > B shall insert in position 6 > > However when i insert A in position 2, the index for successful insertion > of B gets wrong > (should now be 7 instead of 6) > > No, it's not an option to sort the indexes and start inserting from the > back. > The most elegant option is not to store indexes, but list iterators, which > attach to the list element > and would automatically move, especially if an element is inserted before. > > I could not find such functionality in python lists of [ 1,2,3 ] > > Does python have such functionality ? > if yes, where can i find it ? You should be more clear about how to establish the desired insertion point. In your example, you first say that the insertion of B should be between 6 and 7. But after A gets inserted, you say that B's insertion point should change. How is anyone able to know what the correct insertion point should be at any time? If the rule is that B should get inserted after a particular known element, you can find out the index of that element with list.index() and insert just after that. If the rule is "There is an imaginary location that starts out after index 6 but moves depending on previous insertions", then you will probably need to capture a record of those insertions and use it to adjust the invisible insertion point. But this synchronization could be tricky to keep correct depending on what you want to do to this list. So you need to specify clearly what the rules are going to be. -- https://mail.python.org/mailman/listinfo/python-list From PythonList at DancesWithMice.info Fri Mar 3 16:47:40 2023 From: PythonList at DancesWithMice.info (dn) Date: Sat, 4 Mar 2023 10:47:40 +1300 Subject: Python list insert iterators In-Reply-To: References: Message-ID: <9431f0c1-5b90-1e63-04ef-7201bbfec0b4@DancesWithMice.info> On 03/03/2023 21.22, Guenther Sohler wrote: > Hi Python community, > > I have a got an example list like > > 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 > T T > > and i eventually want to insert items in the given locations > (A shall go between 2 and 3, B shall go between 6 and 7) > > Right now i just use index numbers to define the place: > > A shall insert in position 2 > B shall insert in position 6 > > However when i insert A in position 2, the index for successful insertion > of B gets wrong > (should now be 7 instead of 6) The danger here is using the index to have meaning beyond its function (a position relative to the beginning/end). > No, it's not an option to sort the indexes and start inserting from the > back. Without explaining this criteria (and any others), suggestions can only be guesses! > The most elegant option is not to store indexes, but list iterators, which > attach to the list element > and would automatically move, especially if an element is inserted before. > > I could not find such functionality in python lists of [ 1,2,3 ] So, if list doesn't float-your-boat, what about moving to something else? > Does python have such functionality ? > if yes, where can i find it ? dict - where the keys indicate relative position linked-list (https://en.wikipedia.org/wiki/Linked_list) where each value is accompanied by a "pointer" which addresses the next value by-index; and insertion/deletion is possible by exchanging pointers. -- Regards, =dn From alan at csail.mit.edu Fri Mar 3 18:26:32 2023 From: alan at csail.mit.edu (Alan Bawden) Date: Fri, 03 Mar 2023 18:26:32 -0500 Subject: Python list insert iterators References: Message-ID: <86ilfhwh5j.fsf@williamsburg.bawden.org> Guenther Sohler writes: Hi Python community, I have a got an example list like 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 T T and i eventually want to insert items in the given locations (A shall go between 2 and 3, B shall go between 6 and 7) Right now i just use index numbers to define the place: A shall insert in position 2 B shall insert in position 6 However when i insert A in position 2, the index for successful insertion of B gets wrong (should now be 7 instead of 6) No, it's not an option to sort the indexes and start inserting from the back. If you are definitely inserting from the front, then you can use negative indexes, since the positions relative to the end of the list won't be changing. If you must insert in a random order, that won't help, but you haven't told us what your real constraints are. From greg.ewing at canterbury.ac.nz Fri Mar 3 19:20:42 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 4 Mar 2023 13:20:42 +1300 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> Message-ID: On 4/03/23 7:51 am, avi.e.gross at gmail.com wrote: > I leave you with the question of the day. Was Voldemort pythonic? Well, he was fluent in Parseltongue, which is not a good sign. I hope not, otherwise we'll have to rename Python to "The Language That Shall Not Be Named" and watch out for horcruxes during code reviews. I'll note that he was fluent in Parseltongue, which is not a good sign. -- Greg From hjp-python at hjp.at Sat Mar 4 02:47:32 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 4 Mar 2023 08:47:32 +0100 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> Message-ID: <20230304074732.mdifd4r2bgfers62@hjp.at> On 2023-03-03 13:51:11 -0500, avi.e.gross at gmail.com wrote: > I do not buy into any concept about something being pythonic or not. > > Python has grown too vast and innovated quite a bit, but also borrowed from > others and vice versa. > > There generally is no universally pythonic way nor should there be. Is there > a C way Oh, yes. Definitely. > and then a C++ way and an R way or JavaScript JavaScript has a quite distinctive style. C++ is a big language (maybe too big for a single person to grok completely) so there might be several "dialects". I haven't seen enough R code to form an opinion. > or does only python a language with a philosophy of what is the > pythonic way? No. Even before Python existed there was the adage "a real programmer can write FORTRAN in any language", indicating that idiomatic usage of a language is not governed by syntax and library alone, but there is a cultural element: People writing code in a specific language also read code by other people in that language, so they start imitating each other, just like speakers of natural languages imitate each other. Someone coming from another language will often write code which is correct but un-idiomatic, and you can often guess which language they come from (they are "writing FORTRAN in Python"). Also quite similar to natural languages where you can guess the native language of an L2 speaker by their accent and phrasing. 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 gweatherby at uchc.edu Sat Mar 4 07:31:45 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Sat, 4 Mar 2023 12:31:45 +0000 Subject: Python list insert iterators In-Reply-To: References: Message-ID: Python lists are arrays in other languages. You?ll have to roll your own or find something in https://pypi.org, etc. I think this incomplete implementation does the trick. # # MIT licensed # from dataclasses import dataclass from typing import TypeVar, Generic T = TypeVar("T") @dataclass class ListNode(Generic[T]): _value: T _next: "ListNode" = None # noinspection PyProtectedMember class ListIter(Generic[T]): def __init__(self, list_: 'LinkedList', node: ListNode[T]): self._list = list_ self._node: ListNode[T] = node def __next__(self) -> T: if self._node != None: v = self._node._value self._node = self._node._next return v raise StopIteration() @property def value(self) -> T: return self._node._value def insert_after(self, value: T) -> None: self._list._insert_after(self._node, value) # noinspection PyProtectedMember class LinkedList(Generic[T]): """Singly linked List""" # noinspection PyTypeChecker def __init__(self): self._head: ListNode[T] = None self._tail: ListNode[T] = None def __iter__(self): return ListIter(self, self._head) def _insert_after(self, node: ListNode[T], value: T): if node != self._head: if node != self._tail: node._next = ListNode(value, node._next) def append(self, value: T) -> None: """Add to end of list""" if self._head != None: self._tail._next = (n := ListNode(value)) self._tail = n return self._head = self._tail = ListNode(value) def appendleft(self, value: T) -> None: """Add to beginning of list""" if self._head != None: single = self._head == self._tail self._head = (n := ListNode(value, self._head)) if single: self._tail = n return self._head = self._tail = ListNode(value) def index(self, nth: int) -> ListIter[T]: """Return iterator at nth position""" n = self._head for i in range(nth): n = n._next if n == None: raise IndexError('list index out of range') return ListIter(self, n) # # TODO: add search for value, deletion of elements, et. al. # def unit_test(): """Test basics""" linked_list = LinkedList() for i in range(1, 11): linked_list.append(i) # iteration matching equivalent list for item in zip(linked_list, [i for i in range(1, 11)]): assert (item[0] == item[1]) # verify index() method assert linked_list.index(0).value == 1 assert linked_list.index(1).value == 2 try: print(linked_list.index(11).value) assert False except IndexError: pass # test append left linked_list.appendleft(0) for item in zip(linked_list, [i for i in range(0, 12)]): assert (item[0] == item[1]) def python_mailing_list_example(): """Example from mailing list""" linked_list = LinkedList() for i in range(1, 11): linked_list.append(i) a = linked_list.index(1) print(a.value) b = linked_list.index(5) print(b.value) a.insert_after(27) b.insert_after(45) print(','.join(str(x) for x in linked_list)) unit_test() python_mailing_list_example() From: Python-list on behalf of Guenther Sohler Date: Friday, March 3, 2023 at 12:28 PM To: python-list at python.org Subject: Python list insert iterators *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Hi Python community, I have a got an example list like 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 T T and i eventually want to insert items in the given locations (A shall go between 2 and 3, B shall go between 6 and 7) Right now i just use index numbers to define the place: A shall insert in position 2 B shall insert in position 6 However when i insert A in position 2, the index for successful insertion of B gets wrong (should now be 7 instead of 6) No, it's not an option to sort the indexes and start inserting from the back. The most elegant option is not to store indexes, but list iterators, which attach to the list element and would automatically move, especially if an element is inserted before. I could not find such functionality in python lists of [ 1,2,3 ] Does python have such functionality ? if yes, where can i find it ? -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!gMAiBffu8h9N-YxV4nxLjapnR3InnNHeAbrHchQ-QoKfCHpF68yr8MKpEvXNdW1uJI3pFEXPiSvDRy9BpXAPfbP0k-Mn$ From urbangabo at gmail.com Sat Mar 4 11:38:50 2023 From: urbangabo at gmail.com (Gabor Urban) Date: Sat, 4 Mar 2023 17:38:50 +0100 Subject: Testing list sequence question Message-ID: Hi guys, I have a strange problem that I do not understand. I am testing function which returns a dictionary. The code should ensure that the keys of the dictionary are generated in a given order. I am testing the function with the standard unittest module and use the assertListEqual statement to verify the sequence. Sometimes this test fails, sometimes passes without any change neither in the code, nor in the testcase. I am using "list(myDict.keys())" to create the list of the keys of the dictionary. I am running Python 3.3 on MS Windows. Any idea why is this? Thx, Gabor -- Urb?n G?bor Linux is like a wigwam: no Gates, no Windows and an Apache inside. From roel at roelschroeven.net Sat Mar 4 11:59:32 2023 From: roel at roelschroeven.net (Roel Schroeven) Date: Sat, 4 Mar 2023 17:59:32 +0100 Subject: Testing list sequence question In-Reply-To: References: Message-ID: Gabor Urban schreef op 4/03/2023 om 17:38: > Hi guys, > > I have a strange problem that I do not understand. I am testing function > which returns a dictionary. The code should ensure that the keys of the > dictionary are generated in a given order. > > I am testing the function with the standard unittest module and use the > assertListEqual statement to verify the sequence. Sometimes this test > fails, sometimes passes without any change neither in the code, nor in the > testcase. I am using "list(myDict.keys())" to create the list of the keys > of the dictionary. > > I am running Python 3.3 on MS Windows. Any idea why is this? Prior to Python 3.6 (de facto) and Python 3.7 (officially), there was no guarantee at all about the order of keys in a dict. If you need the keys to be in the same order they were inserted, either use collections.OrderedDict or upgrade to Python 3.7 or later. -- "Life ain't no fairy tale Just give me another ale And I'll drink to Rock 'n Roll" -- Barkeep (The Scabs) From avi.e.gross at gmail.com Sat Mar 4 12:38:22 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 4 Mar 2023 12:38:22 -0500 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: <20230304074732.mdifd4r2bgfers62@hjp.at> References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> <20230304074732.mdifd4r2bgfers62@hjp.at> Message-ID: <001901d94ec0$1e587020$5b095060$@gmail.com> Peter, Of course each language has commonly used idioms as C with pointer arithmetic and code like *p++=*q++ but my point is that although I live near a seaway and from where C originated, I am not aware of words like "c-way" or "scenic" as compared to the way people keep saying "pythonic". Yes, languages develop idioms and frankly, many are replaced with time. And, yes, I am sure I can write FORTRAN style in any language as I used to teach it, but WATFOR? If the question is to show a dozen solutions for a problem written in VALID python and ask a panel of seasoned python programmers which they would prefer, then sometimes there is a more pythonic solution by that definition. Give the same test to newbies who each came from a different language background and are just getting started, and I am not sure I care how they vote! I suggest that given a dozen such choices, several may be reasonable choices and in some cases, I suggest the non-pythonic choice is the right one such as when you expect someone to port your code to other languages and you need to keep it simple. I am simply saying that for ME, some questions are not as simple as others. I am more interested in whether others can read and understand my code, and it runs without problems, and maybe even is slightly efficient, than whether someone deems it pythonic. -----Original Message----- From: Python-list On Behalf Of Peter J. Holzer Sent: Saturday, March 4, 2023 2:48 AM To: python-list at python.org Subject: Re: Which more Pythonic - self.__class__ or type(self)? On 2023-03-03 13:51:11 -0500, avi.e.gross at gmail.com wrote: > I do not buy into any concept about something being pythonic or not. > > Python has grown too vast and innovated quite a bit, but also borrowed from > others and vice versa. > > There generally is no universally pythonic way nor should there be. Is there > a C way Oh, yes. Definitely. > and then a C++ way and an R way or JavaScript JavaScript has a quite distinctive style. C++ is a big language (maybe too big for a single person to grok completely) so there might be several "dialects". I haven't seen enough R code to form an opinion. > or does only python a language with a philosophy of what is the > pythonic way? No. Even before Python existed there was the adage "a real programmer can write FORTRAN in any language", indicating that idiomatic usage of a language is not governed by syntax and library alone, but there is a cultural element: People writing code in a specific language also read code by other people in that language, so they start imitating each other, just like speakers of natural languages imitate each other. Someone coming from another language will often write code which is correct but un-idiomatic, and you can often guess which language they come from (they are "writing FORTRAN in Python"). Also quite similar to natural languages where you can guess the native language of an L2 speaker by their accent and phrasing. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" From list1 at tompassin.net Sat Mar 4 12:49:45 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 4 Mar 2023 12:49:45 -0500 Subject: Testing list sequence question In-Reply-To: References: Message-ID: <9f3a52cc-32b4-4d91-cc2d-240b6b9c3031@tompassin.net> On 3/4/2023 11:38 AM, Gabor Urban wrote: > Hi guys, > > I have a strange problem that I do not understand. I am testing function > which returns a dictionary. The code should ensure that the keys of the > dictionary are generated in a given order. > > I am testing the function with the standard unittest module and use the > assertListEqual statement to verify the sequence. Sometimes this test > fails, sometimes passes without any change neither in the code, nor in the > testcase. I am using "list(myDict.keys())" to create the list of the keys > of the dictionary. > > I am running Python 3.3 on MS Windows. Any idea why is this? List order would not be guaranteed. Sort the list first. Then your problem should clear up. From list1 at tompassin.net Sat Mar 4 13:09:22 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 4 Mar 2023 13:09:22 -0500 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: <20230304074732.mdifd4r2bgfers62@hjp.at> References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> <20230304074732.mdifd4r2bgfers62@hjp.at> Message-ID: On 3/4/2023 2:47 AM, Peter J. Holzer wrote: > Even before Python existed there was the adage "a real programmer > can write FORTRAN in any language", indicating that idiomatic usage of a > language is not governed by syntax and library alone, but there is a > cultural element: People writing code in a specific language also read > code by other people in that language, so they start imitating each > other, just like speakers of natural languages imitate each other. > Someone coming from another language will often write code which is > correct but un-idiomatic, and you can often guess which language they > come from (they are "writing FORTRAN in Python"). What Peter didn't say is that this statement is usually used in a disparaging sense. It tends to imply that a person can write (or is writing) awkward or inappropriate code anywhere. From PythonList at DancesWithMice.info Sat Mar 4 13:25:43 2023 From: PythonList at DancesWithMice.info (dn) Date: Sun, 5 Mar 2023 07:25:43 +1300 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: <20230304074732.mdifd4r2bgfers62@hjp.at> References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> <20230304074732.mdifd4r2bgfers62@hjp.at> Message-ID: <0c001cf9-f914-ece0-e35d-edffcddf4c7e@DancesWithMice.info> On 04/03/2023 20.47, Peter J. Holzer wrote: > On 2023-03-03 13:51:11 -0500, avi.e.gross at gmail.com wrote: ... > No. Even before Python existed there was the adage "a real programmer > can write FORTRAN in any language", indicating that idiomatic usage of a > language is not governed by syntax and library alone, but there is a > cultural element: People writing code in a specific language also read > code by other people in that language, so they start imitating each > other, just like speakers of natural languages imitate each other. > Someone coming from another language will often write code which is > correct but un-idiomatic, and you can often guess which language they > come from (they are "writing FORTRAN in Python"). Also quite similar to > natural languages where you can guess the native language of an L2 > speaker by their accent and phrasing. With ph agree I do... or do you want that in a DO-loop with a FORMAT? -- Regards, =dn From learn2program at gmail.com Sat Mar 4 13:37:34 2023 From: learn2program at gmail.com (Alan Gauld) Date: Sat, 4 Mar 2023 18:37:34 +0000 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: <001901d94ec0$1e587020$5b095060$@gmail.com> References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> <20230304074732.mdifd4r2bgfers62@hjp.at> <001901d94ec0$1e587020$5b095060$@gmail.com> Message-ID: On 04/03/2023 17:38, avi.e.gross at gmail.com wrote: > > Of course each language has commonly used idioms > That's the point, the correct term is probably "idiomatic" rather than "pythonic" but it is a defacto standard that idiomatic Python has become known as Pythonic. I don't think that's a problem. And at least we aren't in the C++ situation where almost everything that was idiomatic up until 1999 is now deemed an anti-pattern and they have standard library modules to try and guide you to use the "correct" idioms! But being Pythonic is still a much more loose term and the community less stressed about it than their C++ cousins where it has almost reached a religious fervour! -- 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 roel at roelschroeven.net Sat Mar 4 13:42:37 2023 From: roel at roelschroeven.net (Roel Schroeven) Date: Sat, 4 Mar 2023 19:42:37 +0100 Subject: Testing list sequence question In-Reply-To: <9f3a52cc-32b4-4d91-cc2d-240b6b9c3031@tompassin.net> References: <9f3a52cc-32b4-4d91-cc2d-240b6b9c3031@tompassin.net> Message-ID: <18fa4330-6308-c7e3-bed4-293f0458b7f0@roelschroeven.net> Thomas Passin schreef op 4/03/2023 om 18:49: > On 3/4/2023 11:38 AM, Gabor Urban wrote: > > Hi guys, > > > > I have a strange problem that I do not understand. I am testing function > > which returns a dictionary. The code should ensure that the keys of the > > dictionary are generated in a given order. > > > > I am testing the function with the standard unittest module and use the > > assertListEqual statement to verify the sequence. Sometimes this test > > fails, sometimes passes without any change neither in the code, nor in the > > testcase. I am using "list(myDict.keys())" to create the list of the keys > > of the dictionary. > > > > I am running Python 3.3 on MS Windows. Any idea why is this? > > List order would not be guaranteed. Sort the list first. Then your > problem should clear up. How would that enable you to check that the keys in the dict are in a specific order? -- "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sat Mar 4 14:37:51 2023 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 5 Mar 2023 06:37:51 +1100 Subject: Testing list sequence question In-Reply-To: <18fa4330-6308-c7e3-bed4-293f0458b7f0@roelschroeven.net> References: <9f3a52cc-32b4-4d91-cc2d-240b6b9c3031@tompassin.net> <18fa4330-6308-c7e3-bed4-293f0458b7f0@roelschroeven.net> Message-ID: On Sun, 5 Mar 2023 at 05:44, Roel Schroeven wrote: > > Thomas Passin schreef op 4/03/2023 om 18:49: > > On 3/4/2023 11:38 AM, Gabor Urban wrote: > > > Hi guys, > > > > > > I have a strange problem that I do not understand. I am testing function > > > which returns a dictionary. The code should ensure that the keys of the > > > dictionary are generated in a given order. > > > > > > I am testing the function with the standard unittest module and use the > > > assertListEqual statement to verify the sequence. Sometimes this test > > > fails, sometimes passes without any change neither in the code, nor in the > > > testcase. I am using "list(myDict.keys())" to create the list of the keys > > > of the dictionary. > > > > > > I am running Python 3.3 on MS Windows. Any idea why is this? > > > > List order would not be guaranteed. Sort the list first. Then your > > problem should clear up. > How would that enable you to check that the keys in the dict are in a > specific order? > In Python 3.3, the keys in a dict are not in a specific order. There is nothing to test. ChrisA From list1 at tompassin.net Sat Mar 4 14:59:42 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 4 Mar 2023 14:59:42 -0500 Subject: Testing list sequence question In-Reply-To: <18fa4330-6308-c7e3-bed4-293f0458b7f0@roelschroeven.net> References: <9f3a52cc-32b4-4d91-cc2d-240b6b9c3031@tompassin.net> <18fa4330-6308-c7e3-bed4-293f0458b7f0@roelschroeven.net> Message-ID: <66f42701-3145-5821-38e9-443dc903bb03@tompassin.net> On 3/4/2023 1:42 PM, Roel Schroeven wrote: > Thomas Passin schreef op 4/03/2023 om 18:49: >> On 3/4/2023 11:38 AM, Gabor Urban wrote: >> >?? Hi guys, >> > > I have a strange problem that I do not understand. I am testing >> function >> > which returns a dictionary. The code should ensure that the keys of the >> > dictionary are generated in a given order. >> > > I am testing the function with the standard unittest module and >> use the >> > assertListEqual statement to verify the sequence. Sometimes this test >> > fails, sometimes passes without any change neither in the code, nor >> in the >> > testcase. I am using "list(myDict.keys())" to create the list of the >> keys >> > of the dictionary. >> > > I am running Python 3.3 on MS Windows. Any idea why is this? >> >> List order would not be guaranteed.? Sort the list first.? Then your >> problem should clear up. > How would that enable you to check that the keys in the dict are in a > specific order? I probably misunderstood. I thought you needed a list of keys in a reproducible order, which sorting the list would achieve. Let's back up. Why do you care about having the keys in some particular order? And what is that order? Perhaps some other code design will satisfy the real purpose. Otherwise, in Python 3.7 and up dicts maintain the insertion order of the keys. If you cannot use those versions of Python for some reason, here's a python 2.7-compatible backport of an ordered dictionary that you could probably adapt: https://code.activestate.com/recipes/576693/ But note: "Dictionaries compare equal if and only if they have the same (key, value) pairs (regardless of ordering)" (from the Python docs). If the order you want is not the original insertion order, then you will perhaps need to adapt the ordered dict idea to your needs. From hjp-python at hjp.at Sat Mar 4 16:17:13 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 4 Mar 2023 22:17:13 +0100 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: <001901d94ec0$1e587020$5b095060$@gmail.com> References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> <20230304074732.mdifd4r2bgfers62@hjp.at> <001901d94ec0$1e587020$5b095060$@gmail.com> Message-ID: <20230304211713.ndd5qyfpt5nod6ii@hjp.at> On 2023-03-04 12:38:22 -0500, avi.e.gross at gmail.com wrote: > Of course each language has commonly used idioms as C with pointer > arithmetic and code like *p++=*q++ but my point is that although I live near > a seaway and from where C originated, I am not aware of words like "c-way" > or "scenic" as compared to the way people keep saying "pythonic". Oh, you're talking about the term, not the concept? You may have something there. I remember lots of discussions about "idiomatic C" or "idiomatic Perl", but not about "C-nic" (nice pun, btw) or "Perlish" code. The Python community may be unique in having invented an adjective for that. 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 avi.e.gross at gmail.com Sat Mar 4 16:18:37 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 4 Mar 2023 16:18:37 -0500 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> <20230304074732.mdifd4r2bgfers62@hjp.at> Message-ID: <002101d94ede$e31daf60$a9590e20$@gmail.com> I don't know, Thomas. For some simple programs, there is some evolutionary benefit by starting with what you know and gradually growing from there. He first time you need to do something that seems to need a loop in python, there are loops to choose from. But as noted in a recent discussion, things are NOT NECESSARILY the same even with something that simple. Did your previous languages retain something like the loop variable outside the loop? What are your new scoping rules? Do you really want to keep using global variables, and so on. And, another biggie is people who just don't seem aware of what comes easily in the new language. I have seen people from primitive environments set up programs with multiple arrays they process the hard way instead of using some forms of structure like a named tuple or class arranged in lists or use a multidimensional numpy/pandas kind of data structure. So ignoring the word pythonic as too specific, is there a way to say that something is the way your current language supports more naturally? Yes, there are sort of fingerprints in how people write. Take the python concept of truthy and how some people will still typically add a test for equality with True. That may not be pythonic to some but is there much harm in being explicit so anyone reading the code better understands what it doe? I have to wonder what others make of my code as my style is likely to be considered closer to "eclectic" as I came to python late and found an expanding language with way too many ways to do anything and can choose. But I claim that too is pythonic! -----Original Message----- From: Python-list On Behalf Of Thomas Passin Sent: Saturday, March 4, 2023 1:09 PM To: python-list at python.org Subject: Re: Which more Pythonic - self.__class__ or type(self)? On 3/4/2023 2:47 AM, Peter J. Holzer wrote: > Even before Python existed there was the adage "a real programmer > can write FORTRAN in any language", indicating that idiomatic usage of a > language is not governed by syntax and library alone, but there is a > cultural element: People writing code in a specific language also read > code by other people in that language, so they start imitating each > other, just like speakers of natural languages imitate each other. > Someone coming from another language will often write code which is > correct but un-idiomatic, and you can often guess which language they > come from (they are "writing FORTRAN in Python"). What Peter didn't say is that this statement is usually used in a disparaging sense. It tends to imply that a person can write (or is writing) awkward or inappropriate code anywhere. -- https://mail.python.org/mailman/listinfo/python-list From avi.e.gross at gmail.com Sat Mar 4 16:25:42 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 4 Mar 2023 16:25:42 -0500 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: <0c001cf9-f914-ece0-e35d-edffcddf4c7e@DancesWithMice.info> References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> <20230304074732.mdifd4r2bgfers62@hjp.at> <0c001cf9-f914-ece0-e35d-edffcddf4c7e@DancesWithMice.info> Message-ID: <002301d94edf$e03c44e0$a0b4cea0$@gmail.com> Great idea, DN! A whole series of books can be written such as: - Python for virgin dummies who never programmed before. - Python for former BASIC programmers - Python for former LISP programmers with a forked tongue - Python for former Ada Programmers - Python for ... - Python for those who find a dozen former languages are simply not enough. - Python for people who really want to mainly use the modules like pandas or sklearn ... - Pythonic upgrades to the methods used in former inferior languages ... - How to speak with a Pythonese accent and lose you old accent based on your former native language(s). I am sure some books along these lines have already been written! Who wants to collaborate? -----Original Message----- From: Python-list On Behalf Of dn via Python-list Sent: Saturday, March 4, 2023 1:26 PM To: python-list at python.org Subject: Re: Which more Pythonic - self.__class__ or type(self)? On 04/03/2023 20.47, Peter J. Holzer wrote: > On 2023-03-03 13:51:11 -0500, avi.e.gross at gmail.com wrote: ... > No. Even before Python existed there was the adage "a real programmer > can write FORTRAN in any language", indicating that idiomatic usage of a > language is not governed by syntax and library alone, but there is a > cultural element: People writing code in a specific language also read > code by other people in that language, so they start imitating each > other, just like speakers of natural languages imitate each other. > Someone coming from another language will often write code which is > correct but un-idiomatic, and you can often guess which language they > come from (they are "writing FORTRAN in Python"). Also quite similar to > natural languages where you can guess the native language of an L2 > speaker by their accent and phrasing. With ph agree I do... or do you want that in a DO-loop with a FORMAT? -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list From avi.e.gross at gmail.com Sat Mar 4 16:46:44 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 4 Mar 2023 16:46:44 -0500 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> <20230304074732.mdifd4r2bgfers62@hjp.at> <001901d94ec0$1e587020$5b095060$@gmail.com> Message-ID: <003101d94ee2$d051d6a0$70f583e0$@gmail.com> Alan, I got divorced from the C++ crowd decades ago when I left Bell Labs. You are making me glad I did! I do accept your suggestion that you can be idiomatic if you follow the common methods of whatever language you use. That will take you quite far as long as you are not a total slave to it. But I note some idioms catch on and some are imposed and some become almost moot. I am not sure which aspects of C++ have changed drastically and may go re-study the modern version as I was a very early adoptee within AT&T and saw changes even back then. But I consider something like the half dozen or so major print variants in python and wonder how much longer some of them will be seen as worth using, let alone idiomatic. Something like an fstring may dominate for many purposes. I know in R, that I used to use some convoluted methods to assemble output that I often now ignore once a "glue" package gave me something similar to fstring abilities where all kinds of variables and calculations can now be embedded withing a string to be dynamically evaluated in your current environment. Some of the documents I write now similarly embed parts of programs and also have an inline ability to evaluate small amounts of code in one of many languages that inserts directly into the text as it is being typeset. So I see moving targets where what was formerly at or near the state of the art, becomes pass?. So much of my early work rapidly became trivial or irrelevant or never caught on or became lost in an environment I no longer used. To keep going forward often involves leaving things behind. Some new features in Python will be interesting to watch. I mentioned the match statement. I was using a similar construct in a JVM language called SCALA ages ago. There it was a sort of core part of the language and often replaced constructs normally used by other languages such as many simple or nested IF statements. I am sure someone will point out where they borrowed parts from or who did it better, but what I am saying is that I want to see if it becomes an exotic addition to Python in a way that loosely melds, or if it becomes the PYTHONIC way ... -----Original Message----- From: Alan Gauld Sent: Saturday, March 4, 2023 1:38 PM To: avi.e.gross at gmail.com; python-list at python.org Subject: Re: RE: Which more Pythonic - self.__class__ or type(self)? On 04/03/2023 17:38, avi.e.gross at gmail.com wrote: > > Of course each language has commonly used idioms > That's the point, the correct term is probably "idiomatic" rather than "pythonic" but it is a defacto standard that idiomatic Python has become known as Pythonic. I don't think that's a problem. And at least we aren't in the C++ situation where almost everything that was idiomatic up until 1999 is now deemed an anti-pattern and they have standard library modules to try and guide you to use the "correct" idioms! But being Pythonic is still a much more loose term and the community less stressed about it than their C++ cousins where it has almost reached a religious fervour! -- 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 Sat Mar 4 17:04:03 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 4 Mar 2023 17:04:03 -0500 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: <002101d94ede$e31daf60$a9590e20$@gmail.com> References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> <20230304074732.mdifd4r2bgfers62@hjp.at> <002101d94ede$e31daf60$a9590e20$@gmail.com> Message-ID: On 3/4/2023 4:18 PM, avi.e.gross at gmail.com wrote: > I don't know, Thomas. For some simple programs, there is some evolutionary > benefit by starting with what you know and gradually growing from there. He > first time you need to do something that seems to need a loop in python, > there are loops to choose from. > > But as noted in a recent discussion, things are NOT NECESSARILY the same > even with something that simple. Did your previous languages retain > something like the loop variable outside the loop? What are your new scoping > rules? Do you really want to keep using global variables, and so on. > > And, another biggie is people who just don't seem aware of what comes easily > in the new language. I have seen people from primitive environments set up > programs with multiple arrays they process the hard way instead of using > some forms of structure like a named tuple or class arranged in lists or use > a multidimensional numpy/pandas kind of data structure. > > So ignoring the word pythonic as too specific, is there a way to say that > something is the way your current language supports more naturally? > > Yes, there are sort of fingerprints in how people write. Take the python > concept of truthy and how some people will still typically add a test for > equality with True. That may not be pythonic to some but is there much harm > in being explicit so anyone reading the code better understands what it doe? > > I have to wonder what others make of my code as my style is likely to be > considered closer to "eclectic" as I came to python late and found an > expanding language with way too many ways to do anything and can choose. But > I claim that too is pythonic! I think you are over-thinking this, Avi :) > > -----Original Message----- > From: Python-list On > Behalf Of Thomas Passin > Sent: Saturday, March 4, 2023 1:09 PM > To: python-list at python.org > Subject: Re: Which more Pythonic - self.__class__ or type(self)? > > On 3/4/2023 2:47 AM, Peter J. Holzer wrote: >> Even before Python existed there was the adage "a real programmer >> can write FORTRAN in any language", indicating that idiomatic usage of a >> language is not governed by syntax and library alone, but there is a >> cultural element: People writing code in a specific language also read >> code by other people in that language, so they start imitating each >> other, just like speakers of natural languages imitate each other. >> Someone coming from another language will often write code which is >> correct but un-idiomatic, and you can often guess which language they >> come from (they are "writing FORTRAN in Python"). > > What Peter didn't say is that this statement is usually used in a > disparaging sense. It tends to imply that a person can write (or is > writing) awkward or inappropriate code anywhere. > From gweatherby at uchc.edu Sat Mar 4 07:32:40 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Sat, 4 Mar 2023 12:32:40 +0000 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: References: Message-ID: Nope. No consensus. I?d use self.__class__ . Seems more explicit and direct to me. From: Python-list on behalf of Ian Pilcher Date: Thursday, March 2, 2023 at 4:17 PM To: python-list at python.org Subject: Which more Pythonic - self.__class__ or type(self)? *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Seems like an FAQ, and I've found a few things on StackOverflow that discuss the technical differences in edge cases, but I haven't found anything that talks about which form is considered to be more Pythonic in those situations where there's no functional difference. Is there any consensus? -- ======================================================================== Google Where SkyNet meets Idiocracy ======================================================================== -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!iK8xBvLrRYfAR0KdkDmK-VwyL0ZZUjFJZ9Tj4j-IBz3_B1M0iQFFE3dV-f4bV41DQwnFL_wC2xWRni-0pMUqAw$ From serignan.famille29 at gmail.com Sat Mar 4 12:13:15 2023 From: serignan.famille29 at gmail.com (Tom) Date: Sat, 4 Mar 2023 18:13:15 +0100 Subject: hi Message-ID: Bonjour je suis fran?ais et je ne comprend pas comment je peux acceder a python merci de me repondre CORDIALEMENT Lilian ? Envoy? ? partir de [1]Courrier pour Windows ? References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From list1 at tompassin.net Sat Mar 4 18:28:18 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 4 Mar 2023 18:28:18 -0500 Subject: hi In-Reply-To: References: Message-ID: <1cab1551-cc83-0830-25f7-7464828b4826@tompassin.net> On 3/4/2023 12:13 PM, Tom wrote: > Bonjour je suis fran?ais et je ne comprend pas comment je peux acceder a > python merci de me repondre > > CORDIALEMENT Lilian > > > > Envoy? ? partir de [1]Courrier pour Windows Veuillez expliquer ce que vous entendez par "peux acc?der ? un python". Si vous utilisez Windows, vous devez installer le programme Python, puis l'ex?cuter dans une fen?tre de console en tapant "python" ou "py". La plupart des syst?mes Linux sont livr?s avec Python d?j? install? (tapez "python3" au lieu de "python"). Ne tapez pas les guillemets. [translation by Google Translate] > References > > Visible links > 1. https://go.microsoft.com/fwlink/?LinkId=550986 From python at mrabarnett.plus.com Sat Mar 4 18:26:22 2023 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 4 Mar 2023 23:26:22 +0000 Subject: hi In-Reply-To: References: Message-ID: On 2023-03-04 17:13, Tom wrote: > Bonjour je suis fran?ais et je ne comprend pas comment je peux acceder a > python merci de me repondre > > CORDIALEMENT Lilian > Go to https://www.python.org/downloads/ and download the installer for your operating system (Windows or MacOS). For Windows I'd recommend "Windows installer (64-bit)" unless your computer is only 32-bit. Also, get yourself a decent editor for plain text that supports syntax colouring, although you can use IDLE, which comes with Python. From avi.e.gross at gmail.com Sat Mar 4 22:38:20 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 4 Mar 2023 22:38:20 -0500 Subject: Which more Pythonic - self.__class__ or type(self)? In-Reply-To: References: <7e9518b0-8e97-bcaf-24ba-e7f013690659@yahoo.co.uk> <005801d94e01$1f9850f0$5ec8f2d0$@gmail.com> <20230304074732.mdifd4r2bgfers62@hjp.at> <002101d94ede$e31daf60$a9590e20$@gmail.com> Message-ID: <00a101d94f13$ee49fee0$caddfca0$@gmail.com> >>> I think you are over-thinking this, Avi :) Is overthinking the pythonic way or did I develop such a habit from some other language? More seriously, I find in myself that I generally do not overthink. I overtalk and sort of overwrite, so for now, I think I will drop out of this possibly non-pythonic topic and go read another book or a few hundred so when it comes up again ... -----Original Message----- From: Python-list On Behalf Of Thomas Passin Sent: Saturday, March 4, 2023 5:04 PM To: python-list at python.org Subject: Re: Which more Pythonic - self.__class__ or type(self)? On 3/4/2023 4:18 PM, avi.e.gross at gmail.com wrote: > I don't know, Thomas. For some simple programs, there is some evolutionary > benefit by starting with what you know and gradually growing from there. He > first time you need to do something that seems to need a loop in python, > there are loops to choose from. > > But as noted in a recent discussion, things are NOT NECESSARILY the same > even with something that simple. Did your previous languages retain > something like the loop variable outside the loop? What are your new scoping > rules? Do you really want to keep using global variables, and so on. > > And, another biggie is people who just don't seem aware of what comes easily > in the new language. I have seen people from primitive environments set up > programs with multiple arrays they process the hard way instead of using > some forms of structure like a named tuple or class arranged in lists or use > a multidimensional numpy/pandas kind of data structure. > > So ignoring the word pythonic as too specific, is there a way to say that > something is the way your current language supports more naturally? > > Yes, there are sort of fingerprints in how people write. Take the python > concept of truthy and how some people will still typically add a test for > equality with True. That may not be pythonic to some but is there much harm > in being explicit so anyone reading the code better understands what it doe? > > I have to wonder what others make of my code as my style is likely to be > considered closer to "eclectic" as I came to python late and found an > expanding language with way too many ways to do anything and can choose. But > I claim that too is pythonic! I think you are over-thinking this, Avi :) > > -----Original Message----- > From: Python-list On > Behalf Of Thomas Passin > Sent: Saturday, March 4, 2023 1:09 PM > To: python-list at python.org > Subject: Re: Which more Pythonic - self.__class__ or type(self)? > > On 3/4/2023 2:47 AM, Peter J. Holzer wrote: >> Even before Python existed there was the adage "a real programmer >> can write FORTRAN in any language", indicating that idiomatic usage of a >> language is not governed by syntax and library alone, but there is a >> cultural element: People writing code in a specific language also read >> code by other people in that language, so they start imitating each >> other, just like speakers of natural languages imitate each other. >> Someone coming from another language will often write code which is >> correct but un-idiomatic, and you can often guess which language they >> come from (they are "writing FORTRAN in Python"). > > What Peter didn't say is that this statement is usually used in a > disparaging sense. It tends to imply that a person can write (or is > writing) awkward or inappropriate code anywhere. > -- https://mail.python.org/mailman/listinfo/python-list From greg.ewing at canterbury.ac.nz Sun Mar 5 01:19:35 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 5 Mar 2023 19:19:35 +1300 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: Message-ID: On 5/03/23 5:12 pm, Dino wrote: > I can do a substring search in a list of 30k elements in less than 2ms > with Python. Is my reasoning sound? I just did a similar test with your actual data and got about the same result. If that's fast enough for you, then you don't need to do anything fancy. -- Greg From urbangabo at gmail.com Sun Mar 5 05:00:56 2023 From: urbangabo at gmail.com (Gabor Urban) Date: Sun, 5 Mar 2023 11:00:56 +0100 Subject: Testing list sequence question -- thanks for the info Message-ID: Hi guys, Thank you very much for the accurate answer. Upgrading our Python to 3.7 seems to be out of question at the moment. I will check the requirement specification if the order of the keys is important at all. It could be a wish only. -- Urb?n G?bor Linux is like a wigwam: no Gates, no Windows and an Apache inside. From rob.cliffe at btinternet.com Wed Mar 1 06:57:15 2023 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Wed, 1 Mar 2023 11:57:15 +0000 Subject: Cryptic software announcements (was: ANN: DIPY 1.6.0) In-Reply-To: <20230301001328.iw4ranneqvo6o3r5@hjp.at> References: <20230301001328.iw4ranneqvo6o3r5@hjp.at> Message-ID: <5d4476f6-7d38-41b8-9ca1-fd6a24504290@btinternet.com> On 01/03/2023 00:13, Peter J. Holzer wrote: > [This isn't specifically about DIPY, I've noticed the same thing in > other announcements] > > On 2023-02-28 13:48:56 -0500, Eleftherios Garyfallidis wrote: >> Hello all, >> >> >> We are excited to announce a new release of DIPY: DIPY 1.6.0 is out from >> the oven! > That's nice, but what is DIPY? > > >> In addition, registration for the oceanic DIPY workshop 2023 (April 24-28) >> is now open! Our comprehensive program is designed to equip you with the >> skills and knowledge needed to master the latest techniques and tools in >> structural and diffusion imaging. > Ok, so since the workshop is about ".., tools in structural and > diffusion imaging", DIPY is probably such a tool. > > However, without this incidental announcement I wouldn't have any idea > what it is or if it would be worth my time clicking at any of the links. > > > I think it would be a good idea if software announcements would include > a single paragraph (or maybe just a single sentence) summarizing what > the software is and does. > > hp > > +1 Rob Cliffe From mats at wichmann.us Sun Mar 5 10:53:10 2023 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 5 Mar 2023 08:53:10 -0700 Subject: Cryptic software announcements (was: ANN: DIPY 1.6.0) In-Reply-To: <5d4476f6-7d38-41b8-9ca1-fd6a24504290@btinternet.com> References: <20230301001328.iw4ranneqvo6o3r5@hjp.at> <5d4476f6-7d38-41b8-9ca1-fd6a24504290@btinternet.com> Message-ID: <82e74aef-e761-5d6f-ec4c-749e3cf95e86@wichmann.us> On 3/1/23 04:57, Rob Cliffe via Python-list wrote: >> I think it would be a good idea if software announcements would include >> a single paragraph (or maybe just a single sentence) summarizing what >> the software is and does. >> >> ???????? hp >> >> > +1 > Rob Cliffe Excellent adivce - and many of the announcements on the separate python-announce list do actually follow this model (and this is probably actually the right place to send announcements). I'd even extend the suggestion further - it's surprising how many newcomers ask questions about a particular package that many people have not heard of - it all seems so obvious when you have an assignment, but when there are over 400,000 packages on PyPI it should actually not be surprising that a few of us have not actually heard of all of them :-) Maybe give a bit more context... From grant.b.edwards at gmail.com Sun Mar 5 11:25:22 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 05 Mar 2023 08:25:22 -0800 (PST) Subject: Testing list sequence question -- thanks for the info References: Message-ID: <6404c272.920a0220.94164.341e@mx.google.com> On 2023-03-05, Gabor Urban wrote: > Upgrading our Python to 3.7 seems to be out of question at the moment. Using an OrderedDict doesn't work for you? -- Grant From dino at no.spam.ar Sat Mar 4 22:43:54 2023 From: dino at no.spam.ar (Dino) Date: Sat, 4 Mar 2023 22:43:54 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) Message-ID: I need fast text-search on a large (not huge, let's say 30k records totally) list of items. Here's a sample of my raw data (a list of US cars: model and make) $ head all_cars_unique.csv\ Acura,CL Acura,ILX Acura,Integra Acura,Legend Acura,MDX Acura,MDX Sport Hybrid Acura,NSX Acura,RDX Acura,RL Acura,RLX $ wc -l all_cars_unique.csv 1415 all_cars_unique.csv $ grep -i v60 all_cars_unique.csv Genesis,GV60 Volvo,V60 $ Essentially, I want my input field to suggest autofill options with data from this file/list. The user types "v60" and a REST point will offer: [ {"model":"GV60", "manufacturer":"Genesis"}, {"model":"V60", "manufacturer":"Volvo"} ] i.e. a JSON response that I can use to generate the autofill with JavaScript. My Back-End is Python (Flask). How can I implement this? A library called Whoosh seems very promising (albeit it's so feature-rich that it's almost like shooting a fly with a bazooka in my case), but I see two problems: 1) Whoosh is either abandoned or the project is a mess in terms of community and support (https://groups.google.com/g/whoosh/c/QM_P8cGi4v4 ) and 2) Whoosh seems to be a Python only thing, which is great for now, but I wouldn't want this to become an obstacle should I need port it to a different language at some point. are there other options that are fast out there? Can I "grep" through a data structure in python... but faster? Thanks Dino From dino at no.spam.ar Sat Mar 4 22:47:03 2023 From: dino at no.spam.ar (Dino) Date: Sat, 4 Mar 2023 22:47:03 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: Message-ID: Here's the complete data file should anyone care. Acura,CL Acura,ILX Acura,Integra Acura,Legend Acura,MDX Acura,MDX Sport Hybrid Acura,NSX Acura,RDX Acura,RL Acura,RLX Acura,RLX Sport Hybrid Acura,RSX Acura,SLX Acura,TL Acura,TLX Acura,TSX Acura,Vigor Acura,ZDX Alfa Romeo,164 Alfa Romeo,4C Alfa Romeo,4C Spider Alfa Romeo,Giulia Alfa Romeo,Spider Alfa Romeo,Stelvio Alfa Romeo,Tonale Aston Martin,DB11 Aston Martin,DB9 Aston Martin,DB9 GT Aston Martin,DBS Aston Martin,DBS Superleggera Aston Martin,DBX Aston Martin,Rapide Aston Martin,Rapide S Aston Martin,Vanquish Aston Martin,Vanquish S Aston Martin,Vantage Aston Martin,Virage Audi,100 Audi,80 Audi,90 Audi,A3 Audi,A3 Sportback e-tron Audi,A4 Audi,A4 (2005.5) Audi,A4 allroad Audi,A5 Audi,A5 Sport Audi,A6 Audi,A6 allroad Audi,A7 Audi,A8 Audi,Cabriolet Audi,Q3 Audi,Q4 Sportback e-tron Audi,Q4 e-tron Audi,Q5 Audi,Q5 Sportback Audi,Q7 Audi,Q8 Audi,Quattro Audi,R8 Audi,RS 3 Audi,RS 4 Audi,RS 5 Audi,RS 6 Audi,RS 7 Audi,RS Q8 Audi,RS e-tron GT Audi,S3 Audi,S4 Audi,S4 (2005.5) Audi,S5 Audi,S6 Audi,S7 Audi,S8 Audi,SQ5 Audi,SQ5 Sportback Audi,SQ7 Audi,SQ8 Audi,TT Audi,allroad Audi,e-tron Audi,e-tron GT Audi,e-tron S Audi,e-tron S Sportback Audi,e-tron Sportback BMW,1 Series BMW,2 Series BMW,3 Series BMW,4 Series BMW,5 Series BMW,6 Series BMW,7 Series BMW,8 Series BMW,Alpina B7 BMW,M BMW,M2 BMW,M3 BMW,M4 BMW,M5 BMW,M6 BMW,M8 BMW,X1 BMW,X2 BMW,X3 BMW,X3 M BMW,X4 BMW,X4 M BMW,X5 BMW,X5 M BMW,X6 BMW,X6 M BMW,X7 BMW,Z3 BMW,Z4 BMW,Z4 M BMW,Z8 BMW,i3 BMW,i4 BMW,i7 BMW,i8 BMW,iX Bentley,Arnage Bentley,Azure Bentley,Azure T Bentley,Bentayga Bentley,Brooklands Bentley,Continental Bentley,Continental GT Bentley,Flying Spur Bentley,Mulsanne Buick,Cascada Buick,Century Buick,Enclave Buick,Encore Buick,Encore GX Buick,Envision Buick,LaCrosse Buick,LeSabre Buick,Lucerne Buick,Park Avenue Buick,Rainier Buick,Regal Buick,Regal Sportback Buick,Regal TourX Buick,Rendezvous Buick,Riviera Buick,Roadmaster Buick,Skylark Buick,Terraza Buick,Verano Cadillac,ATS Cadillac,ATS-V Cadillac,Allante Cadillac,Brougham Cadillac,CT4 Cadillac,CT5 Cadillac,CT6 Cadillac,CT6-V Cadillac,CTS Cadillac,CTS-V Cadillac,Catera Cadillac,DTS Cadillac,DeVille Cadillac,ELR Cadillac,Eldorado Cadillac,Escalade Cadillac,Escalade ESV Cadillac,Escalade EXT Cadillac,Fleetwood Cadillac,LYRIQ Cadillac,SRX Cadillac,STS Cadillac,Seville Cadillac,Sixty Special Cadillac,XLR Cadillac,XT4 Cadillac,XT5 Cadillac,XT6 Cadillac,XTS Chevrolet,1500 Extended Cab Chevrolet,1500 Regular Cab Chevrolet,2500 Crew Cab Chevrolet,2500 Extended Cab Chevrolet,2500 HD Extended Cab Chevrolet,2500 HD Regular Cab Chevrolet,2500 Regular Cab Chevrolet,3500 Crew Cab Chevrolet,3500 Extended Cab Chevrolet,3500 HD Extended Cab Chevrolet,3500 HD Regular Cab Chevrolet,3500 Regular Cab Chevrolet,APV Cargo Chevrolet,Astro Cargo Chevrolet,Astro Passenger Chevrolet,Avalanche Chevrolet,Avalanche 1500 Chevrolet,Avalanche 2500 Chevrolet,Aveo Chevrolet,Beretta Chevrolet,Blazer Chevrolet,Blazer EV Chevrolet,Bolt EUV Chevrolet,Bolt EV Chevrolet,Camaro Chevrolet,Caprice Chevrolet,Caprice Classic Chevrolet,Captiva Sport Chevrolet,Cavalier Chevrolet,City Express Chevrolet,Classic Chevrolet,Cobalt Chevrolet,Colorado Crew Cab Chevrolet,Colorado Extended Cab Chevrolet,Colorado Regular Cab Chevrolet,Corsica Chevrolet,Corvette Chevrolet,Cruze Chevrolet,Cruze Limited Chevrolet,Equinox Chevrolet,Equinox EV Chevrolet,Express 1500 Cargo Chevrolet,Express 1500 Passenger Chevrolet,Express 2500 Cargo Chevrolet,Express 2500 Passenger Chevrolet,Express 3500 Cargo Chevrolet,Express 3500 Passenger Chevrolet,G-Series 1500 Chevrolet,G-Series 2500 Chevrolet,G-Series 3500 Chevrolet,G-Series G10 Chevrolet,G-Series G20 Chevrolet,G-Series G30 Chevrolet,HHR Chevrolet,Impala Chevrolet,Impala Limited Chevrolet,Lumina Chevrolet,Lumina APV Chevrolet,Lumina Cargo Chevrolet,Lumina Passenger Chevrolet,Malibu Chevrolet,Malibu (Classic) Chevrolet,Malibu Limited Chevrolet,Metro Chevrolet,Monte Carlo Chevrolet,Prizm Chevrolet,S10 Blazer Chevrolet,S10 Crew Cab Chevrolet,S10 Extended Cab Chevrolet,S10 Regular Cab Chevrolet,SS Chevrolet,SSR Chevrolet,Silverado (Classic) 1500 Crew Cab Chevrolet,Silverado (Classic) 1500 Extended Cab Chevrolet,Silverado (Classic) 1500 HD Crew Cab Chevrolet,Silverado (Classic) 1500 Regular Cab Chevrolet,Silverado (Classic) 2500 HD Crew Cab Chevrolet,Silverado (Classic) 2500 HD Extended Cab Chevrolet,Silverado (Classic) 2500 HD Regular Cab Chevrolet,Silverado (Classic) 3500 Crew Cab Chevrolet,Silverado (Classic) 3500 Extended Cab Chevrolet,Silverado (Classic) 3500 Regular Cab Chevrolet,Silverado 1500 Crew Cab Chevrolet,Silverado 1500 Double Cab Chevrolet,Silverado 1500 Extended Cab Chevrolet,Silverado 1500 HD Crew Cab Chevrolet,Silverado 1500 LD Double Cab Chevrolet,Silverado 1500 Limited Crew Cab Chevrolet,Silverado 1500 Limited Double Cab Chevrolet,Silverado 1500 Limited Regular Cab Chevrolet,Silverado 1500 Regular Cab Chevrolet,Silverado 2500 Crew Cab Chevrolet,Silverado 2500 Extended Cab Chevrolet,Silverado 2500 HD Crew Cab Chevrolet,Silverado 2500 HD Double Cab Chevrolet,Silverado 2500 HD Extended Cab Chevrolet,Silverado 2500 HD Regular Cab Chevrolet,Silverado 2500 Regular Cab Chevrolet,Silverado 3500 Crew Cab Chevrolet,Silverado 3500 Extended Cab Chevrolet,Silverado 3500 HD Crew Cab Chevrolet,Silverado 3500 HD Double Cab Chevrolet,Silverado 3500 HD Extended Cab Chevrolet,Silverado 3500 HD Regular Cab Chevrolet,Silverado 3500 Regular Cab Chevrolet,Silverado EV Chevrolet,Sonic Chevrolet,Spark Chevrolet,Spark EV Chevrolet,Sportvan G10 Chevrolet,Sportvan G20 Chevrolet,Sportvan G30 Chevrolet,Suburban Chevrolet,Suburban 1500 Chevrolet,Suburban 2500 Chevrolet,Suburban 3500HD Chevrolet,Tahoe Chevrolet,Tahoe (New) Chevrolet,Tracker Chevrolet,TrailBlazer Chevrolet,Trailblazer Chevrolet,Traverse Chevrolet,Trax Chevrolet,Uplander Cargo Chevrolet,Uplander Passenger Chevrolet,Venture Cargo Chevrolet,Venture Passenger Chevrolet,Volt Chrysler,200 Chrysler,300 Chrysler,300M Chrysler,Aspen Chrysler,Cirrus Chrysler,Concorde Chrysler,Crossfire Chrysler,Fifth Ave Chrysler,Grand Voyager Chrysler,Imperial Chrysler,LHS Chrysler,LeBaron Chrysler,New Yorker Chrysler,PT Cruiser Chrysler,Pacifica Chrysler,Pacifica Hybrid Chrysler,Prowler Chrysler,Sebring Chrysler,Town & Country Chrysler,Voyager Daewoo,Lanos Daewoo,Leganza Daewoo,Nubira Daihatsu,Charade Daihatsu,Rocky Dodge,Avenger Dodge,Caliber Dodge,Caravan Cargo Dodge,Caravan Passenger Dodge,Challenger Dodge,Charger Dodge,Colt Dodge,D150 Club Cab Dodge,D150 Regular Cab Dodge,D250 Club Cab Dodge,D250 Regular Cab Dodge,D350 Club Cab Dodge,D350 Regular Cab Dodge,Dakota Club Cab Dodge,Dakota Crew Cab Dodge,Dakota Extended Cab Dodge,Dakota Quad Cab Dodge,Dakota Regular Cab Dodge,Dart Dodge,Daytona Dodge,Durango Dodge,Dynasty Dodge,Grand Caravan Cargo Dodge,Grand Caravan Passenger Dodge,Hornet Dodge,Intrepid Dodge,Journey Dodge,Magnum Dodge,Monaco Dodge,Neon Dodge,Nitro Dodge,Ram 1500 Club Cab Dodge,Ram 1500 Crew Cab Dodge,Ram 1500 Mega Cab Dodge,Ram 1500 Quad Cab Dodge,Ram 1500 Regular Cab Dodge,Ram 2500 Club Cab Dodge,Ram 2500 Crew Cab Dodge,Ram 2500 Mega Cab Dodge,Ram 2500 Quad Cab Dodge,Ram 2500 Regular Cab Dodge,Ram 3500 Club Cab Dodge,Ram 3500 Crew Cab Dodge,Ram 3500 Mega Cab Dodge,Ram 3500 Quad Cab Dodge,Ram 3500 Regular Cab Dodge,Ram 50 Regular Cab Dodge,Ram Van 1500 Dodge,Ram Van 2500 Dodge,Ram Van 3500 Dodge,Ram Van B150 Dodge,Ram Van B250 Dodge,Ram Van B350 Dodge,Ram Wagon 1500 Dodge,Ram Wagon 2500 Dodge,Ram Wagon 3500 Dodge,Ram Wagon B150 Dodge,Ram Wagon B250 Dodge,Ram Wagon B350 Dodge,Ramcharger Dodge,Shadow Dodge,Spirit Dodge,Sprinter 2500 Cargo Dodge,Sprinter 2500 Passenger Dodge,Sprinter 3500 Cargo Dodge,Stealth Dodge,Stratus Dodge,Viper Eagle,Premier Eagle,Summit Eagle,Talon Eagle,Vision FIAT,124 Spider FIAT,500 FIAT,500 Abarth FIAT,500L FIAT,500X FIAT,500c FIAT,500c Abarth FIAT,500e Ferrari,296 GTB Ferrari,430 Scuderia Ferrari,458 Italia Ferrari,458 Speciale Ferrari,458 Spider Ferrari,488 GTB Ferrari,488 Pista Ferrari,488 Spider Ferrari,599 GTB Fiorano Ferrari,599 GTO Ferrari,612 Scaglietti Ferrari,812 Competizione Ferrari,812 Competizione A Ferrari,812 GTS Ferrari,812 Superfast Ferrari,California Ferrari,F12berlinetta Ferrari,F430 Ferrari,F8 Ferrari,FF Ferrari,GTC4Lusso Ferrari,Portofino Ferrari,Roma Ferrari,SF90 Fisker,Karma Ford,Aerostar Cargo Ford,Aerostar Passenger Ford,Aspire Ford,Bronco Ford,Bronco Sport Ford,C-MAX Energi Ford,C-MAX Hybrid Ford,Club Wagon Ford,Contour Ford,Crown Victoria Ford,E-Transit 350 Cargo Van Ford,E150 Cargo Ford,E150 Passenger Ford,E150 Super Duty Cargo Ford,E150 Super Duty Passenger Ford,E250 Cargo Ford,E250 Super Duty Cargo Ford,E350 Super Duty Cargo Ford,E350 Super Duty Passenger Ford,EcoSport Ford,Econoline E150 Cargo Ford,Econoline E150 Passenger Ford,Econoline E250 Cargo Ford,Econoline E350 Cargo Ford,Econoline E350 Super Duty Cargo Ford,Econoline E350 Super Duty Passenger Ford,Edge Ford,Escape Ford,Escape Plug-in Hybrid Ford,Escort Ford,Excursion Ford,Expedition Ford,Expedition EL Ford,Expedition MAX Ford,Explorer Ford,Explorer Sport Ford,Explorer Sport Trac Ford,F150 (Heritage) Regular Cab Ford,F150 (Heritage) Super Cab Ford,F150 Lightning Ford,F150 Regular Cab Ford,F150 Super Cab Ford,F150 SuperCrew Cab Ford,F250 Crew Cab Ford,F250 Regular Cab Ford,F250 Super Cab Ford,F250 Super Duty Crew Cab Ford,F250 Super Duty Regular Cab Ford,F250 Super Duty Super Cab Ford,F350 Crew Cab Ford,F350 Regular Cab Ford,F350 Super Cab Ford,F350 Super Duty Crew Cab Ford,F350 Super Duty Regular Cab Ford,F350 Super Duty Super Cab Ford,F450 Super Duty Crew Cab Ford,F450 Super Duty Regular Cab Ford,Festiva Ford,Fiesta Ford,Five Hundred Ford,Flex Ford,Focus Ford,Focus ST Ford,Freestar Cargo Ford,Freestar Passenger Ford,Freestyle Ford,Fusion Ford,Fusion Energi Ford,Fusion Plug-in Hybrid Ford,GT Ford,Maverick Ford,Mustang Ford,Mustang MACH-E Ford,Probe Ford,Ranger Regular Cab Ford,Ranger Super Cab Ford,Ranger SuperCab Ford,Ranger SuperCrew Ford,Taurus Ford,Taurus X Ford,Tempo Ford,Thunderbird Ford,Transit 150 Cargo Van Ford,Transit 150 Crew Van Ford,Transit 150 Passenger Van Ford,Transit 150 Van Ford,Transit 150 Wagon Ford,Transit 250 Cargo Van Ford,Transit 250 Crew Van Ford,Transit 250 Van Ford,Transit 350 Cargo Van Ford,Transit 350 Crew Van Ford,Transit 350 HD Cargo Van Ford,Transit 350 HD Crew Van Ford,Transit 350 HD Van Ford,Transit 350 Passenger Van Ford,Transit 350 Van Ford,Transit 350 Wagon Ford,Transit Connect Cargo Ford,Transit Connect Cargo Van Ford,Transit Connect Passenger Ford,Transit Connect Passenger Wagon Ford,Windstar Cargo Ford,Windstar Passenger Ford,ZX2 Freightliner,Sprinter 1500 Cargo Freightliner,Sprinter 1500 Passenger Freightliner,Sprinter 2500 Cargo Freightliner,Sprinter 2500 Crew Freightliner,Sprinter 2500 Passenger Freightliner,Sprinter 3500 Cargo Freightliner,Sprinter 3500 Crew Freightliner,Sprinter 3500 XD Crew Freightliner,Sprinter 3500XD Cargo Freightliner,Sprinter 4500 Cargo Freightliner,Sprinter 4500 Crew Freightliner,Sprinter WORKER Cargo Freightliner,Sprinter WORKER Passenger GMC,1500 Club Coupe GMC,1500 Regular Cab GMC,2500 Club Coupe GMC,2500 Crew Cab GMC,2500 HD Club Coupe GMC,2500 HD Extended Cab GMC,2500 HD Regular Cab GMC,2500 Regular Cab GMC,3500 Club Coupe GMC,3500 Crew Cab GMC,3500 Extended Cab GMC,3500 Regular Cab GMC,Acadia GMC,Acadia Limited GMC,Canyon Crew Cab GMC,Canyon Extended Cab GMC,Canyon Regular Cab GMC,Envoy GMC,Envoy XL GMC,Envoy XUV GMC,Hummer EV Pickup GMC,Hummer EV SUV GMC,Jimmy GMC,Rally Wagon 1500 GMC,Rally Wagon 2500 GMC,Rally Wagon 3500 GMC,Rally Wagon G2500 GMC,Rally Wagon G3500 GMC,Safari Cargo GMC,Safari Passenger GMC,Savana 1500 Cargo GMC,Savana 1500 Passenger GMC,Savana 2500 Cargo GMC,Savana 2500 Passenger GMC,Savana 3500 Cargo GMC,Savana 3500 Passenger GMC,Sierra (Classic) 1500 Crew Cab GMC,Sierra (Classic) 1500 Extended Cab GMC,Sierra (Classic) 1500 HD Crew Cab GMC,Sierra (Classic) 1500 Regular Cab GMC,Sierra (Classic) 2500 Crew Cab GMC,Sierra (Classic) 2500 HD Crew Cab GMC,Sierra (Classic) 2500 HD Extended Cab GMC,Sierra (Classic) 2500 HD Regular Cab GMC,Sierra (Classic) 3500 Crew Cab GMC,Sierra (Classic) 3500 Extended Cab GMC,Sierra (Classic) 3500 Regular Cab GMC,Sierra 1500 Crew Cab GMC,Sierra 1500 Double Cab GMC,Sierra 1500 Extended Cab GMC,Sierra 1500 HD Crew Cab GMC,Sierra 1500 Limited Crew Cab GMC,Sierra 1500 Limited Double Cab GMC,Sierra 1500 Limited Regular Cab GMC,Sierra 1500 Regular Cab GMC,Sierra 2500 Crew Cab GMC,Sierra 2500 Extended Cab GMC,Sierra 2500 HD Crew Cab GMC,Sierra 2500 HD Double Cab GMC,Sierra 2500 HD Extended Cab GMC,Sierra 2500 HD Regular Cab GMC,Sierra 2500 Regular Cab GMC,Sierra 3500 Crew Cab GMC,Sierra 3500 Extended Cab GMC,Sierra 3500 HD Crew Cab GMC,Sierra 3500 HD Double Cab GMC,Sierra 3500 HD Extended Cab GMC,Sierra 3500 HD Regular Cab GMC,Sierra 3500 Regular Cab GMC,Sonoma Club Cab GMC,Sonoma Club Coupe Cab GMC,Sonoma Crew Cab GMC,Sonoma Extended Cab GMC,Sonoma Regular Cab GMC,Suburban 1500 GMC,Suburban 2500 GMC,Terrain GMC,Vandura 1500 GMC,Vandura 2500 GMC,Vandura 3500 GMC,Vandura G1500 GMC,Vandura G2500 GMC,Vandura G3500 GMC,Yukon GMC,Yukon Denali GMC,Yukon XL GMC,Yukon XL 1500 GMC,Yukon XL 2500 Genesis,Electrified G80 Genesis,G70 Genesis,G80 Genesis,G90 Genesis,GV60 Genesis,GV70 Genesis,GV80 Geo,Metro Geo,Prizm Geo,Storm Geo,Tracker HUMMER,H1 HUMMER,H2 HUMMER,H3 HUMMER,H3T Honda,Accord Honda,Accord Crosstour Honda,Accord Hybrid Honda,CR-V Honda,CR-V Hybrid Honda,CR-Z Honda,Civic Honda,Civic Type R Honda,Clarity Electric Honda,Clarity Fuel Cell Honda,Clarity Plug-in Hybrid Honda,Crosstour Honda,Element Honda,Fit Honda,HR-V Honda,Insight Honda,Odyssey Honda,Passport Honda,Pilot Honda,Prelude Honda,Prologue Honda,Ridgeline Honda,S2000 Honda,del Sol Hyundai,Accent Hyundai,Azera Hyundai,Elantra Hyundai,Elantra GT Hyundai,Elantra Hybrid Hyundai,Elantra N Hyundai,Entourage Hyundai,Equus Hyundai,Excel Hyundai,Genesis Hyundai,Genesis Coupe Hyundai,IONIQ 5 Hyundai,IONIQ 6 Hyundai,IONIQ 7 Hyundai,Ioniq Electric Hyundai,Ioniq Hybrid Hyundai,Ioniq Plug-in Hybrid Hyundai,Kona Hyundai,Kona Electric Hyundai,Kona N Hyundai,NEXO Hyundai,Palisade Hyundai,Santa Cruz Hyundai,Santa Fe Hyundai,Santa Fe Hybrid Hyundai,Santa Fe Plug-in Hybrid Hyundai,Santa Fe Sport Hyundai,Santa Fe XL Hyundai,Scoupe Hyundai,Sonata Hyundai,Sonata Hybrid Hyundai,Sonata Plug-in Hybrid Hyundai,Tiburon Hyundai,Tucson Hyundai,Tucson Fuel Cell Hyundai,Tucson Hybrid Hyundai,Tucson Plug-in Hybrid Hyundai,Veloster Hyundai,Venue Hyundai,Veracruz Hyundai,XG300 Hyundai,XG350 INFINITI,EX INFINITI,FX INFINITI,G INFINITI,I INFINITI,J INFINITI,JX INFINITI,M INFINITI,Q INFINITI,Q40 INFINITI,Q50 INFINITI,Q60 INFINITI,Q70 INFINITI,QX INFINITI,QX30 INFINITI,QX50 INFINITI,QX55 INFINITI,QX60 INFINITI,QX70 INFINITI,QX80 Isuzu,Amigo Isuzu,Ascender Isuzu,Axiom Isuzu,Hombre Regular Cab Isuzu,Hombre Spacecab Isuzu,Impulse Isuzu,Oasis Isuzu,Regular Cab Isuzu,Rodeo Isuzu,Rodeo Sport Isuzu,Spacecab Isuzu,Stylus Isuzu,Trooper Isuzu,VehiCROSS Isuzu,i-280 Extended Cab Isuzu,i-290 Extended Cab Isuzu,i-350 Crew Cab Isuzu,i-370 Crew Cab Isuzu,i-370 Extended Cab Jaguar,E-PACE Jaguar,F-PACE Jaguar,F-TYPE Jaguar,I-PACE Jaguar,S-Type Jaguar,X-Type Jaguar,XE Jaguar,XF Jaguar,XJ Jaguar,XK Jeep,Cherokee Jeep,Comanche Regular Cab Jeep,Commander Jeep,Compass Jeep,Gladiator Jeep,Grand Cherokee Jeep,Grand Cherokee 4xe Jeep,Grand Cherokee L Jeep,Grand Wagoneer Jeep,Grand Wagoneer L Jeep,Liberty Jeep,Patriot Jeep,Recon Jeep,Renegade Jeep,Wagoneer Jeep,Wagoneer L Jeep,Wrangler Jeep,Wrangler Unlimited Jeep,Wrangler Unlimited 4xe Kia,Amanti Kia,Borrego Kia,Cadenza Kia,Carnival Kia,EV6 Kia,EV9 Kia,Forte Kia,Forte Koup Kia,Forte5 Kia,K5 Kia,K900 Kia,Niro Kia,Niro EV Kia,Niro Plug-in Hybrid Kia,Optima Kia,Optima (2006.5) Kia,Optima Hybrid Kia,Optima Plug-in Hybrid Kia,Rio Kia,Rondo Kia,Sedona Kia,Seltos Kia,Sephia Kia,Sorento Kia,Sorento Hybrid Kia,Sorento Plug-in Hybrid Kia,Soul Kia,Soul EV Kia,Spectra Kia,Sportage Kia,Sportage Hybrid Kia,Sportage Plug-in Hybrid Kia,Stinger Kia,Telluride Lamborghini,Aventador Lamborghini,Gallardo Lamborghini,Huracan Lamborghini,Murcielago Lamborghini,Murcielago LP640 Lamborghini,Urus Land Rover,Defender 110 Land Rover,Defender 130 Land Rover,Defender 90 Land Rover,Discovery Land Rover,Discovery Series II Land Rover,Discovery Sport Land Rover,Freelander Land Rover,LR2 Land Rover,LR3 Land Rover,LR4 Land Rover,Range Rover Land Rover,Range Rover Evoque Land Rover,Range Rover Sport Land Rover,Range Rover Velar Lexus,CT Lexus,ES Lexus,GS Lexus,GX Lexus,HS Lexus,IS Lexus,IS F Lexus,LC Lexus,LFA Lexus,LS Lexus,LX Lexus,NX Lexus,RC Lexus,RX Lexus,RZ Lexus,SC Lexus,TX Lexus,UX Lincoln,Aviator Lincoln,Blackwood Lincoln,Continental Lincoln,Corsair Lincoln,LS Lincoln,MKC Lincoln,MKS Lincoln,MKT Lincoln,MKX Lincoln,MKZ Lincoln,Mark LT Lincoln,Mark VII Lincoln,Mark VIII Lincoln,Nautilus Lincoln,Navigator Lincoln,Navigator L Lincoln,Town Car Lincoln,Zephyr Lotus,Elise Lotus,Evora Lotus,Evora 400 Lotus,Evora GT Lotus,Exige Lotus,Exige S Lucid,Air MAZDA,323 MAZDA,626 MAZDA,929 MAZDA,B-Series Cab Plus MAZDA,B-Series Extended Cab MAZDA,B-Series Regular Cab MAZDA,CX-3 MAZDA,CX-30 MAZDA,CX-5 MAZDA,CX-50 MAZDA,CX-7 MAZDA,CX-70 MAZDA,CX-9 MAZDA,CX-90 MAZDA,MAZDA2 MAZDA,MAZDA3 MAZDA,MAZDA5 MAZDA,MAZDA6 MAZDA,MPV MAZDA,MX-3 MAZDA,MX-30 MAZDA,MX-5 Miata MAZDA,MX-5 Miata RF MAZDA,MX-6 MAZDA,Millenia MAZDA,Navajo MAZDA,Protege MAZDA,Protege5 MAZDA,RX-7 MAZDA,RX-8 MAZDA,Tribute MINI,Clubman MINI,Convertible MINI,Cooper MINI,Countryman MINI,Coupe MINI,Hardtop MINI,Hardtop 2 Door MINI,Hardtop 4 Door MINI,Paceman MINI,Roadster Maserati,Coupe Maserati,Ghibli Maserati,GranSport Maserati,GranTurismo Maserati,Grecale Maserati,Levante Maserati,MC20 Maserati,Quattroporte Maybach,57 Maybach,62 McLaren,570GT McLaren,570S McLaren,600LT McLaren,650S McLaren,675LT McLaren,720S McLaren,MP4-12C Mercedes-Benz,190 E Mercedes-Benz,300 CE Mercedes-Benz,300 D Mercedes-Benz,300 E Mercedes-Benz,300 SD Mercedes-Benz,300 SE Mercedes-Benz,300 SL Mercedes-Benz,300 TE Mercedes-Benz,400 E Mercedes-Benz,400 SE Mercedes-Benz,400 SEL Mercedes-Benz,500 E Mercedes-Benz,500 SEC Mercedes-Benz,500 SEL Mercedes-Benz,500 SL Mercedes-Benz,600 SEC Mercedes-Benz,600 SEL Mercedes-Benz,600 SL Mercedes-Benz,A-Class Mercedes-Benz,B-Class Mercedes-Benz,C-Class Mercedes-Benz,CL-Class Mercedes-Benz,CLA Mercedes-Benz,CLA-Class Mercedes-Benz,CLK-Class Mercedes-Benz,CLS Mercedes-Benz,CLS-Class Mercedes-Benz,E-Class Mercedes-Benz,G-Class Mercedes-Benz,GL-Class Mercedes-Benz,GLA Mercedes-Benz,GLA-Class Mercedes-Benz,GLB Mercedes-Benz,GLC Mercedes-Benz,GLC Coupe Mercedes-Benz,GLE Mercedes-Benz,GLE Coupe Mercedes-Benz,GLK-Class Mercedes-Benz,GLS Mercedes-Benz,M-Class Mercedes-Benz,Mercedes-AMG A-Class Mercedes-Benz,Mercedes-AMG C-Class Mercedes-Benz,Mercedes-AMG CLA Mercedes-Benz,Mercedes-AMG CLS Mercedes-Benz,Mercedes-AMG E-Class Mercedes-Benz,Mercedes-AMG EQS Mercedes-Benz,Mercedes-AMG G-Class Mercedes-Benz,Mercedes-AMG GLA Mercedes-Benz,Mercedes-AMG GLB Mercedes-Benz,Mercedes-AMG GLC Mercedes-Benz,Mercedes-AMG GLC Coupe Mercedes-Benz,Mercedes-AMG GLE Mercedes-Benz,Mercedes-AMG GLE Coupe Mercedes-Benz,Mercedes-AMG GLS Mercedes-Benz,Mercedes-AMG GT Mercedes-Benz,Mercedes-AMG S-Class Mercedes-Benz,Mercedes-AMG SL Mercedes-Benz,Mercedes-AMG SLC Mercedes-Benz,Mercedes-AMG SLK Mercedes-Benz,Mercedes-EQ EQB Mercedes-Benz,Mercedes-EQ EQE Mercedes-Benz,Mercedes-EQ EQE SUV Mercedes-Benz,Mercedes-EQ EQS Mercedes-Benz,Mercedes-EQ EQS SUV Mercedes-Benz,Mercedes-Maybach GLS Mercedes-Benz,Mercedes-Maybach S 600 Mercedes-Benz,Mercedes-Maybach S-Class Mercedes-Benz,Metris Cargo Mercedes-Benz,Metris Passenger Mercedes-Benz,Metris WORKER Cargo Mercedes-Benz,Metris WORKER Passenger Mercedes-Benz,R-Class Mercedes-Benz,S-Class Mercedes-Benz,SL Mercedes-Benz,SL-Class Mercedes-Benz,SLC Mercedes-Benz,SLK Mercedes-Benz,SLK-Class Mercedes-Benz,SLR McLaren Mercedes-Benz,SLS-Class Mercedes-Benz,Sprinter 1500 Cargo Mercedes-Benz,Sprinter 1500 Passenger Mercedes-Benz,Sprinter 2500 Cargo Mercedes-Benz,Sprinter 2500 Crew Mercedes-Benz,Sprinter 2500 Passenger Mercedes-Benz,Sprinter 3500 Cargo Mercedes-Benz,Sprinter 3500 Crew Mercedes-Benz,Sprinter 3500 XD Cargo Mercedes-Benz,Sprinter 3500 XD Crew Mercedes-Benz,Sprinter 4500 Cargo Mercedes-Benz,Sprinter 4500 Crew Mercedes-Benz,Sprinter WORKER Cargo Mercedes-Benz,Sprinter WORKER Passenger Mercury,Capri Mercury,Cougar Mercury,Grand Marquis Mercury,Marauder Mercury,Mariner Mercury,Milan Mercury,Montego Mercury,Monterey Mercury,Mountaineer Mercury,Mystique Mercury,Sable Mercury,Topaz Mercury,Tracer Mercury,Villager Mitsubishi,3000GT Mitsubishi,Diamante Mitsubishi,Eclipse Mitsubishi,Eclipse Cross Mitsubishi,Endeavor Mitsubishi,Expo Mitsubishi,Galant Mitsubishi,Lancer Mitsubishi,Lancer Evolution Mitsubishi,Mighty Max Macro Cab Mitsubishi,Mighty Max Regular Cab Mitsubishi,Mirage Mitsubishi,Mirage G4 Mitsubishi,Montero Mitsubishi,Montero Sport Mitsubishi,Outlander Mitsubishi,Outlander PHEV Mitsubishi,Outlander Sport Mitsubishi,Precis Mitsubishi,Raider Double Cab Mitsubishi,Raider Extended Cab Mitsubishi,i-MiEV Nissan,200SX Nissan,240SX Nissan,300ZX Nissan,350Z Nissan,370Z Nissan,400Z Nissan,Altima Nissan,Ariya Nissan,Armada Nissan,Frontier Crew Cab Nissan,Frontier King Cab Nissan,Frontier Regular Cab Nissan,GT-R Nissan,JUKE Nissan,Kicks Nissan,King Cab Nissan,LEAF Nissan,Maxima Nissan,Murano Nissan,NV1500 Cargo Nissan,NV200 Nissan,NV200 Taxi Nissan,NV2500 HD Cargo Nissan,NV3500 HD Cargo Nissan,NV3500 HD Passenger Nissan,NX Nissan,Pathfinder Nissan,Pathfinder Armada Nissan,Quest Nissan,Regular Cab Nissan,Rogue Nissan,Rogue Select Nissan,Rogue Sport Nissan,Sentra Nissan,Stanza Nissan,TITAN Single Cab Nissan,TITAN XD Crew Cab Nissan,TITAN XD King Cab Nissan,TITAN XD Single Cab Nissan,Titan Crew Cab Nissan,Titan King Cab Nissan,Versa Nissan,Versa Note Nissan,Xterra Nissan,Z Nissan,cube Oldsmobile,88 Oldsmobile,98 Oldsmobile,Achieva Oldsmobile,Alero Oldsmobile,Aurora Oldsmobile,Bravada Oldsmobile,Ciera Oldsmobile,Custom Cruiser Oldsmobile,Cutlass Oldsmobile,Cutlass Ciera Oldsmobile,Cutlass Cruiser Oldsmobile,Cutlass Supreme Oldsmobile,Intrigue Oldsmobile,LSS Oldsmobile,Regency Oldsmobile,Silhouette Oldsmobile,Toronado Panoz,Esperante Plymouth,Acclaim Plymouth,Breeze Plymouth,Colt Plymouth,Colt Vista Plymouth,Grand Voyager Plymouth,Laser Plymouth,Neon Plymouth,Prowler Plymouth,Sundance Plymouth,Voyager Polestar,1 Polestar,2 Polestar,3 Polestar,5 Pontiac,Aztek Pontiac,Bonneville Pontiac,Firebird Pontiac,G3 Pontiac,G5 Pontiac,G6 Pontiac,G6 (2009.5) Pontiac,G8 Pontiac,GTO Pontiac,Grand Am Pontiac,Grand Prix Pontiac,LeMans Pontiac,Montana Pontiac,Montana SV6 Pontiac,Solstice Pontiac,Sunbird Pontiac,Sunfire Pontiac,Torrent Pontiac,Trans Sport Pontiac,Vibe Porsche,718 Boxster Porsche,718 Cayman Porsche,718 Spyder Porsche,911 Porsche,928 Porsche,968 Porsche,Boxster Porsche,Carrera GT Porsche,Cayenne Porsche,Cayenne Coupe Porsche,Cayman Porsche,Macan Porsche,Panamera Porsche,Taycan Porsche,Taycan Cross Turismo Ram,1500 Classic Crew Cab Ram,1500 Classic Quad Cab Ram,1500 Classic Regular Cab Ram,1500 Crew Cab Ram,1500 Quad Cab Ram,1500 Regular Cab Ram,2500 Crew Cab Ram,2500 Mega Cab Ram,2500 Regular Cab Ram,3500 Crew Cab Ram,3500 Mega Cab Ram,3500 Regular Cab Ram,C/V Ram,C/V Tradesman Ram,Dakota Crew Cab Ram,Dakota Extended Cab Ram,ProMaster 1500 Cargo Ram,ProMaster 2500 Cargo Ram,ProMaster 3500 Cargo Ram,ProMaster Cargo Van Ram,ProMaster City Ram,ProMaster Window Van Rivian,R1S Rivian,R1T Rolls-Royce,Cullinan Rolls-Royce,Dawn Rolls-Royce,Ghost Rolls-Royce,Phantom Rolls-Royce,Wraith SRT,Viper Saab,9-2X Saab,9-3 Saab,9-4X Saab,9-5 Saab,9-7X Saab,900 Saab,9000 Saturn,Astra Saturn,Aura Saturn,Ion Saturn,L-Series Saturn,Outlook Saturn,Relay Saturn,S-Series Saturn,SKY Saturn,VUE Scion,FR-S Scion,iA Scion,iM Scion,iQ Scion,tC Scion,xA Scion,xB Scion,xD Subaru,Ascent Subaru,B9 Tribeca Subaru,BRZ Subaru,Baja Subaru,Crosstrek Subaru,Forester Subaru,Impreza Subaru,Justy Subaru,Legacy Subaru,Loyale Subaru,Outback Subaru,SVX Subaru,Solterra Subaru,Tribeca Subaru,WRX Subaru,XV Crosstrek Suzuki,Aerio Suzuki,Equator Crew Cab Suzuki,Equator Extended Cab Suzuki,Esteem Suzuki,Forenza Suzuki,Grand Vitara Suzuki,Kizashi Suzuki,Reno Suzuki,SX4 Suzuki,Samurai Suzuki,Sidekick Suzuki,Swift Suzuki,Verona Suzuki,Vitara Suzuki,X-90 Suzuki,XL-7 Suzuki,XL7 Tesla,Cybertruck Tesla,Model 3 Tesla,Model S Tesla,Model X Tesla,Model Y Toyota,4Runner Toyota,86 Toyota,Avalon Toyota,Avalon Hybrid Toyota,C-HR Toyota,Camry Toyota,Camry Hybrid Toyota,Celica Toyota,Corolla Toyota,Corolla Cross Toyota,Corolla Cross Hybrid Toyota,Corolla Hatchback Toyota,Corolla Hybrid Toyota,Corolla iM Toyota,Cressida Toyota,Crown Toyota,Echo Toyota,FJ Cruiser Toyota,GR Supra Toyota,GR86 Toyota,Highlander Toyota,Highlander Hybrid Toyota,Land Cruiser Toyota,MR2 Toyota,Matrix Toyota,Mirai Toyota,Paseo Toyota,Previa Toyota,Prius Toyota,Prius Plug-in Hybrid Toyota,Prius Prime Toyota,Prius c Toyota,Prius v Toyota,RAV4 Toyota,RAV4 Hybrid Toyota,RAV4 Prime Toyota,Regular Cab Toyota,Sequoia Toyota,Sienna Toyota,Solara Toyota,Supra Toyota,T100 Regular Cab Toyota,T100 Xtracab Toyota,Tacoma Access Cab Toyota,Tacoma Double Cab Toyota,Tacoma Regular Cab Toyota,Tacoma Xtracab Toyota,Tercel Toyota,Tundra Access Cab Toyota,Tundra CrewMax Toyota,Tundra Double Cab Toyota,Tundra Hybrid CrewMax Toyota,Tundra Regular Cab Toyota,Venza Toyota,Xtra Cab Toyota,Yaris Toyota,Yaris Hatchback Toyota,Yaris iA Toyota,bZ4X VinFast,VF 8 VinFast,VF 9 Volkswagen,Arteon Volkswagen,Atlas Volkswagen,Atlas Cross Sport Volkswagen,Beetle Volkswagen,CC Volkswagen,Cabrio Volkswagen,Cabrio (New) Volkswagen,Cabriolet Volkswagen,Corrado Volkswagen,Eos Volkswagen,Eurovan Volkswagen,Fox Volkswagen,GLI Volkswagen,GTI Volkswagen,GTI (New) Volkswagen,Golf Volkswagen,Golf (New) Volkswagen,Golf Alltrack Volkswagen,Golf GTI Volkswagen,Golf III Volkswagen,Golf R Volkswagen,Golf SportWagen Volkswagen,ID.4 Volkswagen,ID.Buzz Volkswagen,Jetta Volkswagen,Jetta (New) Volkswagen,Jetta GLI Volkswagen,Jetta III Volkswagen,Jetta SportWagen Volkswagen,New Beetle Volkswagen,Passat Volkswagen,Passat (New) Volkswagen,Phaeton Volkswagen,R32 Volkswagen,Rabbit Volkswagen,Routan Volkswagen,Taos Volkswagen,Tiguan Volkswagen,Tiguan Limited Volkswagen,Touareg Volkswagen,Touareg 2 Volkswagen,e-Golf Volvo,240 Volvo,740 Volvo,850 Volvo,940 Volvo,960 Volvo,C30 Volvo,C40 Recharge Volvo,C70 Volvo,EX90 Volvo,S40 Volvo,S40 (New) Volvo,S60 Volvo,S70 Volvo,S80 Volvo,S90 Volvo,V40 Volvo,V50 Volvo,V60 Volvo,V70 Volvo,V90 Volvo,XC40 Volvo,XC40 Recharge Volvo,XC60 Volvo,XC70 Volvo,XC90 smart,fortwo smart,fortwo EQ cabrio smart,fortwo EQ coupe smart,fortwo cabrio smart,fortwo electric drive smart,fortwo electric drive cabrio From dino at no.spam.ar Sat Mar 4 23:12:28 2023 From: dino at no.spam.ar (Dino) Date: Sat, 4 Mar 2023 23:12:28 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: Message-ID: On 3/4/2023 10:43 PM, Dino wrote: > > I need fast text-search on a large (not huge, let's say 30k records > totally) list of items. Here's a sample of my raw data (a list of US > cars: model and make) I suspect I am really close to answering my own question... >>> import time >>> lis = [str(a**2+a*3+a) for a in range(0,30000)] >>> s = time.process_time_ns(); res = [el for el in lis if "13467" in el]; print(time.process_time_ns() -s); 753800 >>> s = time.process_time_ns(); res = [el for el in lis if "52356" in el]; print(time.process_time_ns() -s); 1068300 >>> s = time.process_time_ns(); res = [el for el in lis if "5256" in el]; print(time.process_time_ns() -s); 862000 >>> s = time.process_time_ns(); res = [el for el in lis if "6" in el]; print(time.process_time_ns() -s); 1447300 >>> s = time.process_time_ns(); res = [el for el in lis if "1" in el]; print(time.process_time_ns() -s); 1511100 >>> s = time.process_time_ns(); res = [el for el in lis if "13467" in el]; print(time.process_time_ns() -s); print(len(res), res[:10]) 926900 2 ['134676021', '313467021'] >>> I can do a substring search in a list of 30k elements in less than 2ms with Python. Is my reasoning sound? Dino From aapost at idontexist.club Sun Mar 5 09:35:15 2023 From: aapost at idontexist.club (aapost) Date: Sun, 5 Mar 2023 09:35:15 -0500 Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. Message-ID: I have run in to this a few times and finally reproduced it. Whether it is as expected I am not sure since it is slightly on the user, but I can think of scenarios where this would be undesirable behavior.. This occurs on 3.11.1 and 3.11.2 using debian 12 testing, in case the reasoning lingers somewhere else. If a file is still open, even if all the operations on the file have ceased for a time, the tail of the written operation data does not get flushed to the file until close is issued and the file closes cleanly. 2 methods to recreate - 1st run from interpreter directly: f = open("abc", "w") for i in range(50000): f.write(str(i) + "\n") you can cat the file and see it stops at 49626 until you issue an f.close() a script to recreate: f = open("abc", "w") for i in range(50000): f.write(str(i) + "\n") while(1): pass cat out the file and same thing, stops at 49626. a ctrl-c exit closes the files cleanly, but if the file exits uncleanly, i.e. a kill command or something else catastrophic. the remaining buffer is lost. Of course one SHOULD manage the closing of their files and this is partially on the user, but if by design something is hanging on to a file while it is waiting for something, then a crash occurs, they lose a portion of what was assumed already complete... From aapost at idontexist.club Sun Mar 5 10:38:41 2023 From: aapost at idontexist.club (aapost) Date: Sun, 5 Mar 2023 10:38:41 -0500 Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. In-Reply-To: References: Message-ID: On 3/5/23 09:35, aapost wrote: > Guess it could just be an annoying gotcha thing on me. calling at least f.flush() in any cases where an explicit close is delayed would be the solution. Additionally (not sure if this still applies): flush() does not necessarily write the file?s data to disk. Use flush() followed by os.fsync() to ensure this behavior. From nospam_2023 at efbe.prima.de Sun Mar 5 11:37:38 2023 From: nospam_2023 at efbe.prima.de (Frank B) Date: Sun, 5 Mar 2023 17:37:38 +0100 Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. In-Reply-To: References: Message-ID: Am 05.03.23 um 15:35 schrieb aapost: > I have run in to this a few times and finally reproduced it. Whether it > is as expected I am not sure since it is slightly on the user, but I can > think of scenarios where this would be undesirable behavior.. This > occurs on 3.11.1 and 3.11.2 using debian 12 testing, in case the > reasoning lingers somewhere else. > > If a file is still open, even if all the operations on the file have > ceased for a time, the tail of the written operation data does not get > flushed to the file until close is issued and the file closes cleanly. > > 2 methods to recreate - 1st run from interpreter directly: > > f = open("abc", "w") > for i in range(50000): > ? f.write(str(i) + "\n") use with open("abc", "w") as f: for i in range(50000): f.write(str(i) + "\n") and all is well Frank From aapost at idontexist.club Sun Mar 5 17:59:39 2023 From: aapost at idontexist.club (aapost) Date: Sun, 5 Mar 2023 17:59:39 -0500 Subject: Cutting slices In-Reply-To: References: Message-ID: On 3/5/23 17:43, Stefan Ram wrote: > The following behaviour of Python strikes me as being a bit > "irregular". A user tries to chop of sections from a string, > but does not use "split" because the separator might become > more complicated so that a regular expression will be required > to find it. But for now, let's use a simple "find": > > |>>> s = 'alpha.beta.gamma' > |>>> s[ 0: s.find( '.', 0 )] > |'alpha' > |>>> s[ 6: s.find( '.', 6 )] > |'beta' > |>>> s[ 11: s.find( '.', 11 )] > |'gamm' > |>>> > > . The user always inserted the position of the previous find plus > one to start the next "find", so he uses "0", "6", and "11". > But the "a" is missing from the final "gamma"! > > And it seems that there is no numerical value at all that > one can use for "n" in "string[ 0: n ]" to get the whole > string, isn't it? > > I would agree with 1st part of the comment. Just noting that string[11:], string[11:None], as well as string[11:16] work ... as well as string[11:324242]... lol.. From cs at cskk.id.au Sun Mar 5 18:48:09 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 6 Mar 2023 10:48:09 +1100 Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. In-Reply-To: References: Message-ID: On 05Mar2023 09:35, aapost wrote: >I have run in to this a few times and finally reproduced it. Whether >it is as expected I am not sure since it is slightly on the user, but >I can think of scenarios where this would be undesirable behavior.. >This occurs on 3.11.1 and 3.11.2 using debian 12 testing, in case the >reasoning lingers somewhere else. > >If a file is still open, even if all the operations on the file have >ceased for a time, the tail of the written operation data does not get >flushed to the file until close is issued and the file closes cleanly. Yes, because files are _buffered_ by default. See the `buffering` parameter to the open() function in the docs. >2 methods to recreate - 1st run from interpreter directly: > >f = open("abc", "w") >for i in range(50000): > f.write(str(i) + "\n") > >you can cat the file and see it stops at 49626 until you issue an f.close() Or until you issue an `f.flush()`. hich is what flush is for. >cat out the file and same thing, stops at 49626. a ctrl-c exit closes >the files cleanly, but if the file exits uncleanly, i.e. a kill command >or something else catastrophic. the remaining buffer is lost. Yes, because of bfufering. This is normal and IMO correct. You can turn it off, or catch-and-flush these circumstances (SIGKILL excepted, because SIGKILL's entire purpose it to be uncatchable). >Of course one SHOULD manage the closing of their files and this is >partially on the user, but if by design something is hanging on to a >file while it is waiting for something, then a crash occurs, they lose >a portion of what was assumed already complete... f.flush() Cheers, Cameron Simpson From PythonList at DancesWithMice.info Sun Mar 5 19:28:01 2023 From: PythonList at DancesWithMice.info (dn) Date: Mon, 6 Mar 2023 13:28:01 +1300 Subject: Cutting slices In-Reply-To: References: Message-ID: On 06/03/2023 11.59, aapost wrote: > On 3/5/23 17:43, Stefan Ram wrote: >> ?? The following behaviour of Python strikes me as being a bit >> ?? "irregular". A user tries to chop of sections from a string, >> ?? but does not use "split" because the separator might become >> ?? more complicated so that a regular expression will be required >> ?? to find it. But for now, let's use a simple "find": >> |>>> s = 'alpha.beta.gamma' >> |>>> s[ 0: s.find( '.', 0 )] >> |'alpha' >> |>>> s[ 6: s.find( '.', 6 )] >> |'beta' >> |>>> s[ 11: s.find( '.', 11 )] >> |'gamm' >> |>>> >> >> ?? . The user always inserted the position of the previous find plus >> ?? one to start the next "find", so he uses "0", "6", and "11". >> ?? But the "a" is missing from the final "gamma"! >> ?? And it seems that there is no numerical value at all that >> ?? one can use for "n" in "string[ 0: n ]" to get the whole >> ?? string, isn't it? >> >> > > I would agree with 1st part of the comment. > > Just noting that string[11:], string[11:None], as well as string[11:16] > work ... as well as string[11:324242]... lol.. To expand on the above, answering the OP's second question: the numeric value is len( s ). If the repetitive process is required, try a loop like: >>> start_index = 11 #to cure the issue-raised >>> try: ... s[ start_index:s.index( '.', start_index ) ] ... except ValueError: ... s[ start_index:len( s ) ] ... 'gamma' However, if the objective is to split, then use the function built for the purpose: >>> s.split( "." ) ['alpha', 'beta', 'gamma'] (yes, the OP says this won't work - but doesn't show why) If life must be more complicated, but the next separator can be predicted, then its close-relative is partition(). NB can use both split() and partition() on the sub-strings produced by an earlier split() or ... ie there may be no reason to work strictly from left to right - can't really help with this because the information above only shows multiple "." characters, and not how multiple separators might be interpreted. A straight-line approach might be to use maketrans() and translate() to convert all the separators to a single character, eg white-space, which can then be split using any of the previously-mentioned methods. If the problem is sufficiently complicated and the OP is prepared to go whole-hog, then PSL's tokenize library or various parser libraries may be worth consideration... -- Regards, =dn From eryksun at gmail.com Sun Mar 5 19:36:54 2023 From: eryksun at gmail.com (Eryk Sun) Date: Sun, 5 Mar 2023 18:36:54 -0600 Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. In-Reply-To: References: Message-ID: On 3/5/23, aapost wrote: > > If a file is still open, even if all the operations on the file have > ceased for a time, the tail of the written operation data does not get > flushed to the file until close is issued and the file closes cleanly. This is normal behavior for buffered file I/O. There's no timer set to flush the buffer after operations have "ceased for a time". It automatically flushes only when the buffer is full or, for line buffering, when a newline is written. The default buffer size is based on the raw file object's _blksize attribute. If st_blksize can't be determined via fstat(), the default _blksize is 8 KiB. Here's an example on Linux. In this example, the buffer size is 4 KiB. >>> f = open('abc', 'w') >>> os.fstat(f.fileno()).st_blksize 4096 >>> f.buffer.raw._blksize 4096 >>> f.writelines(f'{i}\n' for i in range(50000)) >>> with open('abc') as g: g.readlines()[-1] ... '49626\n' >>> pre_flush_size = os.path.getsize('abc') >>> f.flush() >>> post_flush_size = os.path.getsize('abc') >>> post_flush_size - pre_flush_size 2238 Verify that this makes sense, based on what was left in the buffer prior to flushing: >>> remaining_lines = 50000 - 49626 - 1 >>> bytes_per_line = 6 >>> remaining_lines * bytes_per_line 2238 From rob.cliffe at btinternet.com Sun Mar 5 19:36:57 2023 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 6 Mar 2023 00:36:57 +0000 Subject: Cutting slices In-Reply-To: References: Message-ID: <699e6e5c-1c04-93a6-e558-58f3d036c0f7@btinternet.com> On 05/03/2023 22:59, aapost wrote: > On 3/5/23 17:43, Stefan Ram wrote: >> ?? The following behaviour of Python strikes me as being a bit >> ?? "irregular". A user tries to chop of sections from a string, >> ?? but does not use "split" because the separator might become >> ?? more complicated so that a regular expression will be required >> ?? to find it. But for now, let's use a simple "find": >> ?? |>>> s = 'alpha.beta.gamma' >> |>>> s[ 0: s.find( '.', 0 )] >> |'alpha' >> |>>> s[ 6: s.find( '.', 6 )] >> |'beta' >> |>>> s[ 11: s.find( '.', 11 )] >> |'gamm' >> |>>> >> >> ?? . The user always inserted the position of the previous find plus >> ?? one to start the next "find", so he uses "0", "6", and "11". >> ?? But the "a" is missing from the final "gamma"! >> ?? ?? And it seems that there is no numerical value at all that >> ?? one can use for "n" in "string[ 0: n ]" to get the whole >> ?? string, isn't it? >> >> > The final `find` returns -1 because there is no separator after 'gamma'. So you are asking for ??? s[ 11 : -1] which correctly returns 'gamm'. You need to test for this condition. Alternatively you could ensure that there is a final separator: ??? s = 'alpha.beta.gamma.' but you would still need to test when the string was exhausted. Best wishes Rob Cliffe From cs at cskk.id.au Sun Mar 5 19:02:02 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 6 Mar 2023 11:02:02 +1100 Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. In-Reply-To: References: Message-ID: On 05Mar2023 10:38, aapost wrote: >Additionally (not sure if this still applies): >flush() does not necessarily write the file?s data to disk. Use flush() >followed by os.fsync() to ensure this behavior. Yes. You almost _never_ need or want this behaviour. A database tends to fsync at the end of a transaction and at other critical points. However, once you've `flush()`ed the file the data are then in the hands of the OS, to get to disc in a timely but efficient fashion. Calling fsync(), like calling flush(), affects writing _efficiency_ by depriving the OS (or for flush(), the Python I/O buffering system) the opportunity to bundle further data efficiency. It will degrade the overall performance. Also, fsync() need not expedite the data getting to disc. It is equally valid that it just blocks your programme _until_ the data have gone to disc. I practice it probably does expedite things slightly, but the real world effect is that your pogramme will gratuitously block anyway, when it could just get on with its work, secure in the knowledge that the OS has its back. flush() is for causality - ensuring the data are on their way so that some external party _will_ see them rather than waiting forever for data with are lurking in the buffer. If that external party, for you, is an end user tailing a log file, then you might want to flush(0 at the end of every line. Note that there is a presupplied line-buffering mode you can choose which will cause a file to flush like that for you automatically. So when you flush is a policy decision which you can make either during the programme flow or to a less flexible degree when you open the file. As an example of choosing-to-flush, here's a little bit of code in a module I use for writing packet data to a stream (eg a TCP connection): https://github.com/cameron-simpson/css/blob/00ab1a8a64453dc8a39578b901cfa8d1c75c3de2/lib/python/cs/packetstream.py#L624 Starting at line 640: `if Q.empty():` it optionally pauses briefly to see if more packets are coming on the source queue. If another arrives, the flush() is _skipped_, and the decision to flush made again after the next packet is transcribed. In this way a busy source of packets can write maximally efficient data (full buffers) as long as there's new data coming from the queue, but if the queue is empty and stays empty for more that `grace` seconds we flush anyway so that the receiver _will_ still see the latest packet. Cheers, Cameron Simpson From greg.ewing at canterbury.ac.nz Sun Mar 5 20:36:37 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 6 Mar 2023 14:36:37 +1300 Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. In-Reply-To: References: Message-ID: On 6/03/23 1:02 pm, Cameron Simpson wrote: > Also, fsync() need not expedite the data getting to disc. It is equally > valid that it just blocks your programme _until_ the data have gone to > disc. Or until it *thinks* the data has gone to the disk. Some drives do buffering of their own, which may impose additional delays before the data actually gets written. -- Greg From rosuav at gmail.com Sun Mar 5 20:46:44 2023 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Mar 2023 12:46:44 +1100 Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. In-Reply-To: References: Message-ID: On Mon, 6 Mar 2023 at 12:41, Greg Ewing via Python-list wrote: > > On 6/03/23 1:02 pm, Cameron Simpson wrote: > > Also, fsync() need not expedite the data getting to disc. It is equally > > valid that it just blocks your programme _until_ the data have gone to > > disc. > > Or until it *thinks* the data has gone to the disk. Some drives > do buffering of their own, which may impose additional delays > before the data actually gets written. > Sadly true. Usually with SSDs. Unfortunately, at that point, there's nothing ANYONE can do about it, since the OS is deceived as much as anyone else. But Cameron is completely right in that fsync's primary job is "block until" rather than "do this sooner". Adding fsync calls might possibly cause a flush when one otherwise wouldn't have happened, but generally they'll slow things down in the interests of reliability. ChrisA From python at mrabarnett.plus.com Sun Mar 5 20:56:35 2023 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 6 Mar 2023 01:56:35 +0000 Subject: Cutting slices In-Reply-To: References: Message-ID: <0bebccb0-5afa-1b7e-68e9-74aa3bd1e70c@mrabarnett.plus.com> On 2023-03-06 00:28, dn via Python-list wrote: > On 06/03/2023 11.59, aapost wrote: >> On 3/5/23 17:43, Stefan Ram wrote: >>> ?? The following behaviour of Python strikes me as being a bit >>> ?? "irregular". A user tries to chop of sections from a string, >>> ?? but does not use "split" because the separator might become >>> ?? more complicated so that a regular expression will be required >>> ?? to find it. But for now, let's use a simple "find": >>> |>>> s = 'alpha.beta.gamma' >>> |>>> s[ 0: s.find( '.', 0 )] >>> |'alpha' >>> |>>> s[ 6: s.find( '.', 6 )] >>> |'beta' >>> |>>> s[ 11: s.find( '.', 11 )] >>> |'gamm' >>> |>>> >>> >>> ?? . The user always inserted the position of the previous find plus >>> ?? one to start the next "find", so he uses "0", "6", and "11". >>> ?? But the "a" is missing from the final "gamma"! >>> ?? And it seems that there is no numerical value at all that >>> ?? one can use for "n" in "string[ 0: n ]" to get the whole >>> ?? string, isn't it? >>> >>> >> >> I would agree with 1st part of the comment. >> >> Just noting that string[11:], string[11:None], as well as string[11:16] >> work ... as well as string[11:324242]... lol.. > > To expand on the above, answering the OP's second question: the numeric > value is len( s ). > > If the repetitive process is required, try a loop like: > > >>> start_index = 11 #to cure the issue-raised > > >>> try: > ... s[ start_index:s.index( '.', start_index ) ] > ... except ValueError: > ... s[ start_index:len( s ) ] > ... > 'gamma' > Somewhat off-topic, but... When there was a discussion about a None-coalescing operator, I thought that it would've been nice if .find and .rfind returned None instead of -1. There have been times when I've wanted to find the next space (or whatever) and have it return the length of the string if absent. That could've been accomplished with: s.find(' ', pos) ?? len(s) Other times I've wanted it to return -1. That could've been accomplished with: s.find(' ', pos) ?? -1 (There's a place in the re module where .rfind returning -1 is just the right value.) In this instance, slicing with None as the end is just what's wanted. Ah, well... From list1 at tompassin.net Sun Mar 5 21:05:10 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 5 Mar 2023 21:05:10 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: Message-ID: <16234bb6-761e-1315-0ad0-1f90cea6db27@tompassin.net> On 3/4/2023 11:12 PM, Dino wrote: > On 3/4/2023 10:43 PM, Dino wrote: >> >> I need fast text-search on a large (not huge, let's say 30k records >> totally) list of items. Here's a sample of my raw data (a list of US >> cars: model and make) > > I suspect I am really close to answering my own question... > > >>> import time > >>> lis = [str(a**2+a*3+a) for a in range(0,30000)] > >>> s = time.process_time_ns(); res = [el for el in lis if "13467" in > el]; print(time.process_time_ns() -s); > 753800 > >>> s = time.process_time_ns(); res = [el for el in lis if "52356" in > el]; print(time.process_time_ns() -s); > 1068300 > >>> s = time.process_time_ns(); res = [el for el in lis if "5256" in > el]; print(time.process_time_ns() -s); > 862000 > >>> s = time.process_time_ns(); res = [el for el in lis if "6" in el]; > print(time.process_time_ns() -s); > 1447300 > >>> s = time.process_time_ns(); res = [el for el in lis if "1" in el]; > print(time.process_time_ns() -s); > 1511100 > >>> s = time.process_time_ns(); res = [el for el in lis if "13467" in > el]; print(time.process_time_ns() -s); print(len(res), res[:10]) > 926900 > 2 ['134676021', '313467021'] > >>> > > I can do a substring search in a list of 30k elements in less than 2ms > with Python. Is my reasoning sound? I would probably ingest the data at startup into a dictionary - or perhaps several depending on your access patterns - and then you will only need to to a fast lookup in one or more dictionaries. If your access pattern would be easier with SQL queries, load the data into an SQLite database on startup. IOW, do the bulk of the work once at startup. From greg.ewing at canterbury.ac.nz Sun Mar 5 21:18:29 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 6 Mar 2023 15:18:29 +1300 Subject: Cutting slices In-Reply-To: References: Message-ID: On 6/03/23 11:43 am, Stefan Ram wrote: > A user tries to chop of sections from a string, > but does not use "split" because the separator might become > more complicated so that a regular expression will be required > to find it. What's wrong with re.split() in that case? -- Greg From avi.e.gross at gmail.com Sun Mar 5 22:56:26 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sun, 5 Mar 2023 22:56:26 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: Message-ID: <003601d94fdf$a025e680$e071b380$@gmail.com> Dino, Sending lots of data to an archived forum is not a great idea. I snipped most of it out below as not to replicate it. Your question does not look difficult unless your real question is about speed. Realistically, much of the time spent generally is in reading in a file and the actual search can be quite rapid with a wide range of methods. The data looks boring enough and seems to not have much structure other than one comma possibly separating two fields. Do you want the data as one wide filed or perhaps in two parts, which a CSV file is normally used to represent. Do you ever have questions like tell me all cars whose name begins with the letter D and has a V6 engine? If so, you may want more than a vanilla search. What exactly do you want to search for? Is it a set of built-in searches or something the user types in? The data seems to be sorted by the first field and then by the second and I did not check if some searches might be ambiguous. Can there be many entries containing III? Yep. Can the same words like Cruiser or Hybrid appear? So is this a one-time search or multiple searches once loaded as in a service that stays resident and fields requests. The latter may be worth speeding up. I don't NEED to know any of this but want you to know that the answer may depend on this and similar factors. We had a long discussion lately on whether to search using regular expressions or string methods. If your data is meant to be used once, you may not even need to read the file into memory, but read something like a line at a time and test it. Or, if you end up with more data like how many cylinders a car has, it may be time to read it in not just to a list of lines or such data structures, but get numpy/pandas involved and use their many search methods in something like a data.frame. Of course if you are worried about portability, keep using Get Regular Expression Print. Your example was: $ grep -i v60 all_cars_unique.csv Genesis,GV60 Volvo,V60 You seem to have wanted case folding and that is NOT a normal search. And your search is matching anything on any line. If you wanted only a complete field, such as all text after a comma to the end of the line, you could use grep specifications to say that. But once inside python, you would need to make choices depending on what kind of searches you want to allow but also things like do you want all matching lines shown if you search for say "a" ... -----Original Message----- From: Python-list On Behalf Of Dino Sent: Saturday, March 4, 2023 10:47 PM To: python-list at python.org Subject: Re: Fast full-text searching in Python (job for Whoosh?) Here's the complete data file should anyone care. Acura,CL Acura,ILX Acura,Integra Acura,Legend smart,fortwo electric drive smart,fortwo electric drive cabrio -- https://mail.python.org/mailman/listinfo/python-list From avi.e.gross at gmail.com Sun Mar 5 23:01:52 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sun, 5 Mar 2023 23:01:52 -0500 Subject: Cutting slices In-Reply-To: References: Message-ID: <003801d94fe0$62c75700$28560500$@gmail.com> I am not commenting on the technique or why it is chosen just the part where the last search looks for a non-existent period: s = 'alpha.beta.gamma' ... s[ 11: s.find( '.', 11 )] What should "find" do if it hits the end of a string without finding the period you claim is a divider? Could that be why gamma got truncated? Unless you can arrange for a terminal period, maybe you can reconsider the approach. -----Original Message----- From: Python-list On Behalf Of aapost Sent: Sunday, March 5, 2023 6:00 PM To: python-list at python.org Subject: Re: Cutting slices On 3/5/23 17:43, Stefan Ram wrote: > The following behaviour of Python strikes me as being a bit > "irregular". A user tries to chop of sections from a string, > but does not use "split" because the separator might become > more complicated so that a regular expression will be required > to find it. But for now, let's use a simple "find": > > |>>> s = 'alpha.beta.gamma' > |>>> s[ 0: s.find( '.', 0 )] > |'alpha' > |>>> s[ 6: s.find( '.', 6 )] > |'beta' > |>>> s[ 11: s.find( '.', 11 )] > |'gamm' > |>>> > > . The user always inserted the position of the previous find plus > one to start the next "find", so he uses "0", "6", and "11". > But the "a" is missing from the final "gamma"! > > And it seems that there is no numerical value at all that > one can use for "n" in "string[ 0: n ]" to get the whole > string, isn't it? > > I would agree with 1st part of the comment. Just noting that string[11:], string[11:None], as well as string[11:16] work ... as well as string[11:324242]... lol.. -- https://mail.python.org/mailman/listinfo/python-list From barry at barrys-emacs.org Mon Mar 6 07:34:28 2023 From: barry at barrys-emacs.org (Barry) Date: Mon, 6 Mar 2023 12:34:28 +0000 Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. In-Reply-To: References: Message-ID: <8C51B6DB-329C-4415-B2C5-FA3A519004F2@barrys-emacs.org> > On 6 Mar 2023, at 01:42, Greg Ewing via Python-list wrote: > > ?On 6/03/23 1:02 pm, Cameron Simpson wrote: >> Also, fsync() need not expedite the data getting to disc. It is equally valid that it just blocks your programme _until_ the data have gone to disc. > > Or until it *thinks* the data has gone to the disk. Some drives > do buffering of their own, which may impose additional delays > before the data actually gets written. This used to be an issue until Microsoft refused to certify and drive that lied about when data was persisted to the medium. WHQL? That had the effect of stooping driver manufactures having firmware to win benchmarking. Now the OS will use the commands to the drive that allow the OS to know the data is safe. Barry > > -- > Greg > -- > https://mail.python.org/mailman/listinfo/python-list > From gweatherby at uchc.edu Mon Mar 6 10:32:09 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Mon, 6 Mar 2023 15:32:09 +0000 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: <16234bb6-761e-1315-0ad0-1f90cea6db27@tompassin.net> References: <16234bb6-761e-1315-0ad0-1f90cea6db27@tompassin.net> Message-ID: Not sure if this is what Thomas meant, but I was also thinking dictionaries. Dino could build a set of dictionaries with keys ?a? through ?z? that contain data with those letters in them. (I?m assuming case insensitive search) and then just search ?v? if that?s what the user starts with. Increased performance may be achieved by building dictionaries ?aa?,?ab? ... ?zz. And so on. Of course, it?s trading CPU for memory usage, and there?s likely a point at which the cost of building dictionaries exceeds the savings in searching. From: Python-list on behalf of Thomas Passin Date: Sunday, March 5, 2023 at 9:07 PM To: python-list at python.org Subject: Re: Fast full-text searching in Python (job for Whoosh?) I would probably ingest the data at startup into a dictionary - or perhaps several depending on your access patterns - and then you will only need to to a fast lookup in one or more dictionaries. If your access pattern would be easier with SQL queries, load the data into an SQLite database on startup. IOW, do the bulk of the work once at startup. -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!lnP5Hxid5mAgwg8o141SvmHPgCBU8zEaHDgukrQm2igozg5H5XLoIkAmrsHtRbZHR68oYAQpRFPh-Z9telM$ From gweatherby at uchc.edu Mon Mar 6 10:35:02 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Mon, 6 Mar 2023 15:35:02 +0000 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: <003601d94fdf$a025e680$e071b380$@gmail.com> References: <003601d94fdf$a025e680$e071b380$@gmail.com> Message-ID: ?Dino, Sending lots of data to an archived forum is not a great idea. I snipped most of it out below as not to replicate it.? Surely in 2023, storage is affordable enough there?s no need to criticize Dino for posting complete information. If mailing space is a consideration, we could all help by keeping our replies short and to the point. From list1 at tompassin.net Mon Mar 6 11:03:02 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 6 Mar 2023 11:03:02 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: <16234bb6-761e-1315-0ad0-1f90cea6db27@tompassin.net> Message-ID: On 3/6/2023 10:32 AM, Weatherby,Gerard wrote: > Not sure if this is what Thomas meant, but I was also thinking dictionaries. > > Dino could build a set of dictionaries with keys ?a? through ?z? that contain data with those letters in them. (I?m assuming case insensitive search) and then just search ?v? if that?s what the user starts with. > > Increased performance may be achieved by building dictionaries ?aa?,?ab? ... ?zz. And so on. > > Of course, it?s trading CPU for memory usage, and there?s likely a point at which the cost of building dictionaries exceeds the savings in searching. Chances are it would only be seconds at most to build the data cache, and then subsequent queries would respond very quickly. > > From: Python-list on behalf of Thomas Passin > Date: Sunday, March 5, 2023 at 9:07 PM > To: python-list at python.org > Subject: Re: Fast full-text searching in Python (job for Whoosh?) > > I would probably ingest the data at startup into a dictionary - or > perhaps several depending on your access patterns - and then you will > only need to to a fast lookup in one or more dictionaries. > > If your access pattern would be easier with SQL queries, load the data > into an SQLite database on startup. > > IOW, do the bulk of the work once at startup. > -- > https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!lnP5Hxid5mAgwg8o141SvmHPgCBU8zEaHDgukrQm2igozg5H5XLoIkAmrsHtRbZHR68oYAQpRFPh-Z9telM$ From gweatherby at uchc.edu Mon Mar 6 11:03:51 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Mon, 6 Mar 2023 16:03:51 +0000 Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. In-Reply-To: References: Message-ID: Add f.reconfigure it you want line buffering in your example: f = open("abc", "w") f.reconfigure(line_buffering=True) for i in range(50000): f.write(str(i) + "\n") More Pythonic would be: with open("abc", "w") as f: for i in range(5000): print(i,file=f) From: Python-list on behalf of aapost Date: Sunday, March 5, 2023 at 6:33 PM To: python-list at python.org Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** I have run in to this a few times and finally reproduced it. Whether it is as expected I am not sure since it is slightly on the user, but I can think of scenarios where this would be undesirable behavior.. This occurs on 3.11.1 and 3.11.2 using debian 12 testing, in case the reasoning lingers somewhere else. If a file is still open, even if all the operations on the file have ceased for a time, the tail of the written operation data does not get flushed to the file until close is issued and the file closes cleanly. 2 methods to recreate - 1st run from interpreter directly: f = open("abc", "w") for i in range(50000): f.write(str(i) + "\n") you can cat the file and see it stops at 49626 until you issue an f.close() a script to recreate: f = open("abc", "w") for i in range(50000): f.write(str(i) + "\n") while(1): pass cat out the file and same thing, stops at 49626. a ctrl-c exit closes the files cleanly, but if the file exits uncleanly, i.e. a kill command or something else catastrophic. the remaining buffer is lost. Of course one SHOULD manage the closing of their files and this is partially on the user, but if by design something is hanging on to a file while it is waiting for something, then a crash occurs, they lose a portion of what was assumed already complete... -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!kBYMol9JmMVwZD0iSoeeR1fYTiX8DEG-V4LBm4aAw4IJQ6Am4Ql_HYRZOeO8XK3kZvq2_adnid-FeoHr37Tw2I7k$ From aapost at idontexist.club Sun Mar 5 20:40:07 2023 From: aapost at idontexist.club (aapost) Date: Sun, 5 Mar 2023 20:40:07 -0500 Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. In-Reply-To: References: Message-ID: On 3/5/23 09:35, aapost wrote: > I have run in to this a few times and finally reproduced it. Whether it > is as expected I am not sure since it is slightly on the user, but I can > think of scenarios where this would be undesirable behavior.. This > occurs on 3.11.1 and 3.11.2 using debian 12 testing, in case the > reasoning lingers somewhere else. > > If a file is still open, even if all the operations on the file have > ceased for a time, the tail of the written operation data does not get > flushed to the file until close is issued and the file closes cleanly. > > 2 methods to recreate - 1st run from interpreter directly: > > f = open("abc", "w") > for i in range(50000): > ? f.write(str(i) + "\n") > > you can cat the file and see it stops at 49626 until you issue an f.close() > > a script to recreate: > > f = open("abc", "w") > for i in range(50000): > ? f.write(str(i) + "\n") > while(1): > ? pass > > cat out the file and same thing, stops at 49626. a ctrl-c exit closes > the files cleanly, but if the file exits uncleanly, i.e. a kill command > or something else catastrophic. the remaining buffer is lost. > > Of course one SHOULD manage the closing of their files and this is > partially on the user, but if by design something is hanging on to a > file while it is waiting for something, then a crash occurs, they lose a > portion of what was assumed already complete... >Cameron >Eryk Yeah, I later noticed open() has the buffering option in the docs, and the warning on a subsequent page: Warning Calling f.write() without using the with keyword or calling f.close() might result in the arguments of f.write() not being completely written to the disk, even if the program exits successfully. I will have to set the buffer arg to 1. I just hadn't thought about buffering in quite a while since python just handles most of the things lower level languages don't. I guess my (of course incorrect) assumptions would have leaned toward some sort of auto handling of the flush, or a non-buffer default (not saying it should). And I understand why it is the way it is from a developer standpoint, it's sort of a mental thing in the moment, I was in a sysadmin way of thinking, switching around from doing things in bash with multiple terminals, forgetting the fundamentals of what the python interpreter is vs a sequence of terminal commands. That being said, while "with" is great for many use cases, I think its overuse causes concepts like flush and the underlying "whys" to atrophy (especially since it is obviously a concept that is still important). It also doesn't work well when doing quick and dirty work in the interpreter to build a file on the fly with a sequence of commands you haven't completely thought through yet, in addition to the not wanting to close yet, the subsequent indention requirement is annoying. f = open("fn", "w", 1) will be the go to for that type of work since now I know. Again, just nitpicking, lol. From bowman at montana.com Mon Mar 6 10:46:39 2023 From: bowman at montana.com (rbowman) Date: 6 Mar 2023 15:46:39 GMT Subject: Fast full-text searching in Python (job for Whoosh?) References: <16234bb6-761e-1315-0ad0-1f90cea6db27@tompassin.net> Message-ID: On Mon, 6 Mar 2023 15:32:09 +0000, Weatherby,Gerard wrote: > Increased performance may be achieved by building dictionaries ?aa?,?ab? > ... ?zz. And so on. Or a trie. There have been several implementations but I believe this is the most active: https://pypi.org/project/PyTrie/ From bowman at montana.com Mon Mar 6 10:52:28 2023 From: bowman at montana.com (rbowman) Date: 6 Mar 2023 15:52:28 GMT Subject: Fast full-text searching in Python (job for Whoosh?) References: <003601d94fdf$a025e680$e071b380$@gmail.com> Message-ID: On Mon, 6 Mar 2023 07:40:29 -0500, Dino wrote: > The idea that someone types into an input field and matches start > dancing in the browser made me think that this was exactly what I > needed, and hence I figured that asking here about Whoosh would be a > good idea. I know realize that Whoosh would be overkill for my use-case, > as a simple (case insensitive) query substring would get me 90% of what > I want. Speed is in the order of a few milliseconds out of the box, > which is chump change in the context of a web UI. For a web application the round trips to the server for the next set of suggestions swamp out the actual lookups. Use the developer console in your browser to look at the network traffic and you'll see it's busy. From aapost at idontexist.club Sun Mar 5 20:50:17 2023 From: aapost at idontexist.club (aapost) Date: Sun, 5 Mar 2023 20:50:17 -0500 Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. In-Reply-To: References: Message-ID: On 3/5/23 19:02, Cameron Simpson wrote: > On 05Mar2023 10:38, aapost wrote: >> Additionally (not sure if this still applies): >> flush() does not necessarily write the file?s data to disk. Use >> flush() followed by os.fsync() to ensure this behavior. > > Yes. You almost _never_ need or want this behaviour. A database tends to > fsync at the end of a transaction and at other critical points. > > However, once you've `flush()`ed the file the data are then in the hands > of the OS, to get to disc in a timely but efficient fashion. Calling > fsync(), like calling flush(), affects writing _efficiency_ by depriving > the OS (or for flush(), the Python I/O buffering system) the opportunity > to bundle further data efficiency. It will degrade the overall performance. > > Also, fsync() need not expedite the data getting to disc. It is equally > valid that it just blocks your programme _until_ the data have gone to > disc. I practice it probably does expedite things slightly, but the real > world effect is that your pogramme will gratuitously block anyway, when > it could just get on with its work, secure in the knowledge that the OS > has its back. > > flush() is for causality - ensuring the data are on their way so that > some external party _will_ see them rather than waiting forever for data > with are lurking in the buffer.? If that external party, for you, is an > end user tailing a log file, then you might want to flush(0 at the end > of every line.? Note that there is a presupplied line-buffering mode you > can choose which will cause a file to flush like that for you > automatically. > > So when you flush is a policy decision which you can make either during > the programme flow or to a less flexible degree when you open the file. > > As an example of choosing-to-flush, here's a little bit of code in a > module I use for writing packet data to a stream (eg a TCP connection): > https://github.com/cameron-simpson/css/blob/00ab1a8a64453dc8a39578b901cfa8d1c75c3de2/lib/python/cs/packetstream.py#L624 > > Starting at line 640: `if Q.empty():` it optionally pauses briefly to > see if more packets are coming on the source queue. If another arrives, > the flush() is _skipped_, and the decision to flush made again after the > next packet is transcribed. In this way a busy source of packets can > write maximally efficient data (full buffers) as long as there's new > data coming from the queue, but if the queue is empty and stays empty > for more that `grace` seconds we flush anyway so that the receiver > _will_ still see the latest packet. > > Cheers, > Cameron Simpson Thanks for the details. And yes, that above quote was from a non-official doc without a version reference that several forum posts were referencing, with no further reasoning as to why they make the suggestion or to what importance it was (for the uninformed trying to parse it, the suggestion could be because of anything, like python lacking something that maybe was fixed, or who knows.) Thanks. From auriocus at gmx.de Mon Mar 6 03:07:32 2023 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 6 Mar 2023 09:07:32 +0100 Subject: Cutting slices In-Reply-To: References: Message-ID: Am 05.03.23 um 23:43 schrieb Stefan Ram: > The following behaviour of Python strikes me as being a bit > "irregular". A user tries to chop of sections from a string, > but does not use "split" because the separator might become > more complicated so that a regular expression will be required > to find it. OK, so if you want to use an RE for splitting, can you not use re.split() ? It basically works like the built-in splitting in AWK >>> s='alphaAbetaBgamma' >>> import re >>> re.split(r'A|B|C', s) ['alpha', 'beta', 'gamma'] >>> Christian From dino at no.spam.ar Mon Mar 6 07:26:24 2023 From: dino at no.spam.ar (Dino) Date: Mon, 6 Mar 2023 07:26:24 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: Message-ID: On 3/5/2023 1:19 AM, Greg Ewing wrote: > I just did a similar test with your actual data and got > about the same result. If that's fast enough for you, > then you don't need to do anything fancy. thank you, Greg. That's what I am going to do in fact. From dino at no.spam.ar Mon Mar 6 07:28:50 2023 From: dino at no.spam.ar (Dino) Date: Mon, 6 Mar 2023 07:28:50 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: <16234bb6-761e-1315-0ad0-1f90cea6db27@tompassin.net> Message-ID: On 3/5/2023 9:05 PM, Thomas Passin wrote: > > I would probably ingest the data at startup into a dictionary - or > perhaps several depending on your access patterns - and then you will > only need to to a fast lookup in one or more dictionaries. > > If your access pattern would be easier with SQL queries, load the data > into an SQLite database on startup. Thank you. SQLite would be overkill here, plus all the machinery that I would need to set up to make sure that the DB is rebuilt/updated regularly. Do you happen to know something about Whoosh? have you ever used it? > IOW, do the bulk of the work once at startup. Sound advice Thank you From dino at no.spam.ar Mon Mar 6 07:40:29 2023 From: dino at no.spam.ar (Dino) Date: Mon, 6 Mar 2023 07:40:29 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: <003601d94fdf$a025e680$e071b380$@gmail.com> Message-ID: Thank you for taking the time to write such a detailed answer, Avi. And apologies for not providing more info from the get go. What I am trying to achieve here is supporting autocomplete (no pun intended) in a web form field, hence the -i case insensitive example in my initial question. Your points are all good, and my original question was a bit rushed. I guess that the problem was that I saw this video: https://www.youtube.com/watch?v=gRvZbYtwTeo&ab_channel=NextDayVideo The idea that someone types into an input field and matches start dancing in the browser made me think that this was exactly what I needed, and hence I figured that asking here about Whoosh would be a good idea. I know realize that Whoosh would be overkill for my use-case, as a simple (case insensitive) query substring would get me 90% of what I want. Speed is in the order of a few milliseconds out of the box, which is chump change in the context of a web UI. Thank you again for taking the time to look at my question Dino On 3/5/2023 10:56 PM, avi.e.gross at gmail.com wrote: > Dino, Sending lots of data to an archived forum is not a great idea. I > snipped most of it out below as not to replicate it. > > Your question does not look difficult unless your real question is about > speed. Realistically, much of the time spent generally is in reading in a > file and the actual search can be quite rapid with a wide range of methods. > > The data looks boring enough and seems to not have much structure other than > one comma possibly separating two fields. Do you want the data as one wide > filed or perhaps in two parts, which a CSV file is normally used to > represent. Do you ever have questions like tell me all cars whose name > begins with the letter D and has a V6 engine? If so, you may want more than > a vanilla search. > > What exactly do you want to search for? Is it a set of built-in searches or > something the user types in? > > The data seems to be sorted by the first field and then by the second and I > did not check if some searches might be ambiguous. Can there be many entries > containing III? Yep. Can the same words like Cruiser or Hybrid appear? > > So is this a one-time search or multiple searches once loaded as in a > service that stays resident and fields requests. The latter may be worth > speeding up. > > I don't NEED to know any of this but want you to know that the answer may > depend on this and similar factors. We had a long discussion lately on > whether to search using regular expressions or string methods. If your data > is meant to be used once, you may not even need to read the file into > memory, but read something like a line at a time and test it. Or, if you end > up with more data like how many cylinders a car has, it may be time to read > it in not just to a list of lines or such data structures, but get > numpy/pandas involved and use their many search methods in something like a > data.frame. > > Of course if you are worried about portability, keep using Get Regular > Expression Print. > > Your example was: > > $ grep -i v60 all_cars_unique.csv > Genesis,GV60 > Volvo,V60 > > You seem to have wanted case folding and that is NOT a normal search. And > your search is matching anything on any line. If you wanted only a complete > field, such as all text after a comma to the end of the line, you could use > grep specifications to say that. > > But once inside python, you would need to make choices depending on what > kind of searches you want to allow but also things like do you want all > matching lines shown if you search for say "a" ... > > From avi.e.gross at gmail.com Mon Mar 6 12:37:09 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Mon, 6 Mar 2023 12:37:09 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: <003601d94fdf$a025e680$e071b380$@gmail.com> Message-ID: <00d401d95052$470e7350$d52b59f0$@gmail.com> Gerard, I was politely pointing out how it was more than the minimum necessary and might gets repeated multiple times as people replied. The storage space is a resource someone else provides and I prefer not abusing it. However, since the OP seems to be asking a question focused on how long it takes to search using possible techniques, indeed some people would want the entire data to test with. In my personal view, the a snippet of the data is what I need to see how it is organized and then what I need way more is some idea for what kind of searching is needed. If I was told there would be a web page allowing users to search a web service hosting the data on a server with one process called as much as needed that spawned threads to handle the task, I might see it as very worthwhile to read in the data once into some data structure that allows rapid searches over and over. If it is an app called ONCE as a whole for each result, as in the grep example, why bother and just read a line at a time and be done with it. My suggestion remains my preference. The discussion is archived. Messages are can optimally be trimmed as needed and not allowed to contain the full contents of the last twenty replies back and forth unless that is needed. Larger amounts of data can be offered to share and if wanted, can be posted or send to someone asking for it or placed in some public accessible place. But my preference may not be relevant as the forum has hosts or owners and it is what they want that counts. The data this time was not really gigantic. But I often work with data from a CSV that has hundreds of columns and hundreds of thousands or more rows, with some of the columns containing large amounts of text. But I may be interested in how to work with say just half a dozen columns and for the purposes of my question here, perhaps a hundred representative rows. Should I share everything, or maybe save the subset and only share that? This is not about python as a language but about expressing ideas and opinions on a public forum with limited resources. Yes, over the years, my combined posts probably use far more archival space. We are not asked to be sparse, just not be wasteful. The OP may consider what he is working with as a LOT of data but it really isn't by modern standards. -----Original Message----- From: Python-list On Behalf Of Weatherby,Gerard Sent: Monday, March 6, 2023 10:35 AM To: python-list at python.org Subject: Re: Fast full-text searching in Python (job for Whoosh?) "Dino, Sending lots of data to an archived forum is not a great idea. I snipped most of it out below as not to replicate it." Surely in 2023, storage is affordable enough there's no need to criticize Dino for posting complete information. If mailing space is a consideration, we could all help by keeping our replies short and to the point. -- https://mail.python.org/mailman/listinfo/python-list From avi.e.gross at gmail.com Mon Mar 6 12:49:20 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Mon, 6 Mar 2023 12:49:20 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: <16234bb6-761e-1315-0ad0-1f90cea6db27@tompassin.net> Message-ID: <00d901d95053$fb3a7440$f1af5cc0$@gmail.com> Thomas, I may have missed any discussion where the OP explained more about proposed usage. If the program is designed to load the full data once, never get updates except by re-reading some file, and then handles multiple requests, then some things may be worth doing. It looked to me, and I may well be wrong, like he wanted to search for a string anywhere in the text so a grep-like solution is a reasonable start with the actual data being stored as something like a list of character strings you can search "one line" at a time. I suspect a numpy variant may work faster. And of course any search function he builds can be made to remember some or all previous searches using a cache decorator. That generally uses a dictionary for the search keys internally. But using lots of dictionaries strikes me as only helping if you are searching for text anchored to the start of a line so if you ask for "Honda" you instead ask the dictionary called "h" and search perhaps just for "onda" then recombine the prefix in any results. But the example given wanted to match something like "V6" in middle of the text and I do not see how that would work as you would now need to search 26 dictionaries completely. -----Original Message----- From: Python-list On Behalf Of Thomas Passin Sent: Monday, March 6, 2023 11:03 AM To: python-list at python.org Subject: Re: Fast full-text searching in Python (job for Whoosh?) On 3/6/2023 10:32 AM, Weatherby,Gerard wrote: > Not sure if this is what Thomas meant, but I was also thinking dictionaries. > > Dino could build a set of dictionaries with keys ?a? through ?z? that contain data with those letters in them. (I?m assuming case insensitive search) and then just search ?v? if that?s what the user starts with. > > Increased performance may be achieved by building dictionaries ?aa?,?ab? ... ?zz. And so on. > > Of course, it?s trading CPU for memory usage, and there?s likely a point at which the cost of building dictionaries exceeds the savings in searching. Chances are it would only be seconds at most to build the data cache, and then subsequent queries would respond very quickly. > > From: Python-list on behalf of Thomas Passin > Date: Sunday, March 5, 2023 at 9:07 PM > To: python-list at python.org > Subject: Re: Fast full-text searching in Python (job for Whoosh?) > > I would probably ingest the data at startup into a dictionary - or > perhaps several depending on your access patterns - and then you will > only need to to a fast lookup in one or more dictionaries. > > If your access pattern would be easier with SQL queries, load the data > into an SQLite database on startup. > > IOW, do the bulk of the work once at startup. > -- > https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!lnP5Hxid5mAgwg8o141SvmHPgCBU8zEaHDgukrQm2igozg5H5XLoIkAmrsHtRbZHR68oYAQpRFPh-Z9telM$ -- https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Mon Mar 6 12:50:54 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 6 Mar 2023 12:50:54 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: <16234bb6-761e-1315-0ad0-1f90cea6db27@tompassin.net> Message-ID: On 3/6/2023 7:28 AM, Dino wrote: > On 3/5/2023 9:05 PM, Thomas Passin wrote: >> >> I would probably ingest the data at startup into a dictionary - or >> perhaps several depending on your access patterns - and then you will >> only need to to a fast lookup in one or more dictionaries. >> >> If your access pattern would be easier with SQL queries, load the data >> into an SQLite database on startup. > > Thank you. SQLite would be overkill here, plus all the machinery that I > would need to set up to make sure that the DB is rebuilt/updated regularly. > Do you happen to know something about Whoosh? have you ever used it? I know nothing about it, sorry. But anything beyond python dictionaries and possibly some lists strikes me as overkill for what you have described. >> IOW, do the bulk of the work once at startup. > > Sound advice > > Thank you From dieter at handshake.de Mon Mar 6 13:31:00 2023 From: dieter at handshake.de (Dieter Maurer) Date: Mon, 6 Mar 2023 19:31:00 +0100 Subject: Bug 3.11.x behavioral, open file buffers not flushed til file closed. In-Reply-To: References: Message-ID: <25606.12644.201879.210578@ixdm.fritz.box> aapost wrote at 2023-3-5 09:35 -0500: > ... >If a file is still open, even if all the operations on the file have >ceased for a time, the tail of the written operation data does not get >flushed to the file until close is issued and the file closes cleanly. This is normal: the buffer is flushed if one of the following conditions are met: 1. you call `flush` 2. the buffer overflows 3. the file is closed. From avi.e.gross at gmail.com Mon Mar 6 13:45:34 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Mon, 6 Mar 2023 13:45:34 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: <00ed01d9505b$bb66e8f0$3234bad0$@gmail.com> References: <003601d94fdf$a025e680$e071b380$@gmail.com> <00ed01d9505b$bb66e8f0$3234bad0$@gmail.com> Message-ID: <00f301d9505b$d5e019e0$81a04da0$@gmail.com> Ah, thanks Dino. Autocomplete within a web page can be an interesting scenario but also a daunting one. Now, do you mean you have a web page with a text field, initially I suppose empty, and the user types a single character and rapidly a drop-down list or something is created and shown? And as they type, it may shrink? And as soon as they select one, it is replaced in the text field and done? If your form has an attached function written in JavaScript, some might load your data into the browser and do all that work from within. No python needed. Now if your scenario is similar to the above, or perhaps the user needs to ask for autocompletion by using tab or something, and you want to keep sending requests to a server, you can of course use any language on the server. BUT I would be cautious in such a design. My guess is you autocomplete on every keystroke and the user may well type multiple characters resulting in multiple requests for your program. Is a new one called every time or is it a running service. If the latter, it pays to read in the data once and then carefully serve it. But when you get just the letter "h" you may not want to send and process a thousand results but limit It to say the first N. If they then add an o to make a ho, You may not need to do much if it is anchored to the start except to search in the results of the previous search rather than the whole data. But have you done some searching on how autocomplete from a fixed corpus is normally done? It is a quite common thing. -----Original Message----- From: Python-list On Behalf Of Dino Sent: Monday, March 6, 2023 7:40 AM To: python-list at python.org Subject: Re: RE: Fast full-text searching in Python (job for Whoosh?) Thank you for taking the time to write such a detailed answer, Avi. And apologies for not providing more info from the get go. What I am trying to achieve here is supporting autocomplete (no pun intended) in a web form field, hence the -i case insensitive example in my initial question. Your points are all good, and my original question was a bit rushed. I guess that the problem was that I saw this video: https://www.youtube.com/watch?v=gRvZbYtwTeo&ab_channel=NextDayVideo The idea that someone types into an input field and matches start dancing in the browser made me think that this was exactly what I needed, and hence I figured that asking here about Whoosh would be a good idea. I know realize that Whoosh would be overkill for my use-case, as a simple (case insensitive) query substring would get me 90% of what I want. Speed is in the order of a few milliseconds out of the box, which is chump change in the context of a web UI. Thank you again for taking the time to look at my question Dino On 3/5/2023 10:56 PM, avi.e.gross at gmail.com wrote: > Dino, Sending lots of data to an archived forum is not a great idea. I > snipped most of it out below as not to replicate it. > > Your question does not look difficult unless your real question is about > speed. Realistically, much of the time spent generally is in reading in a > file and the actual search can be quite rapid with a wide range of methods. > > The data looks boring enough and seems to not have much structure other than > one comma possibly separating two fields. Do you want the data as one wide > filed or perhaps in two parts, which a CSV file is normally used to > represent. Do you ever have questions like tell me all cars whose name > begins with the letter D and has a V6 engine? If so, you may want more than > a vanilla search. > > What exactly do you want to search for? Is it a set of built-in searches or > something the user types in? > > The data seems to be sorted by the first field and then by the second and I > did not check if some searches might be ambiguous. Can there be many entries > containing III? Yep. Can the same words like Cruiser or Hybrid appear? > > So is this a one-time search or multiple searches once loaded as in a > service that stays resident and fields requests. The latter may be worth > speeding up. > > I don't NEED to know any of this but want you to know that the answer may > depend on this and similar factors. We had a long discussion lately on > whether to search using regular expressions or string methods. If your data > is meant to be used once, you may not even need to read the file into > memory, but read something like a line at a time and test it. Or, if you end > up with more data like how many cylinders a car has, it may be time to read > it in not just to a list of lines or such data structures, but get > numpy/pandas involved and use their many search methods in something like a > data.frame. > > Of course if you are worried about portability, keep using Get Regular > Expression Print. > > Your example was: > > $ grep -i v60 all_cars_unique.csv > Genesis,GV60 > Volvo,V60 > > You seem to have wanted case folding and that is NOT a normal search. And > your search is matching anything on any line. If you wanted only a complete > field, such as all text after a comma to the end of the line, you could use > grep specifications to say that. > > But once inside python, you would need to make choices depending on what > kind of searches you want to allow but also things like do you want all > matching lines shown if you search for say "a" ... > > -- https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Mon Mar 6 13:38:15 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 6 Mar 2023 13:38:15 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: <00d901d95053$fb3a7440$f1af5cc0$@gmail.com> References: <16234bb6-761e-1315-0ad0-1f90cea6db27@tompassin.net> <00d901d95053$fb3a7440$f1af5cc0$@gmail.com> Message-ID: On 3/6/2023 12:49 PM, avi.e.gross at gmail.com wrote: > Thomas, > > I may have missed any discussion where the OP explained more about proposed usage. If the program is designed to load the full data once, never get updates except by re-reading some file, and then handles multiple requests, then some things may be worth doing. > > It looked to me, and I may well be wrong, like he wanted to search for a string anywhere in the text so a grep-like solution is a reasonable start with the actual data being stored as something like a list of character strings you can search "one line" at a time. I suspect a numpy variant may work faster. > > And of course any search function he builds can be made to remember some or all previous searches using a cache decorator. That generally uses a dictionary for the search keys internally. > > But using lots of dictionaries strikes me as only helping if you are searching for text anchored to the start of a line so if you ask for "Honda" you instead ask the dictionary called "h" and search perhaps just for "onda" then recombine the prefix in any results. But the example given wanted to match something like "V6" in middle of the text and I do not see how that would work as you would now need to search 26 dictionaries completely. Well, that's the question, isn't it? Just how is this expected to be used? I didn't read the initial posting that carefully, and I may have missed something that makes a difference. The OP gives as an example a user entering a string ("v60"). The example is for a model designation. If we know that this entry box will only receive model, then I would populate a dictionary using the model numbers as keys. The number of distinct keys will probably not be that large. For example, highly simplified of course: >>> models = {'v60': 'Volvo', 'GV60': 'Genesis', 'cl': 'Acura'} >>> entry = '60' >>> candidates = (m for m in models.keys() if entry in m) >>> list(candidates) ['v60', 'GV60'] The keys would be lower-cased. A separate dictionary would give the complete string with the desired casing. The values could be object references to the complete information. If there might be several different models models with the same key, then the values could be lists or dictionaries and one would need to do some disambiguation, but that should be simple or quick. It all depends on the planned access patterns. If the OP really wants full-text search in the complete unstructured data file, then yes, a full text indexer of some kind will be useful. Whoosh certainly looks good though I have not used it. But for populating dropdown lists in web forms, most likely the design of the form will provide a structure for the various searches. > -----Original Message----- > From: Python-list On Behalf Of Thomas Passin > Sent: Monday, March 6, 2023 11:03 AM > To: python-list at python.org > Subject: Re: Fast full-text searching in Python (job for Whoosh?) > > On 3/6/2023 10:32 AM, Weatherby,Gerard wrote: >> Not sure if this is what Thomas meant, but I was also thinking dictionaries. >> >> Dino could build a set of dictionaries with keys ?a? through ?z? that contain data with those letters in them. (I?m assuming case insensitive search) and then just search ?v? if that?s what the user starts with. >> >> Increased performance may be achieved by building dictionaries ?aa?,?ab? ... ?zz. And so on. >> >> Of course, it?s trading CPU for memory usage, and there?s likely a point at which the cost of building dictionaries exceeds the savings in searching. > > Chances are it would only be seconds at most to build the data cache, > and then subsequent queries would respond very quickly. > >> >> From: Python-list on behalf of Thomas Passin >> Date: Sunday, March 5, 2023 at 9:07 PM >> To: python-list at python.org >> Subject: Re: Fast full-text searching in Python (job for Whoosh?) >> >> I would probably ingest the data at startup into a dictionary - or >> perhaps several depending on your access patterns - and then you will >> only need to to a fast lookup in one or more dictionaries. >> >> If your access pattern would be easier with SQL queries, load the data >> into an SQLite database on startup. >> >> IOW, do the bulk of the work once at startup. >> -- >> https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!lnP5Hxid5mAgwg8o141SvmHPgCBU8zEaHDgukrQm2igozg5H5XLoIkAmrsHtRbZHR68oYAQpRFPh-Z9telM$ > From greg.ewing at canterbury.ac.nz Mon Mar 6 18:06:23 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 7 Mar 2023 12:06:23 +1300 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: <003601d94fdf$a025e680$e071b380$@gmail.com> Message-ID: On 7/03/23 4:35 am, Weatherby,Gerard wrote: > If mailing space is a consideration, we could all help by keeping our replies short and to the point. Indeed. A thread or two of untrimmed quoted messages is probably more data than Dino posted! -- Greg From greg.ewing at canterbury.ac.nz Mon Mar 6 18:10:35 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 7 Mar 2023 12:10:35 +1300 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: <16234bb6-761e-1315-0ad0-1f90cea6db27@tompassin.net> <00d901d95053$fb3a7440$f1af5cc0$@gmail.com> Message-ID: On 7/03/23 6:49 am, avi.e.gross at gmail.com wrote: > But the example given wanted to match something like "V6" in middle of the text and I do not see how that would work as you would now need to search 26 dictionaries completely. It might even make things worse, as there is likely to be a lot of overlap between entries containing "V" and entries containing "6", so you end up searching the same data multiple times. -- Greg From dino at no.spam.ar Mon Mar 6 21:55:37 2023 From: dino at no.spam.ar (Dino) Date: Mon, 6 Mar 2023 21:55:37 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: Message-ID: On 3/4/2023 10:43 PM, Dino wrote: > > I need fast text-search on a large (not huge, let's say 30k records > totally) list of items. Here's a sample of my raw data (a list of US > cars: model and make) Gentlemen, thanks a ton to everyone who offered to help (and did help!). I loved the part where some tried to divine the true meaning of my words :) What you guys wrote is correct: the grep-esque search is guaranteed to turn up a ton of false positives, but for the autofill use-case, that's actually OK. Users will quickly figure what is not relevant and skip those entries, just to zero on in on the suggestion that they find relevant. One issue that was also correctly foreseen by some is that there's going to be a new request at every user key stroke. Known problem. JavaScript programmers use a trick called "debounceing" to be reasonably sure that the user is done typing before a request is issued: https://schier.co/blog/wait-for-user-to-stop-typing-using-javascript I was able to apply that successfully and I am now very pleased with the final result. Apologies if I posted 1400 lines or data file. Seeing that certain newsgroups carry gigabytes of copyright infringing material must have conveyed the wrong impression to me. Thank you. Dino From bowman at montana.com Mon Mar 6 23:05:19 2023 From: bowman at montana.com (rbowman) Date: 7 Mar 2023 04:05:19 GMT Subject: Fast full-text searching in Python (job for Whoosh?) References: Message-ID: On Mon, 6 Mar 2023 21:55:37 -0500, Dino wrote: > ne issue that was also correctly foreseen by some is that there's going > to be a new request at every user key stroke. Known problem. JavaScript > programmers use a trick called "debounceing" to be reasonably sure that > the user is done typing before a request is issued: > > https://schier.co/blog/wait-for-user-to-stop-typing-using-javascript That could be annoying. My use case is address entry. When the user types 102 ma the suggestions might be main manson maple massachusetts masten in a simple case. When they enter 's' it's narrowed down. Typically I'm only dealing with a city or county so the data to be searched isn't huge. The maps.google.com address search covers the world and they're also throwing in a geographical constraint so the suggestions are applicable to the area you're viewing. It must be nice to have a server or two... From stephen_tucker at sil.org Tue Mar 7 00:51:57 2023 From: stephen_tucker at sil.org (Stephen Tucker) Date: Tue, 7 Mar 2023 05:51:57 +0000 Subject: Python 2.7 range Function provokes a Memory Error In-Reply-To: References: Message-ID: Hi again, I tried xrange, but I got an error telling me that my integer was too big for a C long. Clearly, xrange in Py2 is not capable of dealing with Python (that is, possibly very long) integers. I am raising this because, (a) IF xrange in Py3 is a simple "port" from Py2, then it won't handle Python integers either. AND (b) IF xrange in Py3 is intended to be equivalent to range (which, even in Py2, does handle Python integers) THEN It could be argued that xrange in Py3 needs some attention from the developer(s). Stephen Tucker. On Thu, Mar 2, 2023 at 6:24?PM Jon Ribbens via Python-list < python-list at python.org> wrote: > On 2023-03-02, Stephen Tucker wrote: > > The range function in Python 2.7 (and yes, I know that it is now > > superseded), provokes a Memory Error when asked to deiliver a very long > > list of values. > > > > I assume that this is because the function produces a list which it then > > iterates through. > > > > 1. Does the range function in Python 3.x behave the same way? > > No, in Python 3 it is an iterator which produces the next number in the > sequence each time. > > > 2. Is there any equivalent way that behaves more like a for loop (that > is, > > without producing a list)? > > Yes, 'xrange' in Python 2 behaves like 'range' in Python 3. > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Tue Mar 7 01:37:34 2023 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Mar 2023 17:37:34 +1100 Subject: Python 2.7 range Function provokes a Memory Error In-Reply-To: References: Message-ID: On Tue, 7 Mar 2023 at 16:53, Stephen Tucker wrote: > > Hi again, > > I tried xrange, but I got an error telling me that my integer was too big > for a C long. > > Clearly, xrange in Py2 is not capable of dealing with Python (that is, > possibly very long) integers. That's because Py2 has two different integer types, int and long. > I am raising this because, > > (a) IF xrange in Py3 is a simple "port" from Py2, then it won't handle > Python integers either. > > AND > > (b) IF xrange in Py3 is intended to be equivalent to range (which, even in > Py2, does handle Python integers) > > THEN > > It could be argued that xrange in Py3 needs some attention from the > developer(s). Why don't you actually try Python 3 instead of making assumptions based on the state of Python from more than a decade ago? ChrisA From hjp-python at hjp.at Tue Mar 7 08:24:38 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 7 Mar 2023 14:24:38 +0100 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: Message-ID: <20230307132438.wx4suffhnb6x2ixk@hjp.at> On 2023-03-07 04:05:19 +0000, rbowman wrote: > On Mon, 6 Mar 2023 21:55:37 -0500, Dino wrote: > > ne issue that was also correctly foreseen by some is that there's going > > to be a new request at every user key stroke. Known problem. JavaScript > > programmers use a trick called "debounceing" to be reasonably sure that > > the user is done typing before a request is issued: > > > > https://schier.co/blog/wait-for-user-to-stop-typing-using-javascript > > That could be annoying. My use case is address entry. When the user types It can be. The delay is short but noticeable. A somewhat smarter strategy is to send each query as soon as the user hit the key but keep track of what you sent and received and discard responses for obsolete requests (This is necessary because if you first send "ma" and then "mas", the response to the first query might arrive after the response to the second query and you don't want to display "mansion" if the user already typed "mas".) 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 david at lowryduda.com Tue Mar 7 13:28:52 2023 From: david at lowryduda.com (David Lowry-Duda) Date: Tue, 7 Mar 2023 13:28:52 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: Message-ID: On 22:43 Sat 04 Mar 2023, Dino wrote: >How can I implement this? A library called Whoosh seems very promising >(albeit it's so feature-rich that it's almost like shooting a fly with >a bazooka in my case), but I see two problems: > > 1) Whoosh is either abandoned or the project is a mess in terms of >community and support >(https://groups.google.com/g/whoosh/c/QM_P8cGi4v4 ) and > > 2) Whoosh seems to be a Python only thing, which is great for now, >but I wouldn't want this to become an obstacle should I need port it to >a different language at some point. As others have noted, it sounds like relatively straightforward implementations will be sufficient. But I'll note that I use whoosh from time to time and I find it stable and pleasant to work with. It's true that development stopped, but it stopped in a very stable place. I don't recommend using whoosh here, but I would recommend experimenting with it more generally. - DLD From avi.e.gross at gmail.com Tue Mar 7 14:02:03 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Tue, 7 Mar 2023 14:02:03 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: Message-ID: <005701d95127$4dc809b0$e9581d10$@gmail.com> Some of the discussions here leave me confused as the info we think we got early does not last long intact and often morphs into something else and we find much of the discussion is misdirected or wasted. Wouldn't it have been nice if this discussion had not started with a mention of a package/module few have heard of along with a vague request on how best to search for lines that match something in a file? I still do not know enough to feel comfortable even after all this time. It now seems to be a web-based application in which a web page wants to use autocompletion as the user types. So was the web page a static file that the user runs, or is it dynamically created by something like a python program? How is the fact that a user has typed a letter in a textbox or drop down of sorts reflected in a request being sent to a python program to return possible choices? Is the same process called anew each time or is it, or perhaps a group of similar processes or threads going to stick around and be called repeatedly? Lots of details are missing and in particular, much of what is being described sounds like it is happening in the browser, presumably in JavaScript. Also noted is that the first keystroke or two may return too much data. So does the OP still think this is a python question? So much of the discussion sounds like it is in the browser deciding whether to wait for the user to type more before making a request, or throwing away results of an older request. So my guess is that a possible design for this amount of data may simply be to read the file into the browser at startup, or when the first letter is typed, and do all the searches internally, perhaps cascaded as long as backspace or editing is not used. If the data gets much larger, of course, then using a server makes sense albeit it need not use python unless lots more in the project is also ... -----Original Message----- From: Python-list On Behalf Of David Lowry-Duda Sent: Tuesday, March 7, 2023 1:29 PM To: python-list at python.org Subject: Re: Fast full-text searching in Python (job for Whoosh?) On 22:43 Sat 04 Mar 2023, Dino wrote: >How can I implement this? A library called Whoosh seems very promising >(albeit it's so feature-rich that it's almost like shooting a fly with >a bazooka in my case), but I see two problems: > > 1) Whoosh is either abandoned or the project is a mess in terms of >community and support >(https://groups.google.com/g/whoosh/c/QM_P8cGi4v4 ) and > > 2) Whoosh seems to be a Python only thing, which is great for now, >but I wouldn't want this to become an obstacle should I need port it to >a different language at some point. As others have noted, it sounds like relatively straightforward implementations will be sufficient. But I'll note that I use whoosh from time to time and I find it stable and pleasant to work with. It's true that development stopped, but it stopped in a very stable place. I don't recommend using whoosh here, but I would recommend experimenting with it more generally. - DLD -- https://mail.python.org/mailman/listinfo/python-list From jf_byrnes at comcast.net Tue Mar 7 17:48:40 2023 From: jf_byrnes at comcast.net (Jim Byrnes) Date: Tue, 7 Mar 2023 16:48:40 -0600 Subject: test Message-ID: haven't received anything from the list for quite awhile. Got no response when I tried to contact the administrator. From PythonList at DancesWithMice.info Tue Mar 7 17:56:12 2023 From: PythonList at DancesWithMice.info (dn) Date: Wed, 8 Mar 2023 11:56:12 +1300 Subject: test In-Reply-To: References: Message-ID: <16e0c028-78b8-e6cb-3f15-fd5fb65a0cd4@DancesWithMice.info> On 08/03/2023 11.48, Jim Byrnes wrote: > haven't received anything from the list for quite awhile. Got no > response when I tried to contact the administrator. ACK -- Regards, =dn From PythonList at DancesWithMice.info Tue Mar 7 21:47:33 2023 From: PythonList at DancesWithMice.info (dn) Date: Wed, 8 Mar 2023 15:47:33 +1300 Subject: ANN: The long white computing cloud Message-ID: The long white computing cloud - hybrid meeting, ie both in-person and virtual attendance Wed 15 March, 1800 for 1830 (NZDT) = 0530 UTC 1 Cloud and Proud - Digital Sovereignty in Aotearoa Doug Dixon, CEO of Catalyst Cloud, Aotearoa New Zealand's cloud provider. 2 Python in the cloud How to get-started with the admin-stuff, and build a toy-application live-demo. (what could possibly go wrong!?) NB This will be a hybrid event and RSVPs are requested: https://www.meetup.com/nzpug-auckland/events/291789444/ All welcome! -- Regards, =dn From greggtag at gmail.com Tue Mar 7 14:31:10 2023 From: greggtag at gmail.com (Thomas Gregg) Date: Tue, 7 Mar 2023 14:31:10 -0500 Subject: Winodws10 Command Prompt unresponsive to .py commands Message-ID: Hi, I got python 11 to work with the esptool a few days ago. However, I must have something wrong, because now, when I enter any command with .py, Windows Command Prompt just returns without doing anything. Example C:\Users\gregg>esptool.py version C:\Users\gregg> I tried to change the Windows default by filetype. but no luck. Any ideas? Thanks From dino at no.spam.ar Tue Mar 7 07:33:01 2023 From: dino at no.spam.ar (Dino) Date: Tue, 7 Mar 2023 07:33:01 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: Message-ID: <2aGNL.2673769$nwq3.202888@fx13.ams4> On 3/6/2023 11:05 PM, rbowman wrote: > It must be nice to have a server or two... No kidding About everything else you wrote, it makes a ton of sense, in fact it's a dilemma I am facing now. My back-end returns 10 entries (I am limiting to max 10 matches server side for reasons you can imagine). As the user keeps typing, should I restrict the existing result set based on the new information or re-issue a API call to the server? Things get confusing pretty fast for the user. You don't want too many cooks in kitchen, I guess. Played a little bit with both approaches in my little application. Re-requesting from the server seems to win hands down in my case. I am sure that them google engineers reached spectacular levels of UI finesse with stuff like this. > On Mon, 6 Mar 2023 21:55:37 -0500, Dino wrote: >> >> https://schier.co/blog/wait-for-user-to-stop-typing-using-javascript > > That could be annoying. My use case is address entry. When the user types > > 102 ma > > the suggestions might be > > main > manson > maple > massachusetts > masten > > in a simple case. When they enter 's' it's narrowed down. Typically I'm > only dealing with a city or county so the data to be searched isn't huge. > The maps.google.com address search covers the world and they're also > throwing in a geographical constraint so the suggestions are applicable to > the area you're viewing. From bowman at montana.com Tue Mar 7 20:04:28 2023 From: bowman at montana.com (rbowman) Date: 8 Mar 2023 01:04:28 GMT Subject: Fast full-text searching in Python (job for Whoosh?) References: <2aGNL.2673769$nwq3.202888@fx13.ams4> Message-ID: On Tue, 7 Mar 2023 07:33:01 -0500, Dino wrote: > Played a little bit with both approaches in my little application. > Re-requesting from the server seems to win hands down in my case. That's necessary for a non-trivial data set. Assume you get 10 suggestions after the user type 'to'. today tomorrow tomato tonsil torque totem toad toque toward touch If the user type 'l' next and is trying for 'tolerance' you'll need a new set. You'll need a little refinement. If the user is a proficient typist and wants to type 'tolerance' they may get ahead of you. Another consideration is a less proficient typist or someone who can't spell. Again, play with maps.google.com. They're good at it. Put '123 thomd' in the search bar. YMMV but I get 5 variations on 123 Thomas. When they were working down 'thompd' had zero matches so they backed up to 'thom'. If you play with their search they're using some more magic too. Try '123 ellekt'. They may be using a variation on soundex or something more sophisticated. From thomas at python.org Tue Mar 7 23:37:55 2023 From: thomas at python.org (Thomas Wouters) Date: Tue, 7 Mar 2023 20:37:55 -0800 Subject: Python 3.12.0 alpha 6 released Message-ID: I'm pleased to announce the release of Python 3.12 alpha 6. https://www.python.org/downloads/release/python-3120a6/ *This is an early developer preview of Python 3.12.* Major new features of the 3.12 series, compared to 3.11 Python 3.12 is still in development. This release, 3.12.0a6 is the sixth of seven 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 (2023-05-08) and, if necessary, may be modified or deleted up until the release candidate phase (2023-07-31). 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.12 are still being planned and written. Among the new major new features and changes so far: - Even more improved error messages. More exceptions potentially caused by typos now make suggestions to the user. - Support for the Linux perf profiler to report Python function names in traces. - The deprecated wstr and wstr_length members of the C implementation of unicode objects were removed, per PEP 623 . - In the unittest module, a number of long deprecated methods and classes were removed. (They had been deprecated since Python 3.1 or 3.2). - The deprecated smtpd and distutils modules have been removed (see PEP 594 and PEP 632 . The setuptools package (installed by default in virtualenvs and many other places) continues to provide the distutils module. - A number of other old, broken and deprecated functions, classes and methods have been removed. - Invalid backslash escape sequences in strings now warn with SyntaxWarning instead of DeprecationWarning, making them more visible. (They will become syntax errors in the future.) - The internal representation of integers has changed in preparation for performance enhancements. (This should not affect most users as it is an internal detail, but it may cause problems for Cython-generated code.) - (Hey, fellow core developer, if a feature you find important is missing from this list, let Thomas know .) For more details on the changes to Python 3.12, see What's new in Python 3.12. The next pre-release of Python 3.12 will be 3.12.0a7, currently scheduled for 2023-04-03. More resources Online Documentation . PEP 693 , the Python 3.12 Release Schedule. Report bugs via GitHub Issues . Help fund Python and its community . And now for something completely different Let me not to the marriage of true minds > Admit impediments. Love is not love > Which alters when it alteration finds, > Or bends with the remover to remove: > O, no! it is an ever-fixed mark, > That looks on tempests and is never shaken; > It is the star to every wandering bark, > Whose worth?s unknown, although his height be taken. > Love?s not Time?s fool, though rosy lips and cheeks > Within his bending sickle?s compass come; > Love alters not with his brief hours and weeks, > But bears it out even to the edge of doom. > If this be error, and upon me prov?d, > I never writ, nor no man ever lov?d. *Sonnet 116*, by William Shakespeare. 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 unexpectedly chilly California, Your release team, Thomas Wouters Ned Deily Steve Dower -- Thomas Wouters From list1 at tompassin.net Wed Mar 8 00:12:04 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 8 Mar 2023 00:12:04 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: <2aGNL.2673769$nwq3.202888@fx13.ams4> References: <2aGNL.2673769$nwq3.202888@fx13.ams4> Message-ID: <4865d7e9-eb6d-9530-e202-6ce3436a74af@tompassin.net> On 3/7/2023 7:33 AM, Dino wrote: >> It must be nice to have a server or two... > > No kidding > > About everything else you wrote, it makes a ton of sense, in fact it's a > dilemma I am facing now. My back-end returns 10 entries (I am limiting > to max 10 matches server side for reasons you can imagine). > As the user keeps typing, should I restrict the existing result set > based on the new information or re-issue a API call to the server? > Things get confusing pretty fast for the user. You don't want too many > cooks in kitchen, I guess. > Played a little bit with both approaches in my little application. > Re-requesting from the server seems to win hands down in my case. > I am sure that them google engineers reached spectacular levels of UI > finesse with stuff like this. Subject of course to trying this out, I would be inclined to send a much larger list of responses to the client, and let the client reduce the number to be displayed. The latency for sending a longer list will be smaller than establishing a new connection or even reusing an old one to send a new, short list of responses. When the client types more, it can only reduce the number of possibilities - among the (possibly imaginary) larger original number of them. After the next round of user typing, the client can check and see if there are enough surviving responses to list. If not, it can then request a new list from the server. Using this in reverse, if the user deletes some characters from the end, there should be no need to go back to the server. The possible responses would already have been sent to the client. They could be interned in an associative array keyed by the string the client had typed to get those responses. From list1 at tompassin.net Wed Mar 8 00:29:11 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 8 Mar 2023 00:29:11 -0500 Subject: Winodws10 Command Prompt unresponsive to .py commands In-Reply-To: References: Message-ID: <0ceb8adf-e194-3acd-51be-95a5163f61e2@tompassin.net> On 3/7/2023 2:31 PM, Thomas Gregg wrote: > Hi, I got python 11 to work with the esptool a few days ago. However, I > must have something wrong, because now, when I enter any command with .py, > Windows Command Prompt just returns without doing anything. Example > > C:\Users\gregg>esptool.py version > > C:\Users\gregg> > > I tried to change the Windows default by filetype. but no luck. Any > ideas? Thanks Never mind file associations for now. Just run it with Python (that is, the python executable program) - python esptool.py Notes: 1. If esptool is not in the current directory then use the full path to it. 2. Use the right name (instead of just "python") to launch your desired version of Python. On a standard Windows installation it will probably be "py" (without the quotes), or "python3.11" or "py -3.11". But it might possibly be just "python". You will have to try it to see. If you ever do decide you want to run Python programs using file associations, you can read up on how to get them working. Probably the easiest way to get a file association set up is to open the File Explorer and navigate to some directory that has a .py file. Right click on that file and choose OpenWith. Then click on "Choose another app". This will open a dialog that will let you navigate to your Python executable program and assign it to run all .py files. I don't really recommend setting up and depending on a file association, though. That's because it can be a problem if and when you end up with more than one version of Python on your computer. Sometimes you want to use one version to run a Python file, sometimes another. It's hard to make that work if you run them using file associations. Also if anything goes wrong, you probably will not see the error messages. From miked at dewhirst.com.au Wed Mar 8 00:46:52 2023 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Wed, 8 Mar 2023 16:46:52 +1100 Subject: Winodws10 Command Prompt unresponsive to .py commands In-Reply-To: References: Message-ID: <52b3ef19-dfe3-80e2-6298-60c898360fb1@dewhirst.com.au> On 8/03/2023 6:31 am, Thomas Gregg wrote: > Hi, I got python 11 to work with the esptool a few days ago. However, I > must have something wrong, because now, when I enter any command with .py, > Windows Command Prompt just returns without doing anything. Example > > C:\Users\gregg>esptool.py version > > C:\Users\gregg> > > I tried to change the Windows default by filetype. but no luck. Any > ideas? Thanks Prove it works in the command prompt by using the full path to python for example, C:\Python311\python C:\Users\gregg>esptool.py version If that works, look at your path environment variables and see where python is sitting. Substitute the real location of Python 3.11 on your machine. Sadly, I think it defaults to C:\Program Files nowadays. Once you can get Python working by omitting the path, for example, C:\Users\gregg>python esptool.py version ... you can then right-click the .py file and choose whichever program you like to open with. I'm inclined to advise you to focus on getting virtual environments working next and leave all that auto-opening to later. You might find you prefer to right click and select every time. M -- Signed email is an absolute defence against phishing. This email has been signed with my private key. If you import my public key you can automatically decrypt my signature and be sure it came from me. Your email software can handle signing. -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 495 bytes Desc: OpenPGP digital signature URL: From barry at barrys-emacs.org Wed Mar 8 02:46:51 2023 From: barry at barrys-emacs.org (Barry) Date: Wed, 8 Mar 2023 07:46:51 +0000 Subject: Winodws10 Command Prompt unresponsive to .py commands In-Reply-To: <52b3ef19-dfe3-80e2-6298-60c898360fb1@dewhirst.com.au> References: <52b3ef19-dfe3-80e2-6298-60c898360fb1@dewhirst.com.au> Message-ID: > On 8 Mar 2023, at 05:55, Mike Dewhirst wrote: > > ?On 8/03/2023 6:31 am, Thomas Gregg wrote: >> Hi, I got python 11 to work with the esptool a few days ago. However, I >> must have something wrong, because now, when I enter any command with .py, >> Windows Command Prompt just returns without doing anything. Example >> >> C:\Users\gregg>esptool.py version >> >> C:\Users\gregg> >> >> I tried to change the Windows default by filetype. but no luck. Any >> ideas? Thanks > > Prove it works in the command prompt by using the full path to python for example, > > C:\Python311\python C:\Users\gregg>esptool.py version On windows use the py.exe command rather then python.exe. Does `py esptool.py version? > > If that works, look at your path environment variables and see where python is sitting. Substitute the real location of Python 3.11 on your machine. Sadly, I think it defaults to C:\Program Files nowadays. > > Once you can get Python working by omitting the path, for example, > > C:\Users\gregg>python esptool.py version > > ... you can then right-click the .py file and choose whichever program you like to open with. Use py.exe which should in the windows folder to run .py files. Barry > I'm inclined to advise you to focus on getting virtual environments working next and leave all that auto-opening to later. You might find you prefer to right click and select every time. > > M > > -- > Signed email is an absolute defence against phishing. This email has > been signed with my private key. If you import my public key you can > automatically decrypt my signature and be sure it came from me. Your > email software can handle signing. > > -- > https://mail.python.org/mailman/listinfo/python-list From jamesbtobin at gmail.com Wed Mar 8 07:56:36 2023 From: jamesbtobin at gmail.com (James Tobin) Date: Wed, 8 Mar 2023 12:56:36 +0000 Subject: JOB | Lead Linux Sysadmin (Edinburgh/London) Message-ID: Hello, I'm working with an employer that is looking to hire someone in (Edinburgh or London) that can administer on-prem and vmware platforms. Consequently, I had hoped that some members of this group may like to discuss further. I can be reached using "JamesBTobin (at) Gmail (dot) Com". Kind regards, James From dino at no.spam.ar Wed Mar 8 09:40:51 2023 From: dino at no.spam.ar (Dino) Date: Wed, 8 Mar 2023 09:40:51 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: <005701d95127$4dc809b0$e9581d10$@gmail.com> Message-ID: On 3/7/2023 2:02 PM, avi.e.gross at gmail.com wrote: > Some of the discussions here leave me confused as the info we think we got > early does not last long intact and often morphs into something else and we > find much of the discussion is misdirected or wasted. > Apologies. I'm the OP and also the OS (original sinner). My "mistake" was to go for a "stream of consciousness" kind of question, rather than a well researched and thought out one. You are correct, Avi. I have a simple web UI, I came across the Whoosh video and got infatuated with the idea that Whoosh could be used for create a autofill function, as my backend is already Python/Flask. As many have observed and as I have also quickly realized, Whoosh was overkill for my use case. In the meantime people started asking questions, I responded and, before you know it, we are all discussing the intricacies of JavaScript web development in a Python forum. Should I have stopped them? How? One thing is for sure: I am really grateful that so many used so much of their time to help. A big thank you to each of you, friends. Dino From dino at no.spam.ar Wed Mar 8 09:56:32 2023 From: dino at no.spam.ar (Dino) Date: Wed, 8 Mar 2023 09:56:32 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: References: Message-ID: On 3/7/2023 1:28 PM, David Lowry-Duda wrote: > But I'll note that I use whoosh from time to time and I find it stable > and pleasant to work with. It's true that development stopped, but it > stopped in a very stable place. I don't recommend using whoosh here, but > I would recommend experimenting with it more generally. Thank you, David. Noted. From avi.e.gross at gmail.com Wed Mar 8 14:29:31 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 8 Mar 2023 14:29:31 -0500 Subject: Feature migration Message-ID: <006301d951f4$4e9380e0$ebba82a0$@gmail.com> This may be of interest to a few and is only partially about Python. In a recent discussion, I mentioned some new Python features (match) seemed related to a very common feature that has been in a language like SCALA for a long time. I suggested it might catch on and be used as widely as in SCALA and become the pythonic way to do many things, whatever that means, even as it's origins lie elsewhere. This motivated me to go take a new look at SCALA and I was a bit surprised. I will only mention two aspects as they relate to python. One is that they made a version 3 that has significant incompatibilities with version 2. Sounds familiar? The other fascinated me. They seem to be partially copying from python a feature that now appears everywhere but yet strive for some backwards compatibility. They simplified the heck out of all kinds of expressions by using INDENTATION. Lots of curly braces are now gone or optional. You need to indent carefully, and in places it is not quite the same as python. It is way more readable. Python always had indentation as a key feature. Since SCALA did not, it allows you to set options to turn off the new feature, sort of. As I have been saying, all kinds of ideas in computer science can migrate to new and existing languages, often not quite the same way. I am not endorsing SCALA, just noting that I suspect Python had some influence. From hjp-python at hjp.at Wed Mar 8 15:27:55 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 8 Mar 2023 21:27:55 +0100 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: <4865d7e9-eb6d-9530-e202-6ce3436a74af@tompassin.net> References: <2aGNL.2673769$nwq3.202888@fx13.ams4> <4865d7e9-eb6d-9530-e202-6ce3436a74af@tompassin.net> Message-ID: <20230308202755.uwsbazuqw56yzum4@hjp.at> On 2023-03-08 00:12:04 -0500, Thomas Passin wrote: > On 3/7/2023 7:33 AM, Dino wrote: > > in fact it's a dilemma I am facing now. My back-end returns 10 > > entries (I am limiting to max 10 matches server side for reasons you > > can imagine). As the user keeps typing, should I restrict the > > existing result set based on the new information or re-issue a API > > call to the server? Things get confusing pretty fast for the user. > > You don't want too many cooks in kitchen, I guess. > > Played a little bit with both approaches in my little application. > > Re-requesting from the server seems to win hands down in my case. > > I am sure that them google engineers reached spectacular levels of UI > > finesse with stuff like this. > > Subject of course to trying this out, I would be inclined to send a much > larger list of responses to the client, and let the client reduce the number > to be displayed. The latency for sending a longer list will be smaller than > establishing a new connection or even reusing an old one to send a new, > short list of responses. That depends very much on how long that list can become. If it's 200 matches - sure, send them all, even if the client will display only 10 of them. Probably even for 2000. But if you might get 20 million matches you surely don't want to send them all to the client. 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 skip.montanaro at gmail.com Wed Mar 8 15:28:47 2023 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 8 Mar 2023 14:28:47 -0600 Subject: JOB | Lead Linux Sysadmin (Edinburgh/London) In-Reply-To: References: Message-ID: > Hello, I'm working with an employer that is looking to hire someone in > (Edinburgh or London) that can administer on-prem and vmware > platforms. > James, If you haven't already, please post to the Phone Jobs Board: https://www.python.org/jobs/ Skip > From list1 at tompassin.net Wed Mar 8 16:00:32 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 8 Mar 2023 16:00:32 -0500 Subject: Fast full-text searching in Python (job for Whoosh?) In-Reply-To: <20230308202755.uwsbazuqw56yzum4@hjp.at> References: <2aGNL.2673769$nwq3.202888@fx13.ams4> <4865d7e9-eb6d-9530-e202-6ce3436a74af@tompassin.net> <20230308202755.uwsbazuqw56yzum4@hjp.at> Message-ID: <1eb86510-fdbd-a69a-cd2f-1301b85c2f0c@tompassin.net> On 3/8/2023 3:27 PM, Peter J. Holzer wrote: > On 2023-03-08 00:12:04 -0500, Thomas Passin wrote: >> On 3/7/2023 7:33 AM, Dino wrote: >>> in fact it's a dilemma I am facing now. My back-end returns 10 >>> entries (I am limiting to max 10 matches server side for reasons you >>> can imagine). As the user keeps typing, should I restrict the >>> existing result set based on the new information or re-issue a API >>> call to the server? Things get confusing pretty fast for the user. >>> You don't want too many cooks in kitchen, I guess. >>> Played a little bit with both approaches in my little application. >>> Re-requesting from the server seems to win hands down in my case. >>> I am sure that them google engineers reached spectacular levels of UI >>> finesse with stuff like this. >> >> Subject of course to trying this out, I would be inclined to send a much >> larger list of responses to the client, and let the client reduce the number >> to be displayed. The latency for sending a longer list will be smaller than >> establishing a new connection or even reusing an old one to send a new, >> short list of responses. > > That depends very much on how long that list can become. If it's 200 > matches - sure, send them all, even if the client will display only 10 > of them. Probably even for 2000. But if you might get 20 million matches > you surely don't want to send them all to the client. Yes, of course. OTOH, if you have 2000+ possibilities it's basically pointless to send them to the client. You can send the first 10, and hope that will be worth something (it probably won't). You can send all 2000 and let the client show the first say 10, but that probably won't be worth much either. If you have some way to prioritize them, you can include the scores and send the top say 100 what you send to the client, and let the client figure out what to do. If you are going to have that many responses you will need some more complex and sophisticated approach anyway, so the whole discussion would not be applicable. And this would be getting miles (kms) away from the OP's situation. From aapost at idontexist.club Wed Mar 8 16:56:42 2023 From: aapost at idontexist.club (aapost) Date: Wed, 8 Mar 2023 16:56:42 -0500 Subject: Lambda returning tuple question, multi-expression Message-ID: When making a UI there are a lot of binding/trace operations that need to occur that lead to a lot of annoying 1 use function definitions. I don't really see lambda use like below. Giving 2 working lambda examples using a returned tuple to accomplish multiple expressions - what sort of gotchas, if any, might make the following bad practice if I am missing something? Example 1: import tkinter as tk main = tk.Tk() e1 = tk.Entry(master=main) e1["state"] = "disabled" e1.pack() e2 = tk.Entry(master=main) e2["state"] = "disabled" e2.pack() e3 = tk.Entry(master=main) e3["state"] = "disabled" e3.pack() b = tk.Button(master=main, text="Enable") b.config( command=lambda: ( e1.config(state="normal"), e2.config(state="normal"), e3.config(state="normal") ) ) b.pack() Example 2: import tkinter as tk main = tk.Tk() l = tk.Label(master=main) l.a = {"seconds":0} l._updater = lambda: ( l.a.update({"seconds": 1 + l.a["seconds"]}), l.config(text=l.a["seconds"]), l.after(ms=1000, func=l._updater) ) l._updater() l.pack() From greg.ewing at canterbury.ac.nz Wed Mar 8 17:47:03 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 9 Mar 2023 11:47:03 +1300 Subject: Feature migration In-Reply-To: References: <006301d951f4$4e9380e0$ebba82a0$@gmail.com> Message-ID: On 9/03/23 8:29 am, avi.e.gross at gmail.com wrote: > They seem to be partially copying from python a > feature that now appears everywhere but yet strive for some backwards > compatibility. They simplified the heck out of all kinds of expressions by > using INDENTATION. It's possible this was at least parttly inspired by functional languages such as Haskell. Haskell has always allowed indentation as one way of expressing structure. Python wasn't the first language to use indentation semantically. -- Greg From greggtag at gmail.com Wed Mar 8 18:34:37 2023 From: greggtag at gmail.com (Thomas Gregg) Date: Wed, 8 Mar 2023 18:34:37 -0500 Subject: JOB | Lead Linux Sysadmin (Edinburgh/London) In-Reply-To: References: Message-ID: Is there any way to be removed from this list? Thank you, Tom On Wed, Mar 8, 2023 at 3:51?PM Skip Montanaro wrote: > > Hello, I'm working with an employer that is looking to hire someone in > > (Edinburgh or London) that can administer on-prem and vmware > > platforms. > > > > James, > > If you haven't already, please post to the Phone Jobs Board: > > https://www.python.org/jobs/ > > Skip > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From list1 at tompassin.net Wed Mar 8 18:37:07 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 8 Mar 2023 18:37:07 -0500 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: Message-ID: <7af95294-998d-e291-80dd-890fdbe0b913@tompassin.net> On 3/8/2023 4:56 PM, aapost wrote: > b = tk.Button(master=main, text="Enable") > b.config( > ??? command=lambda: ( > ??????? e1.config(state="normal"), > ??????? e2.config(state="normal"), > ??????? e3.config(state="normal") > ??? ) > ) It's hard to understand what you are trying to do here. I don't remember just now what .config() will return, but the lambda will return a tuple of *something*, probably (None, None, None). Even if the tuple does contain three non-None values, config() requires named parameters, not a tuple. In the course of executing the lambda, your three controls e1, e2, and e2 will get configured, but you could just write a function to do that: def set_entries_enabled_state(enabled = True): state = 'normal' if enabled else 'disabled' for e in (e1, e2, e3): e.config(state=state) def config_b_and_entries(enabled = True): state = 'normal' if enabled else 'disabled' b.config(state = state) set_entries_enabled_state(enabled) This is easy to read and understand. (I may not have remembered some Tk details correctly). From cs at cskk.id.au Wed Mar 8 17:44:56 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 9 Mar 2023 09:44:56 +1100 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: Message-ID: On 08Mar2023 16:56, aapost wrote: >When making a UI there are a lot of binding/trace operations that need >to occur that lead to a lot of annoying 1 use function definitions. I >don't really see lambda use like below. > >Giving 2 working lambda examples using a returned tuple to accomplish >multiple expressions - what sort of gotchas, if any, might make the >following bad practice if I am missing something? There're no real gotchas: tuples are evaluated left to right, so you should have things happen in the order you've expressed them (if the order matters). What you lose with a lambda is control constructs like loops and if-statements (well, there's the `x if foo else y` but that gets cumbersome quickly). Once things get complicated you may want to define a more complication function using `def`: def callback1(): ... do complicated stuff ... b.config(command=callback1) The only other issue, which applies across the board with GUIs and is nothing specific to lambdas is that the GUI only renders and operates while the main loop is running. When your callbacks do trivial stuff you're fine. If they block (eg waiting for user input or network calls etc) the GUI is also blocked. You need threads or other concurrent approaches if the GUI is to stay responsive. The flip side of that is that a concurrent context like a Thread should not interact with the GUI directly. In things like Qt I've actually had that mistake crash the app because the Qt framework is (was?) not thread safe. You need to arrange that GUI actions occur in the main programme thread. I think the same applies with tk, and is anyway probably good practice for any GUI. It's not as hard as it sounds - typically when something happens asynchronously you arrange to issue an "event", and the GUI mainloop will process that as it happens - the event callback will be fired (called) by the main loop itself and thus the callback gets to do its thing in the main loop. Cheers, Cameron Simpson From skip.montanaro at gmail.com Wed Mar 8 19:04:06 2023 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 8 Mar 2023 18:04:06 -0600 Subject: JOB | Lead Linux Sysadmin (Edinburgh/London) In-Reply-To: References: Message-ID: There's a link at the bottom of each message to the list info pager. Follow the directions on that page to unsubscribe. Skip On Wed, Mar 8, 2023, 5:38 PM Thomas Gregg wrote: > Is there any way to be removed from this list? > Thank you, Tom > > On Wed, Mar 8, 2023 at 3:51?PM Skip Montanaro > wrote: > > > > Hello, I'm working with an employer that is looking to hire someone in > > > (Edinburgh or London) that can administer on-prem and vmware > > > platforms. > > > > > > > James, > > > > If you haven't already, please post to the Phone Jobs Board: > > > > https://www.python.org/jobs/ > > > > Skip > > > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > From avi.e.gross at gmail.com Wed Mar 8 19:58:36 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 8 Mar 2023 19:58:36 -0500 Subject: Feature migration In-Reply-To: References: <006301d951f4$4e9380e0$ebba82a0$@gmail.com> Message-ID: <002a01d95222$47ed4cc0$d7c7e640$@gmail.com> Greg, Yes, it is very possible from other sources. I doubt it hurts if a popular language, albeit not compiled the same way, uses a feature. I see it a bit as more an impact on things like compiler/interpreter design in that once you see it can reasonably be implemented, some features look doable. I will say the exact methods and rules are different enough and interact with things differently. As an example, you can use an "end" statement at the end of a block to signal what is ending. As regularly repeated. There is no one right way but there are ways supported by the language you are in and others ways that are NOT supported. -----Original Message----- From: Python-list On Behalf Of Greg Ewing via Python-list Sent: Wednesday, March 8, 2023 5:47 PM To: python-list at python.org Subject: Re: Feature migration On 9/03/23 8:29 am, avi.e.gross at gmail.com wrote: > They seem to be partially copying from python a > feature that now appears everywhere but yet strive for some backwards > compatibility. They simplified the heck out of all kinds of expressions by > using INDENTATION. It's possible this was at least parttly inspired by functional languages such as Haskell. Haskell has always allowed indentation as one way of expressing structure. Python wasn't the first language to use indentation semantically. -- Greg -- https://mail.python.org/mailman/listinfo/python-list From aapost at idontexist.club Wed Mar 8 23:19:51 2023 From: aapost at idontexist.club (aapost) Date: Wed, 8 Mar 2023 23:19:51 -0500 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: Message-ID: On 3/8/23 16:56, aapost wrote: > Thomas > Cameron > def set_entries_enabled_state(enabled = True): > state = 'normal' if enabled else 'disabled' > for e in (e1, e2, e3): > e.config(state=state) > > def config_b_and_entries(enabled = True): > state = 'normal' if enabled else 'disabled' > b.config(state = state) > set_entries_enabled_state(enabled) I admit adding commenting might be useful to clearly express intent for patterns I don't commonly see. But when you are managing a bunch of widgets and experimenting with the design, the variable name word salad approach 'in the name of readability' starts to melt your brain a bit and it all starts too look like a wall of..: the_thing.the_things_thing.do_this_thing_to_that_other_thing_but_only_if_this_one_time() So the button b in the example only needs a reference to a callable configured, set with the command= parameter in .config() The code: def func(): pass b.config(command=func) Is equivalent. So that if the button is clicked, code at func (or the lambda) gets called. In both cases (as per my intent), care about the return values of the expressions does not matter and I am fairly certain regardless of what the callable returns, it does not get evaluated/assigned/considered anywhere. (at least that is how I have been considering it, a void foo(void) if you will..). Now as far as the tuple, yes, left to right evaluation is what I expect, (hope anyway, lol), meaning (3, False, 1, x := 5+9, print("hello{}".format(x))) would return a tuple of (3, False, 1, 14, None) which gets assigned to nothing and the string "hello14" printed to console. Now.. When you want to assign a callable that requires args, the main examples people give are a combo of them both, def func(x,y,z): pass x = y = x = "something" b.config(command=lambda x,y,z: func(x,y,z)) So as far as the examples given above (which I can't really parse), if you meant for passing in a bool value, to do so would require something like: b.config(command=lambda enabled: config_b_and_entries(enabled)) Which that type of thing to me gets even harder to grok after a while, and I guess for me I find having to go to a different scope or a separate file to parse a bunch of definitions like these: def set_entries_enabled_state(enabled = True): def config_b_and_entries(enabled = True): ends up taking me out of an object oriented focus / headspace of the layout at hand. And it is sort of like.. Ok I can either b.config(command=lambda: ( a.expr, b.expr.update({something: "morecomplicated"}), c.expr ) ) OR.. b.config(command=lambda a=a, b=b, c=c, s=something: foo(a, b, c, s)) somewhere else: def foo(a, b, c, something): a.expr b.expr.update({something: "morecomplicated"}) c.expr When you are trying to add a bit of dynamic feel to the tediousness of the widget management, keeping things kind of contained to their object just feels more natural to me (at the moment anyway).. (all the packing, unpacking, making collections of widgets within frames appear or go away based on states, colour changes based on input, dynamic widget generation and where their relative attachment should go, etc) I read a lot of sentiment against complicated lambdas suggesting one should go for more functions, but I guess I feel pushing a more complicated lambda to contain behavior more closely to an instance feels more intuitive at the moment (and the sentiment against it doesn't really resonate with me), so long as it isn't introducing some inherent behavioral flaw or bug I am blind to.. Of course I might change my mind at some point during a refactor and think "what the hell is that, why didn't I just..".. Which will probably come in a few weeks. lol One additional note on the Thread comment, I haven't really needed to dig in to that too deeply, but Threading is amazing for tkinter UI troubleshooting, if you add something like: t = threading.Thread(target=maintk.mainloop) and run it with python -i so long has you have attached every widget to some relative position on to the root (maintk in this case), you can interact with any object/widget directly live to see what is going on or what a change does. From list1 at tompassin.net Thu Mar 9 00:13:00 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 9 Mar 2023 00:13:00 -0500 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: Message-ID: <4e82452b-23fc-8d30-6f21-268aabd7d623@tompassin.net> On 3/8/2023 11:19 PM, aapost wrote: > In both cases (as per my intent) Well, that's the trouble. You haven't stated your intent, so we're forced to try to reverse engineer it. Below I state what my reverse-engineering effort thinks is your intent. It would be better if you actually said clearly what you want to achieve. > So as far as the examples given above (which I can't really parse), if > you meant for passing in a bool value, to do so would require something > like: > > b.config(command=lambda enabled: config_b_and_entries(enabled)) As best as I can understand what you are trying to do here, it seems like you want to enable/disable those Entry widgets when you configure the b widget to be enabled/disabled. That way their states would all track each other, with only a single command needing to be issued. That seems like a sensible goal. The function config_b_and_entries() that I suggested is not meant to be the target of a lambda expression that is the argument of b.config(). It is meant to be called *instead* of b.config(command = lambda.....). I can't see any benefit of trying to force this coordination of states by using an obscure lambda expression when you can achieve the same result with a straightforward, easy to read function or method call. OTOH, if you are not trying to achieve this coordination of states, then what are you trying to do? Don't go making us guess any more. From learn2program at gmail.com Thu Mar 9 04:06:13 2023 From: learn2program at gmail.com (Alan Gauld) Date: Thu, 9 Mar 2023 09:06:13 +0000 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: Message-ID: On 08/03/2023 21:56, aapost wrote: > When making a UI there are a lot of binding/trace operations that need > to occur that lead to a lot of annoying 1 use function definitions. I > don't really see lambda use like below. Lambdas are very common in GUI callbacks but I admit I've never seen tuples used to create multiple expressions. That's a neat trick I hadn't thought of and will probably use. > Giving 2 working lambda examples using a returned tuple to accomplish > multiple expressions - what sort of gotchas, if any, might make the > following bad practice if I am missing something? Not bad practice per-se but you are still limited to expressions, no loops for example (although you could fake it with a list comp, but that gets ugly fast!) Also layout is all important here. It could get very messy to read if indentation isn't clear. You only have to look at some Javascript code with function definitions as arguments to functions to see how clunky that can be. Similarly debugging so much code passed as arguments might be an issue - no easy way to step into the lambda. But as an alternative to writing many typical event handlers it's definitely a valid approach that I'll be trying. > b = tk.Button(master=main, text="Enable") > b.config( > command=lambda: ( > e1.config(state="normal"), > e2.config(state="normal"), > e3.config(state="normal") > ) > ) You could of course single line that with: b = tk.Button(master=main, text="Enable", command=lambda: ( e1.config(state="normal"), e2.config(state="normal"), e3.config(state="normal") ) ) It's not a radical change from using a lamba as a callback but it does extend the use case to cover a common GUI scenario. I like it. I wish I'd thought of it years ago. Thanks for sharing. -- 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 gweatherby at uchc.edu Thu Mar 9 05:11:24 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Thu, 9 Mar 2023 10:11:24 +0000 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: Message-ID: Other than the admittedly subjective viewpoint that using the lambda is confusing, there?s probably nothing wrong with the lambda approach. A couple of alternatives: def e(): for e in (e1,e2,e3): e.config(state="normal") b = tk.Button(master=main, text="Enable",command=e) or b = tk.Button(master=main, text="Enable",command=lambda: [e.config(state="normal") for e in (e1, e2, e3)]) From: Python-list on behalf of aapost Date: Wednesday, March 8, 2023 at 5:15 PM To: python-list at python.org Subject: Lambda returning tuple question, multi-expression *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** When making a UI there are a lot of binding/trace operations that need to occur that lead to a lot of annoying 1 use function definitions. I don't really see lambda use like below. Giving 2 working lambda examples using a returned tuple to accomplish multiple expressions - what sort of gotchas, if any, might make the following bad practice if I am missing something? Example 1: import tkinter as tk main = tk.Tk() e1 = tk.Entry(master=main) e1["state"] = "disabled" e1.pack() e2 = tk.Entry(master=main) e2["state"] = "disabled" e2.pack() e3 = tk.Entry(master=main) e3["state"] = "disabled" e3.pack() b = tk.Button(master=main, text="Enable") b.config( command=lambda: ( e1.config(state="normal"), e2.config(state="normal"), e3.config(state="normal") ) ) b.pack() Example 2: import tkinter as tk main = tk.Tk() l = tk.Label(master=main) l.a = {"seconds":0} l._updater = lambda: ( l.a.update({"seconds": 1 + l.a["seconds"]}), l.config(text=l.a["seconds"]), l.after(ms=1000, func=l._updater) ) l._updater() l.pack() -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!i8mp9fRKlBLziXCn6-OIC8fNx0LBohis8m6VARp17Igg5036wrTflGiwwptY18Rgkriw5MquUKxe9Fglqpu8FHEy$ From rosuav at gmail.com Thu Mar 9 06:27:11 2023 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Mar 2023 22:27:11 +1100 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: Message-ID: On Thu, 9 Mar 2023 at 09:14, aapost wrote: > > When making a UI there are a lot of binding/trace operations that need > to occur that lead to a lot of annoying 1 use function definitions. I > don't really see lambda use like below. > > Giving 2 working lambda examples using a returned tuple to accomplish > multiple expressions - what sort of gotchas, if any, might make the > following bad practice if I am missing something? IMO there's nothing wrong with this, but it's worth considering a few alternatives. For instance, the single-use function might be less annoying if you don't have to also name the function in the constructor; this could be achieved with proper use of a decorator, or possibly use of a class namespace, with an appropriate helper. But otherwise, this tuple trick seems pretty much fine to me, although you're still restricted to a series of expressions (no statements), so your code is still going to get a bit awkward if it does anything complicated. ChrisA From robin at reportlab.com Thu Mar 9 09:22:09 2023 From: robin at reportlab.com (Robin Becker) Date: Thu, 9 Mar 2023 14:22:09 +0000 Subject: Python 3.12.0 alpha 6 released In-Reply-To: References: Message-ID: <79aa3db0-2a17-1386-f650-43071f18d281@everest.reportlab.co.uk> On 08/03/2023 04:37, Thomas Wouters wrote: > I'm pleased to announce the release of Python 3.12 alpha 6. > > https://www.python.org/downloads/release/python-3120a6/ > > > *This is an early developer preview of Python 3.12.* > Major new features of the 3.12 series, compared to 3.11 > I was able to test reportlab with the 3.12.0a5 release (I build following the Archlinux pkgbuild), but am unable to do so with 3.12.0a6 because of problems with cython/lxml/freetype-py (I think). With an optimized build of a6 I was getting segfaults which I think were caused by incompatible C extensions from the pip cache so decided to rebuild the requirements. With latest cython git (allegedly 3.0.0b1) I see errors related to tstate eg > Cython/Compiler/Parsing.c:86861:34: error: ?PyThreadState? {aka ?struct _ts?} has no member named ?curexc_traceback? > 86861 | PyObject* tmp_tb = tstate->curexc_traceback; I guess that this is caused by changes in what we are allowed to see of Python internal structure. If anyone knows of a way to advance further I can try to experiment. > Python 3.12 is still in development. This release, 3.12.0a6 is the sixth of > seven 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 (2023-05-08) and, if necessary, may be modified or deleted up > until the release candidate phase (2023-07-31). 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.12 are still being planned and written. > Among the new major new features and changes so far: > >............ > Your release team, > Thomas Wouters > Ned Deily > Steve Dower > -- Robin Becker From aapost at idontexist.club Thu Mar 9 03:29:35 2023 From: aapost at idontexist.club (aapost) Date: Thu, 9 Mar 2023 03:29:35 -0500 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: <4e82452b-23fc-8d30-6f21-268aabd7d623@tompassin.net> Message-ID: On 3/9/23 00:13, Thomas Passin wrote: > lol.. 'us'.. So.. to give an example from your own code: but_play = Tk.Button(_frame, text='Play', width = BUTTONWIDTH + 1, pady = PADY, command=lambda x=plotmgr:play_macro(x), bg = BUTTON_BG, font = NEWFONT) Can be written as: b = Tk.Button(master=_frame) b.config(text='Play', width = BUTTONWIDTH + 1, pady = PADY, command=lambda x=plotmgr:play_macro(x), bg = BUTTON_BG, font = NEWFONT) .config() is just a way of adding/modifying most of the same initialization arguments after the instantiation of the object. tkinter objects are flexible by design, You can also do b["text"] = "adsfa" b["command"] = lambda: (a,b,c,d) I could also rewrite the original example with the exact same result: b = tk.Button( master=main, text="Enable", command=lambda: ( e1.config(state="normal"), e2.config(state="normal"), e3.config(state="normal") ) ) b.pack() b is not changing states at any point. Nothing "happens" to state when .config() is called. b does nothing without a command= configured. .config() is binding the button press event via command= to a call so than an action can occur on button press. There is no 'instead' of b.config() (unless of course using one of the equivalent examples above to do the exact same thing) The disconnect is not in the not understanding of my code, it's in the not understanding of .config(). (which is no big deal, I forgot what a file buffer was just this week, lol) So, as far as the examples, they are simplified abstract psuedo-like-code illustrations to accompany the ask of and open ended question regarding a programming practice. (I did forgot to include main.mainloop() at the end of each one, as I was using python -i when I quickly wrote them) example 1 described: A button press does sequence of actions against widgets, i.e. I have 3 disabled widgets, I press a button, now in sequence all 3 are enabled so I can type in them. Without a lambda tuple sequence this requires a def and an another lambda. example 2 described: dict with an attribute assigned to a label (you can't assign directly to external variables within a lambda, but you can call something with a method like .update(), which why would that be considered any different than any other state changing call?) Then lambda assigned to a label and called to start it up, recursively performs an update to said widget every 1 second. There are several ways to do this without a lambda tuple sequence, none as concise. The 'what I am trying to do' is ask a question regarding opinions and practices on issuing a sequence of actions within a lambda via a tuple (since the common practice approaches against it - mainly with tkinter - feel more convoluted), and in doing so leaving it open ended to get a feel on what opinions are, and to see if any opinions influence mine. From grant.b.edwards at gmail.com Thu Mar 9 14:27:20 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 09 Mar 2023 11:27:20 -0800 (PST) Subject: Baffled by readline module Message-ID: <640a3318.020a0220.67dbd.001a@mx.google.com> In an interactive command-line Python program on Linux, I want to be able to read a line at a time from stdin, providing command line history and editing to the user. In C, I would use GNU readline to do that. Python has the readline module, which appears to be a wrapper for GNU readline. However, I've read and re-read the documenation for that module, but I'm completely baffled. There's all sorts of stuff about history files, but I neither need nor want a history file. Likewise tab-completion: don't want it. All the examples not only involve history files and tab-completion but they're somehow connected to the interactive Python REPL, which is also completely off-base for my use case. Is the readline module not the right tool for an interactive Linux command-line application that needs to provide command line recall and editing to the user who's entering stuff on stdin from a tty? From grant.b.edwards at gmail.com Thu Mar 9 14:50:52 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 09 Mar 2023 11:50:52 -0800 (PST) Subject: Baffled by readline module References: <640a3318.020a0220.67dbd.001a@mx.google.com> Message-ID: <640a389c.020a0220.a3c00.0071@mx.google.com> On 2023-03-09, Grant Edwards wrote: > In an interactive command-line Python program on Linux, I want to be > able to read a line at a time from stdin, providing command line > history and editing to the user. In C, I would use GNU readline to do > that. > > Python has the readline module, which appears to be a wrapper for GNU > readline. However, I've read and re-read the documenation for that > module, but I'm completely baffled. After googling for a while, I finally stumbled across an old Python 2 example that pointed me in the right direction. Here's the sort of example I had hoped to find in the module's docs: #!/usr/bin/python import readline readline.parse_and_bind('set editing-mode emacs') while True: try: line = input('enter something (EOF to quit): ') except EOFError: print() break print('You entered: "%s"' % line) From rosuav at gmail.com Thu Mar 9 14:59:58 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Mar 2023 06:59:58 +1100 Subject: Baffled by readline module In-Reply-To: <640a3318.020a0220.67dbd.001a@mx.google.com> References: <640a3318.020a0220.67dbd.001a@mx.google.com> Message-ID: On Fri, 10 Mar 2023 at 06:28, Grant Edwards wrote: > > In an interactive command-line Python program on Linux, I want to be > able to read a line at a time from stdin, providing command line > history and editing to the user. In C, I would use GNU readline to do > that. > > Python has the readline module, which appears to be a wrapper for GNU > readline. However, I've read and re-read the documenation for that > module, but I'm completely baffled. There's all sorts of stuff about > history files, but I neither need nor want a history file. Likewise > tab-completion: don't want it. All the examples not only involve > history files and tab-completion but they're somehow connected to the > interactive Python REPL, which is also completely off-base for my use > case. > > Is the readline module not the right tool for an interactive Linux > command-line application that needs to provide command line recall and > editing to the user who's entering stuff on stdin from a tty? > Not sure about the history file, and I would assume that if you don't configure one, history is simply lost when you restart. But with tab completion, unless you need to be able to input a tab character, it should be safe to ignore the feature and leave it at the defaults. ChrisA From list1 at tompassin.net Thu Mar 9 15:25:08 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 9 Mar 2023 15:25:08 -0500 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: <4e82452b-23fc-8d30-6f21-268aabd7d623@tompassin.net> Message-ID: On 3/9/2023 3:29 AM, aapost wrote: > The 'what I am trying to do' is ask a question regarding opinions and > practices on issuing a sequence of actions within a lambda via a tuple > (since the common practice approaches against it - mainly with tkinter - > feel more convoluted), and in doing so leaving it open ended to get a > feel on what opinions are, and to see if any opinions influence mine. I finally realized why I am uncomfortable with doing this kind of thing. It's because, IMHO, lambda expressions should not have side effects and should not require much mental effort to grasp what they do. Yes, you can do so. You can even print from a lambda (and it might be useful for debugging): lambda x: print(f'The lambda received {x}') or x*x The Python Reference on readthedocs.io also has a tk example that specifically wants the side effect (see https://python-reference.readthedocs.io/en/latest/docs/operators/lambda.html): >>> # this is a code snippet from a Tkinter gui app >>> # in this case lambda is quite convenient >>> self.btn_cancel = Button(self.progress_container, text='Cancel', >>> command=lambda: subprocess.call('taskkill /f /im uberzip.exe', >>> shell=True)) Maybe so, but I think it's better not to have side effects hidden away in expressions that are hard to read and understand. And being anonymous, there is no function name to remind you what the action is suppose to do. Much better (still IMHO, of course): def kill_uberzip(): """Kill an external running program named uberzip.exe.""" subprocess.call('taskkill /f /im uberzip.exe', shell=True)) self.btn_cancel = Button(self.progress_container, text='Cancel', command = kill_uberzip()) This way, it's easy to understand what btn_cancel() will do each time you scan that line of code. Using the lambda makes you reparse the line and spend mental effort each time you scan it. And this way, you know directly that the button is going to cause a side effect outside your program, which you have to infer (an indirect mental operation) when you scan the lambda. For this particular example, it might turn out that there could be more than one instance of uberzip.exe running at the same time. Which one should be killed, and how do you kill the right one? With the function, you can get those details under control, but I hate to think what might happen to the lambda expression. Yes, of course, there can be times when the lambda expression is somewhat easy to understand and the side effects are harmless. In that case, it may be easy enough to grasp quickly that the anonymous function would not benefit from having a name. So OK, it's not a hard-and-fast rule. From grant.b.edwards at gmail.com Thu Mar 9 16:08:46 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 09 Mar 2023 13:08:46 -0800 (PST) Subject: Baffled by readline module References: <640a3318.020a0220.67dbd.001a@mx.google.com> Message-ID: <640a4ade.020a0220.1d3cb.0243@mx.google.com> On 2023-03-09, Chris Angelico wrote: > Not sure about the history file, and I would assume that if you don't > configure one, history is simply lost when you restart. But with tab > completion, unless you need to be able to input a tab character, it > should be safe to ignore the feature and leave it at the defaults. Indeed, that seems to be how it works (though I never found that stated anywhere in the docs). What's really weird about the docs is that when it is described it doesn't even _mention_ that it provides command-line recall and editing: The readline module defines a number of functions to facilitate completion and reading/writing of history files from the Python interpreter. This module can be used directly, or via the rlcompleter module, which supports completion of Python identifiers at the interactive prompt. Settings made using this module affect the behaviour of both the interpreter?s interactive prompt and the prompts offered by the built-in input() function. It just talks about manipulating history files and about tab-completion of Python identfiers. The last sentence mentions that settings affect both the REPL prompt and the prompts offered by the built-in input() function. However, I also don't really care about the "prompts offered" either. What I care about is the interactive handling of user keystrokes vis-a-vis command line recall and editing. Or is that what's meant by the phrase "behavior of the prompt"? To me "the prompt" is the string that's printed _before_ the program starts reading user keystrokes and doing the stuff I care about. It finally dawned on me after seeing an example I found elsewhere that you don't call some module method to fetch the next user-entered line. You call the input() built-in. Having a module modify the behavior of a built-in makes me cringe. I suppose this way you can easily slap-on "readline" command-line recall/editing to an existing application as long as it uses the input() built-in instead of reading from stdin. -- Grant From cs at cskk.id.au Thu Mar 9 16:31:42 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 10 Mar 2023 08:31:42 +1100 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: Message-ID: On 09Mar2023 09:06, Alan Gauld wrote: >On 08/03/2023 21:56, aapost wrote: >> When making a UI there are a lot of binding/trace operations that need >> to occur that lead to a lot of annoying 1 use function definitions. I >> don't really see lambda use like below. > >Lambdas are very common in GUI callbacks but I admit I've never seen >tuples used to create multiple expressions. That's a neat trick I >hadn't thought of and will probably use. I often uses as a debugging hack. Given: foo=lambda: expr I'll often write: foo=lambda: (X("foo happening here!"), ...maybe more..., expr)[-1] to embed some debug tracing in a lambda defined expression. Cheers, Cameron Simpson From cs at cskk.id.au Thu Mar 9 16:37:49 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 10 Mar 2023 08:37:49 +1100 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: Message-ID: On 09Mar2023 09:06, Alan Gauld wrote: >Also layout is all important here. It could get very messy to read if >indentation isn't clear. You only have to look at some Javascript code >with function definitions as arguments to functions to see how clunky >that can be. Just a note that some code formatters use a trailing comma on the last element to make the commas fold points. Both yapf (my preference) and black let you write a line like (and, indeed, flatten if short enough): ( a, b, c ) but if you write: ( a, b, c, ) they'll fold the lines like: ( a, b, c, ) in varying flavours of indentation depending on tuning. The point being that if, like me, you often have a code formatter active-on-save it can be hinted to nicely present complex tuples (or parameter lists and imports). It isn't magic, but can be quite effective. Cheers, Cameron Simpson From rosuav at gmail.com Thu Mar 9 16:58:26 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Mar 2023 08:58:26 +1100 Subject: Baffled by readline module In-Reply-To: <640a4ade.020a0220.1d3cb.0243@mx.google.com> References: <640a3318.020a0220.67dbd.001a@mx.google.com> <640a4ade.020a0220.1d3cb.0243@mx.google.com> Message-ID: On Fri, 10 Mar 2023 at 08:10, Grant Edwards wrote: > What's really weird about the docs is that when it is described it > doesn't even _mention_ that it provides command-line recall and > editing: > > It just talks about manipulating history files and about > tab-completion of Python identfiers. The last sentence mentions that > settings affect both the REPL prompt and the prompts offered by the > built-in input() function. > Ah. Yes, that's because the **module** doesn't provide command-line recall and editing. It does affect the input() builtin, as is mentioned, but mainly, the module is to configure readline, not to ask for a line of text. It's a bit confusing, but very useful. ChrisA From cs at cskk.id.au Thu Mar 9 16:59:33 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 10 Mar 2023 08:59:33 +1100 Subject: Baffled by readline module In-Reply-To: <640a4ade.020a0220.1d3cb.0243@mx.google.com> References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> Message-ID: On 09Mar2023 13:08, Grant Edwards wrote: >On 2023-03-09, Chris Angelico wrote: >> Not sure about the history file, and I would assume that if you don't >> configure one, history is simply lost when you restart. But with tab >> completion, unless you need to be able to input a tab character, it >> should be safe to ignore the feature and leave it at the defaults. > >Indeed, that seems to be how it works (though I never found that >stated anywhere in the docs). > >What's really weird about the docs is that when it is described it >doesn't even _mention_ that it provides command-line recall and >editing: [...] I think this might be the common case of a module which wraps another library: there's a tension between describing everything in pointless detail and the trite "we're just shimming this library, go read its docs". The module documentation needs to: - not insult the reader by saying nearly nothing ("this is just GNU readline, hooked to Python!") I'm looking at you, many "man" pages on a GNU based system which say "oh just go and read GNI info, it's all over there" - be detailed enough to enumerate the API calls and at least summarise their semantics - be general enough to not overprescribe so that small shifts in the library as it evolves don't cause falsehoods in the module docs (and a nightmarish maintenance burden) Similar example: the "os" modules, which largely shims the OS POSIX calls. It lists them and has a paragraph on their purpose and the meaning of the flags (for example). But the platform specifics and fine grained stuff is off in "man 2 foo" for the Python "os.foo" function. [...] >It finally dawned on me after seeing an example I found elsewhere that >you don't call some module method to fetch the next user-entered line. > >You call the input() built-in. Ah. That's not overtly stated? [...reads...] Ah, there it is in the last sentence of the opening paragraph. Not quite as in-your-face as I'd have liked it. That paragraph could do with being a bullet list of use cases. Cheers, Cameron Simpson From rosuav at gmail.com Thu Mar 9 17:11:31 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Mar 2023 09:11:31 +1100 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: <4e82452b-23fc-8d30-6f21-268aabd7d623@tompassin.net> Message-ID: On Fri, 10 Mar 2023 at 07:43, Thomas Passin wrote: > > On 3/9/2023 3:29 AM, aapost wrote: > > The 'what I am trying to do' is ask a question regarding opinions and > > practices on issuing a sequence of actions within a lambda via a tuple > > (since the common practice approaches against it - mainly with tkinter - > > feel more convoluted), and in doing so leaving it open ended to get a > > feel on what opinions are, and to see if any opinions influence mine. > > I finally realized why I am uncomfortable with doing this kind of thing. > It's because, IMHO, lambda expressions should not have side effects > and should not require much mental effort to grasp what they do. Yes, > you can do so. You can even print from a lambda (and it might be useful > for debugging): > > lambda x: print(f'The lambda received {x}') or x*x I'm not sure why lambda functions shouldn't have side effects. They can be used for anything, as long as it's a single expression (which can, of course, be composed of other expressions). > The Python Reference on readthedocs.io also has a tk example that > specifically wants the side effect (see > https://python-reference.readthedocs.io/en/latest/docs/operators/lambda.html): > > >>> # this is a code snippet from a Tkinter gui app > >>> # in this case lambda is quite convenient > >>> self.btn_cancel = Button(self.progress_container, text='Cancel', > >>> command=lambda: subprocess.call('taskkill /f /im uberzip.exe', > >>> shell=True)) > > Maybe so, but I think it's better not to have side effects hidden away > in expressions that are hard to read and understand. And being > anonymous, there is no function name to remind you what the action is > suppose to do. Much better (still IMHO, of course): The purpose of the lambda function is to tie the effect to the function. Otherwise, you have to go elsewhere to figure out what each one does. It's not inherently better to give names to everything, especially when those functions are only ever used once. In fact, I'd say that that is usually *worse*. > def kill_uberzip(): > """Kill an external running program named uberzip.exe.""" > subprocess.call('taskkill /f /im uberzip.exe', shell=True)) > > self.btn_cancel = Button(self.progress_container, text='Cancel', > command = kill_uberzip()) And this is one of the reasons it's worse: with the lambda function, you won't fall into this trap. It's a classic bug, and a rather nasty one; can you see it? If not, this is a VERY strong argument in favour of the lambda function. Even if you can, the mere fact that you made this error indicates how easy it is to slip into the faulty way of writing it. > This way, it's easy to understand what btn_cancel() will do each time > you scan that line of code. Only if the name is enough information, and it seldom is. Whereas with the lambda function, you have the entire code there, so you can understand what btn_cancel does without having to bookmark your spot there, go elsewhere, and find out what kill_uberzip() does. > For this particular example, it might turn out that there could be more > than one instance of uberzip.exe running at the same time. Which one > should be killed, and how do you kill the right one? With the function, > you can get those details under control, but I hate to think what might > happen to the lambda expression. Maybe, but this is just the example getting in the way. Obviously the larger a function needs to be, the less reasonable to make it a lambda function. That's why I'm of the opinion that it's better to use a different system, such as function decorators or a class namespace. For example: self.btn_cancel = Button(...) @on(self.btn_cancel, "command") def kill_uberzip(): ... Or alternatively: class btn_cancel(Button): def command(self): ... These kinds of systems allow much more flexibility than lambda functions, without the issues of name repetition and disconnection. > Yes, of course, there can be times when the lambda expression is > somewhat easy to understand and the side effects are harmless. In that > case, it may be easy enough to grasp quickly that the anonymous function > would not benefit from having a name. So OK, it's not a hard-and-fast > rule. Definitely not a hard-and-fast rule, but in defense of the Python's lambda, at least we don't have resonance cascades happening. ChrisA From rosuav at gmail.com Thu Mar 9 17:14:13 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Mar 2023 09:14:13 +1100 Subject: Baffled by readline module In-Reply-To: References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> Message-ID: On Fri, 10 Mar 2023 at 09:01, Cameron Simpson wrote: > I think this might be the common case of a module which wraps another > library: there's a tension between describing everything in pointless > detail and the trite "we're just shimming this library, go read its > docs". Yeah, it's a combination of this... > >You call the input() built-in. > > Ah. That's not overtly stated? [...reads...] Ah, there it is in the last > sentence of the opening paragraph. Not quite as in-your-face as I'd have > liked it. That paragraph could do with being a bullet list of use cases. ... and this. With a lot of "just wrap that library" functions, it can be exactly as you say: a bit of documentation about each function, and you can skim those to see what's available. But with readline, there isn't a "give me a command from the user" function, because that's input(). Maybe there should be an example added at the end? ChrisA From grant.b.edwards at gmail.com Thu Mar 9 17:18:10 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 09 Mar 2023 14:18:10 -0800 (PST) Subject: Baffled by readline module References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> Message-ID: <640a5b22.050a0220.f0fb6.039e@mx.google.com> On 2023-03-09, Cameron Simpson wrote: > [...] >>It finally dawned on me after seeing an example I found elsewhere that >>you don't call some module method to fetch the next user-entered line. >> >>You call the input() built-in. > > Ah. That's not overtly stated? [...reads...] Ah, there it is in the last > sentence of the opening paragraph. Not quite as in-your-face as I'd have > liked it. What threw me off the track for a while was that the sentence to which you refer says it affects the "prompts offered by input()". In my head, that means it changes the string that's printed on stdout before stuff is read from stdin. That's different that affecting the handling of user input read by input(). It doesn't actually change anything about the prompts provided by input(). It changes the handling of the user input by input(). I guess I read it too literally. I must spend too much time with computers. > That paragraph could do with being a bullet list of use cases. From aapost at idontexist.club Thu Mar 9 17:16:15 2023 From: aapost at idontexist.club (aapost) Date: Thu, 9 Mar 2023 17:16:15 -0500 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: Message-ID: On 3/9/23 04:06, Alan Gauld wrote: > Thank you for the feedback, I appreciate the comments. To add a little extra, there is actually a reason I lean toward overuse of .config() for a lot of things even though they could be sent to the constructor (other than that w["attribute"]= doesn't work in a lambda). It comes from a use case I needed to solve in the shortcoming of tk with frames not being scrollable, requiring a canvas. When dynamically generating a series of widgets (i.e. loading a custom json/xml layout config file), getting the scrollable area right is a bit of a chore with a catch-22 situation. With an inner frame in a canvas, pack_propogate(tk.True) is the default on the frame, so that the children dictate the size, but in doing so it prevents the frame from expanding to the full width of the area it's given within the UI layout. If you turn pack_propogate to tk.False, it breaks the ability for the canvas to return bbox(tk.ALL) (which is kind of rough anyway as the tcl docs state "The return value may overestimate the actual bounding box by a few pixels."). So you end up with 1,1 and no way of knowing what size scrollable area to set. Trying to obtain this value from a source outside of the canvas requires knowing what you are placing the canvas in each time, and was creating a similar catch-22 as the outer widget doesn't know what it wants it's size to be without knowing what the inner widget wants.. Switching to False, grabbing bbox, then back to True of course causes an unsightly flicker and disrupts the smoothness of the user experience. So my solution is to create a widget instantiator which does a few things, mainly adding something I call a "ghost". it's something like this: instantiator(qlass, master, config_args=None, pack_args=None, init_args=None, ghost=False): if not init_args: init_args = {} object = qlass(master=master, **init_args) if hasattr(master, "ghost"): object.ghost = qlass(master=master.ghost, **init_args) elif ghost: object.ghost = qlass(master=tk.Frame(), **init_args) When i pass it a canvas and say ghost=True, the canvas gets a .ghost duplicate, which is attached to an arbitrary frame that I never pack and stays invisible. Subsequent widgets created to the canvas then see that their parent, starting with the canvas, have a ghost, and in return get a ghost of themselves attached to their parents ghost. This allows you to get an accurate bbox size from the unseen ghost canvas that mirrors the visible version. Keeping the init_args down to only what is necessary helps in consistency, and the subsequent config_args and pack_args I have in their respective dicts. This also allows me to create a quality of life pack function I call ppack() def ppack(self): self.pack(**self.pack_args) if hasattr(self, "ghost"): self.ghost.pack(**self.ghost.pack_args) return self That allows each primary widget to manage and track their own set of configurations. Of course I could strip a lot of that crap out if I find a better and smooth way of obtaining those bbox numbers, but I didn't see any quick solutions in glancing through the tcl/tk source so I went with what works for now. From rosuav at gmail.com Thu Mar 9 17:43:39 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Mar 2023 09:43:39 +1100 Subject: Baffled by readline module In-Reply-To: <640a5b22.050a0220.f0fb6.039e@mx.google.com> References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a5b22.050a0220.f0fb6.039e@mx.google.com> Message-ID: On Fri, 10 Mar 2023 at 09:20, Grant Edwards wrote: > > On 2023-03-09, Cameron Simpson wrote: > > > [...] > >>It finally dawned on me after seeing an example I found elsewhere that > >>you don't call some module method to fetch the next user-entered line. > >> > >>You call the input() built-in. > > > > Ah. That's not overtly stated? [...reads...] Ah, there it is in the last > > sentence of the opening paragraph. Not quite as in-your-face as I'd have > > liked it. > > What threw me off the track for a while was that the sentence to which > you refer says it affects the "prompts offered by input()". In my head, > that means it changes the string that's printed on stdout before stuff > is read from stdin. That's different that affecting the handling of > user input read by input(). > > It doesn't actually change anything about the prompts provided by > input(). It changes the handling of the user input by input(). > > I guess I read it too literally. I must spend too much time with > computers. It does actually affect the prompts, although only in subtle ways. import readline print("Pseudo-prompt: ", end="") msg1 = input() msg2 = input("Actual prompt: ") print(repr(msg1)) print(repr(msg2)) At each of the prompts, type a bit of text, then backspace it all the way. The actual prompt will remain, but the pseudo-prompt will get cleared off. There'll be other small differences too. Maybe that could be mentioned somewhere too; but this is definitely something to be more careful with locking in, since the behaviour may not be quite the same if it's using libedit instead of GNU readline. ChrisA From grant.b.edwards at gmail.com Thu Mar 9 18:02:53 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 09 Mar 2023 15:02:53 -0800 (PST) Subject: Baffled by readline module References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a5b22.050a0220.f0fb6.039e@mx.google.com> Message-ID: <640a659d.050a0220.f0fb6.0443@mx.google.com> On 2023-03-09, Grant Edwards wrote: > On 2023-03-09, Cameron Simpson wrote: > >> [...] >>>It finally dawned on me after seeing an example I found elsewhere that >>>you don't call some module method to fetch the next user-entered line. >>> >>>You call the input() built-in. >> >> Ah. That's not overtly stated? [...reads...] Ah, there it is in the last >> sentence of the opening paragraph. Not quite as in-your-face as I'd have >> liked it. > > What threw me off the track for a while was that the sentence to which > you refer says it affects the "prompts offered by input()". In my head, > that means it changes the string that's printed on stdout before stuff > is read from stdin. That's different that affecting the handling of > user input read by input(). > > It doesn't actually change anything about the prompts provided by > input(). It changes the handling of the user input by input(). > > I guess I read it too literally. I must spend too much time with > computers. Yeesh. What's _really_ embarassing is that I just stumbled across a small test program with which I had apparently figured this out 10-12 years ago. Must be about time to retire... -- Grant From rosuav at gmail.com Thu Mar 9 18:11:34 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Mar 2023 10:11:34 +1100 Subject: Baffled by readline module In-Reply-To: <640a659d.050a0220.f0fb6.0443@mx.google.com> References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a5b22.050a0220.f0fb6.039e@mx.google.com> <640a659d.050a0220.f0fb6.0443@mx.google.com> Message-ID: On Fri, 10 Mar 2023 at 10:04, Grant Edwards wrote: > > Yeesh. What's _really_ embarassing is that I just stumbled across a > small test program with which I had apparently figured this out 10-12 > years ago. Must be about time to retire... > You expect yourself to remember test programs you wrote a decade ago?? I've forgotten full-on projects from that far back! Though, congrats on being able to stumble across it. That's quite something. ChrisA From grant.b.edwards at gmail.com Thu Mar 9 18:43:14 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 09 Mar 2023 15:43:14 -0800 (PST) Subject: Baffled by readline module References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a5b22.050a0220.f0fb6.039e@mx.google.com> <640a659d.050a0220.f0fb6.0443@mx.google.com> Message-ID: <640a6f12.020a0220.1aae6.05d5@mx.google.com> On 2023-03-09, Chris Angelico wrote: > On Fri, 10 Mar 2023 at 10:04, Grant Edwards wrote: > >> Yeesh. What's _really_ embarassing is that I just stumbled across a >> small test program with which I had apparently figured this out >> 10-12 years ago. Must be about time to retire... > > You expect yourself to remember test programs you wrote a decade > ago?? I've forgotten full-on projects from that far back! Another thing that has happened a few times is that I'm trying to figure out how to do something I'm pretty sure should be possible, but I can't figure out how. After the usual resources fail, then I start Googling with varous sets of keywords. After a while, Google eventually finds the answer in an old mailing-list archive where there's a nice explanation in a post... .... by me. > Though, congrats on being able to stumble across it. That's quite > something. After I figured out the answer, I realized it did seem a little familar, so I tried a grep -r in my home directory which has stuff lying around from as far back as 2001. When a computer dies, I generally just cp -a (or rsync -a) $HOME to a new one. -- Grant From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Mar 9 18:49:50 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 9 Mar 2023 17:49:50 -0600 Subject: Baffled by readline module In-Reply-To: <640a659d.050a0220.f0fb6.0443@mx.google.com> References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a5b22.050a0220.f0fb6.039e@mx.google.com> <640a659d.050a0220.f0fb6.0443@mx.google.com> Message-ID: On 2023-03-09 at 15:02:53 -0800, Grant Edwards wrote: > Yeesh. What's _really_ embarassing is that I just stumbled across a > small test program with which I had apparently figured this out 10-12 > years ago. Must be about time to retire... Retiring doesn't help. :-) I retired almost five years ago, and I just (within the past few days) (re)discovered a command line parsing library I'd written about a year and a half ago (i.e., after I retired). Dan From cs at cskk.id.au Thu Mar 9 18:28:49 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 10 Mar 2023 10:28:49 +1100 Subject: Baffled by readline module In-Reply-To: <640a4ade.020a0220.1d3cb.0243@mx.google.com> References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> Message-ID: On 09Mar2023 13:08, Grant Edwards wrote: >Having a module modify the behavior of a built-in makes me cringe. Maybe. But input(), like print(), is one of those funky conveniences for human interaction. I'm somewhat ok with that. If for no other reason than to make keyboard arrow keys act as normal humans expect them to (as opposed to old nerds who predate such fancies). General improvement of the user experience. Another thing affected by readline is the cmd module, which will use it during the input step for completion _if the module is present_. And use it for the input itself if it is loaded. (These might not mean different things and instead be an accident of phrasing.) Again, a human interaction convenience and I'm good with it. Good enough to have written this code recently: try: import readline except ImportError: pass just to turn it on if available. Cheers, Cameron Simpson From rosuav at gmail.com Thu Mar 9 19:02:52 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Mar 2023 11:02:52 +1100 Subject: Baffled by readline module In-Reply-To: References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a5b22.050a0220.f0fb6.039e@mx.google.com> <640a659d.050a0220.f0fb6.0443@mx.google.com> Message-ID: On Fri, 10 Mar 2023 at 10:51, <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > > On 2023-03-09 at 15:02:53 -0800, > Grant Edwards wrote: > > > Yeesh. What's _really_ embarassing is that I just stumbled across a > > small test program with which I had apparently figured this out 10-12 > > years ago. Must be about time to retire... > > Retiring doesn't help. :-) > > I retired almost five years ago, and I just (within the past few days) > (re)discovered a command line parsing library I'd written about a year > and a half ago (i.e., after I retired). > Traditional retirement: Work till you're 60 or 65 or whatever, then society pats you on the head, calls you a "senior citizen", and lets you go and be idle till you die (which might be prematurely soon). Direction-change retirement: Work till you can afford to zero out your income, then finally do what you've always wanted to do, but never had time because you spent so much of it earning money. Tell-the-next-generation: Work till you know so much that you're infinitely valuable, then spend the rest of your life empowering the next group of amazing people. See for instance: NASA. Programmer retirement: At an early age, learn how to wield PHENOMENAL COSMIC POWER, and spend the next X years in an itty bitty working space, earning money. Eventually, upgrade to better living/working space. Eventually, downgrade to a small wooden box six feet below the ground. Never once relinquish the power. Never once abandon that feeling of mastery. We're not really an industry that has a concept of retirement. ChrisA From aapost at idontexist.club Thu Mar 9 17:55:01 2023 From: aapost at idontexist.club (aapost) Date: Thu, 9 Mar 2023 17:55:01 -0500 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: Message-ID: On 3/9/23 16:37, Cameron Simpson wrote: > On 09Mar2023 09:06, Alan Gauld wrote: > Just a note that some code formatters use a trailing comma on the last > element to make the commas fold points. Both yapf (my preference) and > black let you write a line like (and, indeed, flatten if short enough): > > ??? ( a, b, c ) > > but if you write: > > ??? ( a, b, c, ) > > they'll fold the lines like: > > ??? ( a, > ????? b, > ????? c, > ??? ) > Cameron Simpson Thanks for the info, good to know, I actually do like the idea of trailing commas for tuples (helps prevent things like the difference between ("abc") and ("abc",) and makes swapping things around nicer. I've just been using a lot of json lately and it has been subconsciously training me different, lol. From greg.ewing at canterbury.ac.nz Thu Mar 9 19:34:18 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 10 Mar 2023 13:34:18 +1300 Subject: Baffled by readline module In-Reply-To: References: <640a3318.020a0220.67dbd.001a@mx.google.com> <640a4ade.020a0220.1d3cb.0243@mx.google.com> Message-ID: On 10/03/23 10:08 am, Grant Edwards wrote: > It finally dawned on me after seeing an example I found elsewhere that > you don't call some module method to fetch the next user-entered line. > > You call the input() built-in. > > Having a module modify the behavior of a built-in makes me cringe. Importing the module is not modifying the built-in. If your Python has been compiled with gnu readline support, input() *already* provides recall and editing facilities. You only need to import the readline module if you want to change the configuration. Yes, it would be helpful if the docs for the readline module explained this. At present they seem to assume that you already know what the readline module is for and just want a summary of the API. It *is* mentioned briefly in the docs for input(), but again somebody wanting line editing functionality wouldn't necessarily think of looking there. -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 9 19:37:54 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 10 Mar 2023 13:37:54 +1300 Subject: Baffled by readline module In-Reply-To: References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> Message-ID: On 10/03/23 10:59 am, Cameron Simpson wrote: > I think this might be the common case of a module which wraps another > library It's not quite the same thing, though -- the library it wraps is already hooked into things behind the scenes in ways that may not be obvious. (Unless you're Dutch?) -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 9 19:41:07 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 10 Mar 2023 13:41:07 +1300 Subject: Baffled by readline module In-Reply-To: References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a5b22.050a0220.f0fb6.039e@mx.google.com> Message-ID: On 10/03/23 11:43 am, Chris Angelico wrote: > import readline > print("Pseudo-prompt: ", end="") > msg1 = input() > msg2 = input("Actual prompt: ") > print(repr(msg1)) > print(repr(msg2)) > > At each of the prompts, type a bit of text, then backspace it all the > way. The actual prompt will remain, but the pseudo-prompt will get > cleared off. There'll be other small differences too. Hmmm, so it seems that merely importing readline does change things a little bit. This is rather nasty. I'd go so far as to call it a bug in gnu readline -- it shouldn't be erasing something that the user didn't type in. -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 9 19:43:31 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 10 Mar 2023 13:43:31 +1300 Subject: Baffled by readline module In-Reply-To: References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a5b22.050a0220.f0fb6.039e@mx.google.com> <640a659d.050a0220.f0fb6.0443@mx.google.com> <640a6f12.020a0220.1aae6.05d5@mx.google.com> Message-ID: On 10/03/23 12:43 pm, Grant Edwards wrote: > When a computer dies, I > generally just cp -a (or rsync -a) $HOME to a new one. Same here, more or less. My current machine has multiple archaeological layers going back about 5 generations of technology... -- Greg From grant.b.edwards at gmail.com Thu Mar 9 19:46:36 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 09 Mar 2023 16:46:36 -0800 (PST) Subject: Baffled by readline module References: <640a3318.020a0220.67dbd.001a@mx.google.com> <640a4ade.020a0220.1d3cb.0243@mx.google.com> Message-ID: <640a7dec.020a0220.8ce2f.0699@mx.google.com> On 2023-03-10, Greg Ewing via Python-list wrote: > On 10/03/23 10:08 am, Grant Edwards wrote: >> It finally dawned on me after seeing an example I found elsewhere that >> you don't call some module method to fetch the next user-entered line. >> >> You call the input() built-in. >> >> Having a module modify the behavior of a built-in makes me cringe. > > Importing the module is not modifying the built-in. > > If your Python has been compiled with gnu readline support, > input() *already* provides recall and editing facilities. That's not how Python 3.10.10 works for me. When I run the code below, I do not get command recall and editing. If I hit arrow keys, I just see the escape sequence echoed and returned by input(). Likewise for things like ctrl-P, ctrl-N, etc. I have to uncomment the import statement to get command line recall and editing to work. Without the import, the escape sequences from arrow keys just end up in the input data. #!/usr/bin/python # import readline # readline.parse_and_bind('set editing-mode emacs') while True: try: line = input('enter something (EOF to quit): ') except EOFError: print() break print('ENTERED: "%s"' % line) > You only need to import the readline module if you want to > change the configuration. That's not how it acts for me. I have to "import readline" to get command line recall and editing. The parse_and_bind, doesn't seem to do anything -- emacs mode seems to be the default. > Yes, it would be helpful if the docs for the readline module > explained this. At present they seem to assume that you already > know what the readline module is for and just want a summary > of the API. > > It *is* mentioned briefly in the docs for input(), but again > somebody wanting line editing functionality wouldn't necessarily > think of looking there. From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Mar 9 19:42:02 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 9 Mar 2023 18:42:02 -0600 Subject: Baffled by readline module In-Reply-To: References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a5b22.050a0220.f0fb6.039e@mx.google.com> <640a659d.050a0220.f0fb6.0443@mx.google.com> Message-ID: On 2023-03-10 at 11:02:52 +1100, Chris Angelico wrote: > Traditional retirement: Work till you're 60 or 65 or whatever, then > society pats you on the head, calls you a "senior citizen", and lets > you go and be idle till you die (which might be prematurely soon). Sounds like Free Four?: The memories of a man in his old age Are the deeds of a man in his prime. You shuffle in the gloom of the sickroom And talk to yourself as you die. Great tune. Bad life. > Direction-change retirement: Work till you can afford to zero out your > income, then finally do what you've always wanted to do, but never had > time because you spent so much of it earning money. A little bit of that. We live in the RV, and we have crisscrossed the country more than once, coronavirus notwithstanding. > Tell-the-next-generation: Work till you know so much that you're > infinitely valuable, then spend the rest of your life empowering the > next group of amazing people. See for instance: NASA. And a little bit of that, too. NASA would have been nice; I did my most of my time in the commercial space, with a short break in the government contracting business. > Programmer retirement: At an early age, learn how to wield PHENOMENAL > COSMIC POWER, and spend the next X years in an itty bitty working > space, earning money. Eventually, upgrade to better living/working > space. Eventually, downgrade to a small wooden box six feet below the > ground. Never once relinquish the power. Never once abandon that > feeling of mastery. I was with you until that part of the small wooden box. :-) > We're not really an industry that has a concept of retirement. Which is why I'm still here (on this mailing list, and a handful of others like it). Thanks for asking. ? https://www.azlyrics.com/lyrics/pinkfloyd/freefour.html From greg.ewing at canterbury.ac.nz Thu Mar 9 20:53:55 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 10 Mar 2023 14:53:55 +1300 Subject: Baffled by readline module In-Reply-To: References: <640a3318.020a0220.67dbd.001a@mx.google.com> <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a7dec.020a0220.8ce2f.0699@mx.google.com> Message-ID: On 10/03/23 1:46 pm, Grant Edwards wrote: > That's not how it acts for me. I have to "import readline" to get > command line recall and editing. Maybe this has changed? Or is platform dependent? With Python 3.8 on MacOSX I can use up arrow with input() to recall stuff I've typed before, without having to import anything. -- Greg From rosuav at gmail.com Thu Mar 9 20:57:48 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Mar 2023 12:57:48 +1100 Subject: Baffled by readline module In-Reply-To: References: <640a3318.020a0220.67dbd.001a@mx.google.com> <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a7dec.020a0220.8ce2f.0699@mx.google.com> Message-ID: On Fri, 10 Mar 2023 at 12:56, Greg Ewing via Python-list wrote: > > On 10/03/23 1:46 pm, Grant Edwards wrote: > > That's not how it acts for me. I have to "import readline" to get > > command line recall and editing. > > Maybe this has changed? Or is platform dependent? > > With Python 3.8 on MacOSX I can use up arrow with input() > to recall stuff I've typed before, without having to > import anything. > import sys; "readline" in sys.modules Is it? Might be that something's pre-importing it. ChrisA From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Mar 9 22:00:41 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 9 Mar 2023 21:00:41 -0600 Subject: Baffled by readline module In-Reply-To: References: <640a3318.020a0220.67dbd.001a@mx.google.com> <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a7dec.020a0220.8ce2f.0699@mx.google.com> Message-ID: On 2023-03-10 at 12:57:48 +1100, Chris Angelico wrote: > On Fri, 10 Mar 2023 at 12:56, Greg Ewing via Python-list > wrote: > > > > On 10/03/23 1:46 pm, Grant Edwards wrote: > > > That's not how it acts for me. I have to "import readline" to get > > > command line recall and editing. > > > > Maybe this has changed? Or is platform dependent? > > > > With Python 3.8 on MacOSX I can use up arrow with input() > > to recall stuff I've typed before, without having to > > import anything. > > > > import sys; "readline" in sys.modules > > Is it? Might be that something's pre-importing it. My ~/.pythonrc contains the following: import readline import rlcompleter readline.parse_and_bind( 'tab: complete' ) IIRC, that's been there "forever," certainly back into Python2, and probably back into Python1. On my Arch Linux system Python 3.10.9, I get readline behavior with or without those lines. From grant.b.edwards at gmail.com Thu Mar 9 22:11:56 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 09 Mar 2023 19:11:56 -0800 (PST) Subject: Baffled by readline module References: <640a3318.020a0220.67dbd.001a@mx.google.com> <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a7dec.020a0220.8ce2f.0699@mx.google.com> Message-ID: <640a9ffc.050a0220.4031a.07ab@mx.google.com> On 2023-03-10, 2QdxY4RzWzUUiLuE at potatochowder.com <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > On 2023-03-10 at 12:57:48 +1100, > Chris Angelico wrote: > >> On Fri, 10 Mar 2023 at 12:56, Greg Ewing via Python-list >> wrote: >> > >> > On 10/03/23 1:46 pm, Grant Edwards wrote: >> > > That's not how it acts for me. I have to "import readline" to get >> > > command line recall and editing. >> > >> > Maybe this has changed? Or is platform dependent? >> > >> > With Python 3.8 on MacOSX I can use up arrow with input() >> > to recall stuff I've typed before, without having to >> > import anything. If you run this application from the command line, you get command recall and editing when entering strings at the "cmd:" prompt? #!/usr/bin/python while True: try: line = input('cmd: ') except EOFError: print() break print('You entered "%s"' % line) >> import sys; "readline" in sys.modules >> >> Is it? Might be that something's pre-importing it. > > My ~/.pythonrc contains the following: > > import readline > import rlcompleter > readline.parse_and_bind( 'tab: complete' ) > > IIRC, that's been there "forever," certainly back into Python2, and > probably back into Python1. On my Arch Linux system Python 3.10.9, I > get readline behavior with or without those lines. I "get readline behavior" in the REPL without an "import readline", but that's irrelevent. We're talking about a command-line application that's calling input(). From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Mar 9 22:23:23 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 9 Mar 2023 21:23:23 -0600 Subject: Baffled by readline module In-Reply-To: <640a9ffc.050a0220.4031a.07ab@mx.google.com> References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a7dec.020a0220.8ce2f.0699@mx.google.com> <640a9ffc.050a0220.4031a.07ab@mx.google.com> Message-ID: On 2023-03-09 at 19:11:56 -0800, Grant Edwards wrote: > On 2023-03-10, 2QdxY4RzWzUUiLuE at potatochowder.com <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > If you run this application from the command line, you get command > recall and editing when entering strings at the "cmd:" prompt? > > #!/usr/bin/python > while True: > try: > line = input('cmd: ') > except EOFError: > print() > break > print('You entered "%s"' % line) In my case, no. From greg.ewing at canterbury.ac.nz Fri Mar 10 00:09:28 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 10 Mar 2023 18:09:28 +1300 Subject: Baffled by readline module In-Reply-To: References: <640a3318.020a0220.67dbd.001a@mx.google.com> <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a7dec.020a0220.8ce2f.0699@mx.google.com> Message-ID: On 10/03/23 2:57 pm, Chris Angelico wrote: > import sys; "readline" in sys.modules > > Is it? Yes, it is -- but only when using the repl! If I put that in a script, I get False. My current theory is that it gets pre-imported when using Python interactively because the repl itself uses it. -- Greg From greg.ewing at canterbury.ac.nz Fri Mar 10 00:11:57 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 10 Mar 2023 18:11:57 +1300 Subject: Baffled by readline module In-Reply-To: References: <640a3318.020a0220.67dbd.001a@mx.google.com> <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a7dec.020a0220.8ce2f.0699@mx.google.com> Message-ID: On 10/03/23 4:00 pm, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > My ~/.pythonrc contains the following: > > import readline > import rlcompleter > readline.parse_and_bind( 'tab: complete' ) I don't have a ~/.pythonrc, so that's not what's doing it for me. -- Greg From gheskett at shentel.net Fri Mar 10 04:13:25 2023 From: gheskett at shentel.net (gene heskett) Date: Fri, 10 Mar 2023 04:13:25 -0500 Subject: Baffled by readline module In-Reply-To: References: <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a5b22.050a0220.f0fb6.039e@mx.google.com> <640a659d.050a0220.f0fb6.0443@mx.google.com> Message-ID: On 3/9/23 20:31, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > > I was with you until that part of the small wooden box. :-) > So was I, but we all put that off as long as we can. I retired 22 years ago. >> We're not really an industry that has a concept of retirement. > > Which is why I'm still here (on this mailing list, and a handful of > others like it). > More echo. And doing things, albeit at a slower pace, that I always wanted to do. Take care and stay well all. Cheers, Gene Heskett. -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author, 1940) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From gweatherby at uchc.edu Fri Mar 10 05:30:41 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Fri, 10 Mar 2023 10:30:41 +0000 Subject: Baffled by readline module In-Reply-To: <640a3318.020a0220.67dbd.001a@mx.google.com> References: <640a3318.020a0220.67dbd.001a@mx.google.com> Message-ID: I would say, ?No, readline is not the right tool.? cmd.Cmd is: https://docs.python.org/3/library/cmd.html. I have a couple of cmd.Cmd modules, one of which I use daily and the other weekly. From: Python-list on behalf of Grant Edwards Date: Thursday, March 9, 2023 at 2:29 PM To: python-list at python.org Subject: Baffled by readline module *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** In an interactive command-line Python program on Linux, I want to be able to read a line at a time from stdin, providing command line history and editing to the user. In C, I would use GNU readline to do that. Python has the readline module, which appears to be a wrapper for GNU readline. However, I've read and re-read the documenation for that module, but I'm completely baffled. There's all sorts of stuff about history files, but I neither need nor want a history file. Likewise tab-completion: don't want it. All the examples not only involve history files and tab-completion but they're somehow connected to the interactive Python REPL, which is also completely off-base for my use case. Is the readline module not the right tool for an interactive Linux command-line application that needs to provide command line recall and editing to the user who's entering stuff on stdin from a tty? -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!iMrZQmCvzTBhFnzmb4Px34UNZrxSWMjU1Hxvg9CTc_-3tFWtjxB3-OrQUrXChOoNP8vm3em2V1XxihY0742KUNLDJnrV$ From grant.b.edwards at gmail.com Fri Mar 10 09:37:56 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 10 Mar 2023 06:37:56 -0800 (PST) Subject: Baffled by readline module References: <640a3318.020a0220.67dbd.001a@mx.google.com> =?utf-8?q?=3CSJ0PR1?= =?utf-8?q?4MB586445FB9FC0FB1327A1CA00B9BA9=40SJ0PR14MB5864=2Enamprd14=2Epro?= =?utf-8?q?d=2Eoutlook=2Ecom=3E?= Message-ID: <640b40c4.920a0220.da552.0107@mx.google.com> On 2023-03-10, Weatherby,Gerard wrote: > I would say, ?No, readline is not the right tool.? > > cmd.Cmd is: https://docs.python.org/3/library/cmd.html. I have a > couple of cmd.Cmd modules, one of which I use daily and the other > weekly. I'll have to remember that one. It doesn't really fit my current use case, but there are others where it would work nicely. However, cmd.Cmd does not provide command recall and editing. According to the page above, that's provided by the readline module: If the readline module is loaded, input will automatically inherit bash-like history-list editing (e.g. Control-P scrolls back to the last command, Control-N forward to the next one, Control-F moves the cursor to the right non-destructively, Control-B moves the cursor to the left non-destructively, etc.). -- Grant From gweatherby at uchc.edu Fri Mar 10 11:07:41 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Fri, 10 Mar 2023 16:07:41 +0000 Subject: Baffled by readline module In-Reply-To: <640b40c4.920a0220.da552.0107@mx.google.com> References: <640a3318.020a0220.67dbd.001a@mx.google.com> =?utf-8?q?=3CSJ0PR1?= =?utf-8?q?4MB586445FB9FC0FB1327A1CA00B9BA9=40SJ0PR14MB5864=2Enamprd14=2Epro?= =?utf-8?q?d=2Eoutlook=2Ecom=3E?= <640b40c4.920a0220.da552.0107@mx.google.com> Message-ID: On our Linux systems, I can up-arrow to go back to prior commands and use the left and right arrows to navigate a line. The functionality may be provided internally by readline. I?ve never had to dig into it because it meets my needs out of the box. From: Python-list on behalf of Grant Edwards Date: Friday, March 10, 2023 at 9:39 AM To: python-list at python.org Subject: Re: Baffled by readline module *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** On 2023-03-10, Weatherby,Gerard wrote: > I would say, ?No, readline is not the right tool.? > > cmd.Cmd is: https://urldefense.com/v3/__https://docs.python.org/3/library/cmd.html__;!!Cn_UX_p3!iH9PMR4wNfv3oBLWR_W46RY8KUzLVxsA_XRv2RJk6Td_ND59EaBvcJ58-Crx2PReX-ELMx7IEMAQ1YfpIt7xmHBGs8a1$ . I have a > couple of cmd.Cmd modules, one of which I use daily and the other > weekly. I'll have to remember that one. It doesn't really fit my current use case, but there are others where it would work nicely. However, cmd.Cmd does not provide command recall and editing. According to the page above, that's provided by the readline module: If the readline module is loaded, input will automatically inherit bash-like history-list editing (e.g. Control-P scrolls back to the last command, Control-N forward to the next one, Control-F moves the cursor to the right non-destructively, Control-B moves the cursor to the left non-destructively, etc.). -- Grant -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!iH9PMR4wNfv3oBLWR_W46RY8KUzLVxsA_XRv2RJk6Td_ND59EaBvcJ58-Crx2PReX-ELMx7IEMAQ1YfpIt7xmEU_EBpr$ From grant.b.edwards at gmail.com Fri Mar 10 12:12:41 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 10 Mar 2023 09:12:41 -0800 (PST) Subject: Baffled by readline module References: <640a3318.020a0220.67dbd.001a@mx.google.com> <640b40c4.920a0220.da552.0107@mx.google.com> =?utf-8?q?=3CSJ0PR14MB5864E96D?= =?utf-8?q?E5796AC4DAFB9FCCB9BA9=40SJ0PR14MB5864=2Enamprd14=2Eprod=2Eoutlook?= =?utf-8?q?=2Ecom=3E?= Message-ID: <640b6509.020a0220.2b13.05db@mx.google.com> On 2023-03-10, Weatherby,Gerard wrote: > On our Linux systems, I can up-arrow to go back to prior commands > and use the left and right arrows to navigate a line. The > functionality may be provided internally by readline. I?ve never had > to dig into it because it meets my needs out of the box. Apparently the cmd.Cmd docs are wrong. It says: If the readline module is loaded, input will automatically inherit bash-like history-list editing (e.g. Control-P scrolls back to the last command, Control-N forward to the next one, Control-F moves the cursor to the right non-destructively, Control-B moves the cursor to the left non-destructively, etc.). On my Python 3.10.10 Linux system, cmd.Com itself is importing the readline module unconditionally when I call cmdloop(). There's no 'if' about it. [It's moot for my current usage, because my application allows multiple commands per input line, and I don't see how cmd.Cmd can support that.] Here's my application that seem to show that cmd.Cmd.cmdloop() is importing the readline module: -------------------------------testit.py-------------------------------- import sys print('readline' in sys.modules) import cmd print('readline' in sys.modules) class MyShell(cmd.Cmd): intro = 'Welcome to my shell. Type help or ? to list commands.\n' prompt = '(what) ' file = None def do_what(self,arg): print('readline' in sys.modules) def do_bye(self, arg): print('Good bye') return True print('readline' in sys.modules) if __name__ == '__main__': print('readline' in sys.modules) MyShell().cmdloop() ------------------------------------------------------------------------ And here's what I see when I run it: ------------------------------------------------------------------------ $ python testit.py False False False False Welcome to my shell. Type help or ? to list commands. (what) what True (what) bye Good bye $ ------------------------------------------------------------------------ From simon+python at bleah.co.uk Fri Mar 10 12:23:22 2023 From: simon+python at bleah.co.uk (Simon Ward) Date: Fri, 10 Mar 2023 17:23:22 +0000 Subject: Baffled by readline module In-Reply-To: <640b40c4.920a0220.da552.0107@mx.google.com> References: <640a3318.020a0220.67dbd.001a@mx.google.com> <640b40c4.920a0220.da552.0107@mx.google.com> Message-ID: <20230310172322.GC23562@bleah.co.uk> On Fri, Mar 10, 2023 at 06:37:56AM -0800, Grant Edwards wrote: >On 2023-03-10, Weatherby,Gerard wrote: >I'll have to remember that one. It doesn't really fit my current use >case, but there are others where it would work nicely. > >However, cmd.Cmd does not provide command recall and >editing. According to the page above, that's provided by the readline >module There is also prompt_toolkit[1] for even more fancy command?line handling. The documentation even states it ?can be a very advanced pure Python replacement for GNU readline, but it can also be used for building full screen applications.? (It doesn?t depend on readline or libedit.) It?s used by IPython for its history, editing, and completion features. If cmd with readline is overkill for your use case then this is even more so, but I thought it worth a mention. Simon From eryksun at gmail.com Fri Mar 10 13:11:34 2023 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 10 Mar 2023 12:11:34 -0600 Subject: Baffled by readline module In-Reply-To: References: <640a3318.020a0220.67dbd.001a@mx.google.com> <640a4ade.020a0220.1d3cb.0243@mx.google.com> <640a7dec.020a0220.8ce2f.0699@mx.google.com> Message-ID: On 3/9/23, Greg Ewing via Python-list wrote: > On 10/03/23 4:00 pm, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: >> My ~/.pythonrc contains the following: >> >> import readline >> import rlcompleter >> readline.parse_and_bind( 'tab: complete' ) > > I don't have a ~/.pythonrc, so that's not what's doing it > for me. If it's available, the readline and rlcompleter modules are imported if stdin is a tty, [I]solated mode isn't enabled, and either [i]nspect is enabled or the REPL is being run. For example: $ python -c "import sys;print('readline' in sys.modules)" False $ python -ic "import sys;print('readline' in sys.modules)" True >>> $ python -ic "import sys;print('readline' in sys.modules)" 0>> $ python -Iic "import sys;print('readline' in sys.modules)" False >>> This is determined by the following function in "Modules/main.c:" pymain_import_readline(const PyConfig *config) { if (config->isolated) { return; } if (!config->inspect && config_run_code(config)) { return; } if (!isatty(fileno(stdin))) { return; } PyObject *mod = PyImport_ImportModule("readline"); if (mod == NULL) { PyErr_Clear(); } else { Py_DECREF(mod); } mod = PyImport_ImportModule("rlcompleter"); if (mod == NULL) { PyErr_Clear(); } else { Py_DECREF(mod); } } The hook for input() is handled by PyOS_Readline() in "Parser/myreadline.c". It depends on the exported function pointer PyOS_ReadlineFunctionPointer. When imported, the readline extension module in "Modules/readline.c" sets PyOS_ReadlineFunctionPointer to its call_readline() function. --- On Windows, Python is not distributed with a readline module. Instead, Python relies on the console host's builtin support for command-line editing, history, and aliases. The Windows console API function ReadConsoleW() has a parameter that supports implementing custom command-line completion. This is how the CMD shell implements tab completion for file paths. However, no one has developed a version of rlcompleter for the Windows console. Instead, there's a third-party "pyreadline3" package (note the "3"; don't install "pyreadline" by mistake) that implements readline for the Windows console, which supports rlcompleter. From cs at cskk.id.au Fri Mar 10 16:08:21 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 11 Mar 2023 08:08:21 +1100 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: Message-ID: On 09Mar2023 17:55, aapost wrote: >On 3/9/23 16:37, Cameron Simpson wrote: >>Just a note that some code formatters use a trailing comma on the last >>element to make the commas fold points. Both yapf (my preference) and >>black let you write a line like (and, indeed, flatten if short >>enough): >> >> ??? ( a, b, c ) >> >>but if you write: >> >> ??? ( a, b, c, ) >> >>they'll fold the lines like: >> >> ??? ( a, >> ????? b, >> ????? c, >> ??? ) >>Cameron Simpson > > >Thanks for the info, good to know, I actually do like the idea of >trailing commas for tuples (helps prevent things like the difference >between ("abc") and ("abc",) and makes swapping things around nicer. Just keep in mind that if you restructure code with copy/paste it can be a small issue (not really tied to the trailing comma but commas in general. More than once I've been bitten by doing roughly this: f( a, b=x+y, ) shuffled to: b=x+y, f( a, b=b, ) Whoops! It shows up almost immediately, but the first time it took me a while to see that stray comma. >I've just been using a lot of json lately and it has been >subconsciously training me different, lol. Yes, it hates the trailing comma. So annoying. Cheers, Cameron Simpson From cs at cskk.id.au Fri Mar 10 15:51:17 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 11 Mar 2023 07:51:17 +1100 Subject: Baffled by readline module In-Reply-To: <640b6509.020a0220.2b13.05db@mx.google.com> References: <640b6509.020a0220.2b13.05db@mx.google.com> Message-ID: On 10Mar2023 09:12, Grant Edwards wrote: >On 2023-03-10, Weatherby,Gerard wrote: >> On our Linux systems, I can up-arrow to go back to prior commands >> and use the left and right arrows to navigate a line. The >> functionality may be provided internally by readline. I?ve never had >> to dig into it because it meets my needs out of the box. > >Apparently the cmd.Cmd docs are wrong. It says: > > If the readline module is loaded, input will automatically > inherit bash-like history-list editing (e.g. Control-P scrolls > back to the last command, Control-N forward to the next one, > Control-F moves the cursor to the right non-destructively, > Control-B moves the cursor to the left non-destructively, etc.). > >On my Python 3.10.10 Linux system, cmd.Com itself is importing the >readline module unconditionally when I call cmdloop(). There's no 'if' >about it. I was wondering about that myself, whether this is an accident of phrasing. It doesn't say "is imported", so maybe the author was thinking "if readline's part of the install" here. Anyway, I've got a try/import-readline/except-importerror/pass in my cmd.Cmd wrapper, because I read this the way you read it. Cheers, Cameron Simpson From grant.b.edwards at gmail.com Fri Mar 10 17:38:28 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 10 Mar 2023 14:38:28 -0800 (PST) Subject: Baffled by readline module References: <640b6509.020a0220.2b13.05db@mx.google.com> Message-ID: <640bb164.020a0220.2a7a1.0ed1@mx.google.com> On 2023-03-10, Cameron Simpson wrote: > On 10Mar2023 09:12, Grant Edwards wrote: >>On 2023-03-10, Weatherby,Gerard wrote: >>> On our Linux systems, I can up-arrow to go back to prior commands >>> and use the left and right arrows to navigate a line. The >>> functionality may be provided internally by readline. I?ve never had >>> to dig into it because it meets my needs out of the box. >> >>Apparently the cmd.Cmd docs are wrong. It says: >> >> If the readline module is loaded, input will automatically >> inherit bash-like history-list editing (e.g. Control-P scrolls >> back to the last command, Control-N forward to the next one, >> Control-F moves the cursor to the right non-destructively, >> Control-B moves the cursor to the left non-destructively, etc.). >> >>On my Python 3.10.10 Linux system, cmd.Com itself is importing the >>readline module unconditionally when I call cmdloop(). There's no 'if' >>about it. > > I was wondering about that myself, whether this is an accident of > phrasing. It doesn't say "is imported", so maybe the author was thinking > "if readline's part of the install" here. Ah, that never ocurred to me. I understood "loaded" to mean "imported" without giving it a second thought. It probably does mean supported. From chris at candp-ent.com Fri Mar 10 15:15:23 2023 From: chris at candp-ent.com (Chris) Date: Fri, 10 Mar 2023 14:15:23 -0600 Subject: Problem with wxPython form Message-ID: <694ffeeb-1b2e-ec70-76df-579445cc0364@candp-ent.com> Hi everyone. I'm new to Python and wxPython. I've got a form I use to calculate the Sq In of a leather project. I'm using python 3.9.13 and wxPython 4.20 I'm having the following issues: 1) When I come into the form, no grid cell has the focus set - I start typing and nothing happens. I have to click the cell. If I hit Tab or Enter, the OnKeyDown fires, but does not move to the appropriate cell - it does nothing but run the update and move off of the current cell. The action I'm trying to make is this ENTER KEY: Always go down 1 row and to col 0 TAB, if Col 0 Move to Col 1 on same row, if Col 1 go to Row +1, Col 0 I also need to have what3ever cell it is supposed to land on to get the focus so I can just type. Currently I have to click in each cell I want/need to add. There could be up to 20 pieces of leather with differing sizes, so in order to accurately calculate the Sq In, I need to get all the measurements in. The form, one of several tabs, comes up and does everything else I've coded for great. Just no navigation. Can anyone assist? Here is the module with the form /***********************************************************************/ ''' Module Name : alwsqin.py Author ? ? ?: Chris Anderson Create Date : 03/10/2023 Description : This module contains the Sq In/MM/CM of leather used This file is Copyright Anderson Leather Works (c) 2023 ''' /########################################################################/ /#/ /# File Last Update and Person/ /#/ /#***********************************************************************/ /# Imports/ /import/wx /#from Imports/ /from/alwlogic /import/leather_sqin /class/LeatherSqInPanel(wx.Panel): ''' Name ? ? ? ?: LeatherSqInPanel Author ? ? ?: Chris Anderson Create Date : 02/23/2023 Description : Panel for the 'Leather Sq In Calculator ? ? ? ? ? ? ? in Leatherworking Cost Estimator app ''' dbTableName /=/'None' /def/__init__(self, parent): ? ? wx.Panel.__init__(/self/, parent) /self/.ls /=/leather_sqin /self/.grid /=/wx.grid.Grid(/self/, size/=/(600, 515)) /self/.grid.CreateGrid(30, 6) /# Set column labels/ /self/.grid.SetColLabelValue(0, "Length") /self/.grid.SetColLabelValue(1, "Width") /self/.grid.SetColLabelValue(2, "Total") /self/.grid.SetColLabelValue(3, "Grand Total") /self/.grid.SetColLabelValue(4, "Type") /self/.grid.SetColLabelValue(5, "Select Calc Method") /for/col /in/range(/self/.grid.GetNumberCols()): /self/.grid.AutoSizeColumn(col) /self/.grid.EnableEditing(True) /# Set dropdown choices for column 5, row 0/ ? ? types /=/["Sq In", "Sq Cm", "Sq Mm"] /self/.type_dropdown /=/wx.ComboBox(/self/.grid, choices/=/types, style/=/wx.CB_DROPDOWN/|/wx.CB_READONLY) /self/.type_editor /=/wx.grid.GridCellChoiceEditor(choices/=/types) /self/.grid.SetCellEditor(0, 5, /self/.type_editor) /self/.grid.SetCellRenderer(0, 5, wx.grid.GridCellAutoWrapStringRenderer()) /# Set initial value for Type column/ /self/.grid.SetCellValue(0, 5, types[0]) /# Make Total and Grand Total cells read-only/ /for/i /in/range(/self/.grid.GetNumberRows()): /self/.grid.SetReadOnly(i, 2) /self/.grid.SetReadOnly(i, 3) /# Set Type column values/ /self/.grid.SetCellValue(0, 4, "Sq In") /self/.grid.SetCellValue(1, 4, "Sq Cm") /self/.grid.SetCellValue(2, 4, "Sq Mm") /# Populate grid with data from LeatherSqIn object/ /for/i, row /in/enumerate(/self/.ls.get_data()): /for/j, val /in/enumerate(row): /self/.grid.SetCellValue(i, j, str(val)) /if/j /==/0: /# Check if first column/ /self/.grid.SetCellValue(i, j/+/1, "Sq In") /# Set default value for column 2/ /if/i /==/0/and/j /==/5: /self/.grid.SetCellEditor(i, j, wx.grid.GridCellChoiceEditor(choices/=/["Sq In", "Sq Cm", "Sq Mm"])) /else/: /self/.grid.SetCellValue(i, j, str(val)) /# Calculate totals and grand total/ /for/i, row /in/enumerate(/self/.ls.get_data()): /self/.ls.calculate_total(row) ? ? grandTotal /=/0.0 ? ? total /=/0.0 /self/.ls.calculate_grand_total(grandTotal, total) /# Bind events/ /self/.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGED, /self/.OnCellChange) /self/.grid.Bind(wx.EVT_KEY_DOWN, /self/.OnKeyDown) /# Bind the key down event/ /# Add grid and button sizers to top sizer/ ? ? sizer /=/wx.BoxSizer(wx.VERTICAL) ? ? sizer.Add(/self/.grid, 1, wx.ALL) /self/.SetSizer(sizer) /# Set grid line width for last column to 0/ /self/.grid.SetCellHighlightPenWidth(0) /# Set grid cursor and focus/ /# Select cell R0C0 and set focus/ ? ? wx.CallAfter(/self/.grid.SetGridCursor, 0, 0) ? ? wx.CallAfter(/self/.grid.MakeCellVisible, 0, 0) ? ? wx.CallAfter(/self/.grid.SetFocus) /def//OnCellChange/(self, event): print("OnCellChange called") ? ? row, col /=/event.GetRow(), event.GetCol() ? ? value /=//self/.grid.GetCellValue(row, col) /# update total for the row/ /if/col /==/0/or/col /==/1: /try/: /self/.grid.SetCellValue(row, 2, /f/'{/self/.ls.calc_sqin(float(/self/.grid.GetCellValue(row, 0)), float(/self/.grid.GetCellValue(row, 1)))}') /except/ValueError: /pass/ /# update grand total/ ? ? grandTotal /=/0.0 /for/row /in/range(1, /self/.grid.GetNumberRows()): /try/: ? ? ? ? ? ? grandTotal /=//self/.ls.calculate_grand_total(grandTotal, /self/.grid.GetCellValue(row, 2)) /except/ValueError: /pass/ /self/.grid.SetCellValue(0, 3, /f/'{grandTotal/:.2f/}') /# handle key events/ /if/isinstance(event, wx.grid.GridEvent) /and/event.GetEventType() /==/wx.EVT_KEY_DOWN: print("Key event captured") print(event) ? ? ? ? keycode /=/event.GetKeyCode() /if/keycode /==/wx.WXK_TAB: print("OnCellChange:TAB called") /if/col /==/0: /if/event.ShiftDown(): /self/.grid.SetGridCursor(row, col/-/1) /else/: /self/.grid.SetGridCursor(row, col/+/1) /else/: /self/.grid.SetGridCursor(row/+/1, 0) /elif/keycode /==/wx.WXK_RETURN: print("OnCellChange:Enter called") /self/.grid.SetGridCursor(row/+/1, 0) /# update dropdown options for type column/ /if/col /==/5/and/row /==/0: /# update the total and grand total when the dropdown is changed/ /try/: ? ? ? ? ? ? length /=/float(/self/.grid.GetCellValue(row, 0)) ? ? ? ? ? ? width /=/float(/self/.grid.GetCellValue(row, 1)) ? ? ? ? ? ? type_ /=//self/.grid.GetCellValue(row, 5) ? ? ? ? ? ? sqin /=//self/.ls.calc_sqin(length, width, type_) /self/.grid.SetCellValue(row, 2, /f/'{sqin/:.2f/}') ? ? ? ? ? ? grandTotal /=/0.0 /for/row /in/range(1, /self/.grid.GetNumberRows()): /try/: ? ? ? ? ? ? ? ? ? ? grandTotal /=//self/.ls.calculate_grand_total(grandTotal, /self/.grid.GetCellValue(row, 2)) /except/ValueError: /pass/ /self/.grid.SetCellValue(0, 3, /f/'{grandTotal/:.2f/}') /except/ValueError: /pass/ /def//OnClearButtonClick/(self, event): /self/.grid.ClearGrid() /def//OnKeyDown/(self, event): print("Key was hit") ? ? keyCode /=/event.GetKeyCode() ? ? row, col /=//self/.grid.GetGridCursorRow(), /self/.grid.GetGridCursorCol() /if/keyCode /==/wx.WXK_RETURN: /# If ENTER is pressed, move to next row, column 0/ /if/row / References: <640b6509.020a0220.2b13.05db@mx.google.com> Message-ID: This is the implementation of cmd.Cmd (Python 3.9). As you can see in cmdloop(), the import is already wrapped, and the readline feature can be turned off explicitly by passing None to the completekey in the constructor. def __init__(self, completekey='tab', stdin=None, stdout=None): """Instantiate a line-oriented interpreter framework. The optional argument 'completekey' is the readline name of a completion key; it defaults to the Tab key. If completekey is not None and the readline module is available, command completion is done automatically. The optional arguments stdin and stdout specify alternate input and output file objects; if not specified, sys.stdin and sys.stdout are used. """ if stdin is not None: self.stdin = stdin else: self.stdin = sys.stdin if stdout is not None: self.stdout = stdout else: self.stdout = sys.stdout self.cmdqueue = [] self.completekey = completekey def cmdloop(self, intro=None): """Repeatedly issue a prompt, accept input, parse an initial prefix off the received input, and dispatch to action methods, passing them the remainder of the line as argument. """ self.preloop() if self.use_rawinput and self.completekey: try: import readline self.old_completer = readline.get_completer() readline.set_completer(self.complete) readline.parse_and_bind(self.completekey+": complete") except ImportError: pass From: Python-list on behalf of Cameron Simpson Date: Friday, March 10, 2023 at 5:15 PM To: python-list at python.org Subject: Re: Baffled by readline module *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** On 10Mar2023 09:12, Grant Edwards wrote: >On 2023-03-10, Weatherby,Gerard wrote: >> On our Linux systems, I can up-arrow to go back to prior commands >> and use the left and right arrows to navigate a line. The >> functionality may be provided internally by readline. I?ve never had >> to dig into it because it meets my needs out of the box. > >Apparently the cmd.Cmd docs are wrong. It says: > > If the readline module is loaded, input will automatically > inherit bash-like history-list editing (e.g. Control-P scrolls > back to the last command, Control-N forward to the next one, > Control-F moves the cursor to the right non-destructively, > Control-B moves the cursor to the left non-destructively, etc.). > >On my Python 3.10.10 Linux system, cmd.Com itself is importing the >readline module unconditionally when I call cmdloop(). There's no 'if' >about it. I was wondering about that myself, whether this is an accident of phrasing. It doesn't say "is imported", so maybe the author was thinking "if readline's part of the install" here. Anyway, I've got a try/import-readline/except-importerror/pass in my cmd.Cmd wrapper, because I read this the way you read it. Cheers, Cameron Simpson -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!jjJFSxKkzPwZf_NLr44bZNCgMKRu0CPwvbh-jItjkqH_B2mJzTCW4ijlNHg8ysJpyMcCbaaa0Prf5SI$ From cs at cskk.id.au Fri Mar 10 19:57:42 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 11 Mar 2023 11:57:42 +1100 Subject: Baffled by readline module In-Reply-To: References: Message-ID: On 10Mar2023 23:11, Weatherby,Gerard wrote: >This is the implementation of cmd.Cmd (Python 3.9). As you can see in cmdloop(), the import is already wrapped, and the readline feature can be turned off explicitly by passing None to the completekey in the constructor. This isn't strictly true, as I read it. This says that if you supply a `completekey`, _then_ `cmdloop` will try to import `readline` and set up working completion for that key. It _doesn't_ say that readline is or is not automatically active for its other features (command line editing, history etc). Having a gander further down the `cmdloop` function we see: while not stop: if self.cmdqueue: line = self.cmdqueue.pop(0) else: if self.use_rawinput: try: line = input(self.prompt) except EOFError: line = 'EOF' and on a Python 3.10 here we see: >>> help(input) Help on built-in function input in module builtins: input(prompt=None, /) Read a string from standard input. The trailing newline is stripped. The prompt string, if given, is printed to standard output without a trailing newline before reading input. If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError. On *nix systems, readline is used if available. which says to me that readline is used if available, regardless of whether it is already imported. Cheers, Cameron Simpson From aapost at idontexist.club Fri Mar 10 18:46:40 2023 From: aapost at idontexist.club (aapost) Date: Fri, 10 Mar 2023 18:46:40 -0500 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: <4e82452b-23fc-8d30-6f21-268aabd7d623@tompassin.net> Message-ID: On 3/9/23 15:25, Thomas Passin wrote: > >>> # this is a code snippet from a Tkinter gui app > >>> # in this case lambda is quite convenient > >>> self.btn_cancel = Button(self.progress_container, text='Cancel', > >>>???? command=lambda: subprocess.call('taskkill /f /im uberzip.exe', > >>>???? shell=True)) > def kill_uberzip(): > ??? """Kill an external running program named uberzip.exe.""" > ??? subprocess.call('taskkill /f /im uberzip.exe', shell=True)) > > self.btn_cancel = Button(self.progress_container, text='Cancel', > ???? command = kill_uberzip()) > > This way, it's easy to understand what btn_cancel() will do each time > you scan that line of code.? Using the lambda makes you reparse the line > and spend mental effort each time you scan it.? And this way, you know > directly that the button is going to cause a side effect outside your > program, which you have to infer (an indirect mental operation) when you > scan the lambda. > > For this particular example, it might turn out that there could be more > than one instance of uberzip.exe running at the same time.? Which one > should be killed, and how do you kill the right one?? With the function, > you can get those details under control, but I hate to think what might > happen to the lambda expression. > > Yes, of course, there can be times when the lambda expression is > somewhat easy to understand and the side effects are harmless.? In that > case, it may be easy enough to grasp quickly that the anonymous function > would not benefit from having a name.? So OK, it's not a hard-and-fast > rule. The not knowing which uberzip to kill is a design choice, the bad design of the the example is not really the fault of the lambda. And in general with naming anything, much has to do with context. Buttons perform actions, it should be implicitly understood at the button level and in context of where it is placed what it is a button is for. A button without a command has no use, so it is understood it needs to do something, with good design it would be better to know what the buttons purpose is, rather than having to then parse an additional function to figure it out. Case in point, to solve the subprocess problem, (ignoring the "whys" and the lack of usefulness of this example, just grok the pattern, maybe you are designing a game of whack-a-mole and are watching 4 things and need to do something when you see a change from 1 of them) import tkinter as tk import subprocess main = tk.Tk() main.pids = { "messages": None, "syslog": None, "kern": None, "user": None, } tk.Button( master=main, text="Start tailing logs", command=lambda: ( main.pids.update({"messages" :subprocess.Popen(["tail", "-n", "1", "-f", "/var/log/messages"])}), main.pids.update({"syslog" :subprocess.Popen(["tail", "-n", "1", "-f", "/var/log/syslog"])}), main.pids.update({"kern" :subprocess.Popen(["tail", "-n", "1", "-f", "/var/log/kern.log"])}), main.pids.update({"user" :subprocess.Popen(["tail", "-n", "1", "-f", "/var/log/user.log"])}), ), ).pack() tk.Button( master=main, text="Kill messages tail", command=lambda: ( main.pids["messages"].kill() if main.pids["messages"] else None, ), ).pack() tk.Button( master=main, text="Kill syslog tail", command=lambda: ( main.pids["syslog"].kill() if main.pids["syslog"] else None, ), ).pack() tk.Button( master=main, text="Kill kern tail", command=lambda: ( main.pids["kern"].kill() if main.pids["kern"] else None, ), ).pack() tk.Button( master=main, text="Kill user tail", command=lambda: ( main.pids["user"].kill() if main.pids["user"] else None, ), ).pack() tk.Button( master=main, text="Kill all tails", command=lambda: ( main.pids["messages"].kill() if main.pids["messages"] else None, main.pids["syslog"].kill() if main.pids["syslog"] else None, main.pids["kern"].kill() if main.pids["kern"] else None, main.pids["user"].kill() if main.pids["user"] else None, ), ).pack() main.mainloop() From aapost at idontexist.club Fri Mar 10 19:07:12 2023 From: aapost at idontexist.club (aapost) Date: Fri, 10 Mar 2023 19:07:12 -0500 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: <4e82452b-23fc-8d30-6f21-268aabd7d623@tompassin.net> Message-ID: On 3/10/23 18:46, aapost wrote: > ??????? main.pids.update({"messages" :subprocess.Popen(["tail", "-n", > "1", "-f", "/var/log/messages"])}), > ??????? main.pids.update({"syslog" :subprocess.Popen(["tail", "-n", > "1", "-f", "/var/log/syslog"])}), > ??????? main.pids.update({"kern" :subprocess.Popen(["tail", "-n", "1", > "-f", "/var/log/kern.log"])}), > ??????? main.pids.update({"user" :subprocess.Popen(["tail", "-n", "1", > "-f", "/var/log/user.log"])}), > ????), To pre-emptively address the bug there it would need to be: main.pids.update({"messages" :subprocess.Popen(["tail", "-n", "1", "-f", "/var/log/messages"])}) if not main.pids["messages"] else None, main.pids.update({"syslog" :subprocess.Popen(["tail", "-n", "1", "-f", "/var/log/syslog"])}) if not main.pids["syslog"] else None, main.pids.update({"kern" :subprocess.Popen(["tail", "-n", "1", "-f", "/var/log/kern.log"])}) if not main.pids["kern"] else None, main.pids.update({"user" :subprocess.Popen(["tail", "-n", "1", "-f", "/var/log/user.log"])}) if not main.pids["user"] else None, which does start to break down readability due to line length, as there isn't really an indention rule set for something uncommonly used. but some renaming makes the pattern clearer pids.update({"messages" :subprocess.Popen(["cmd1"])}) if not pids["messages"] else None, pids.update({"syslog" :subprocess.Popen(["cmd2"])}) if not pids["syslog"] else None, pids.update({"kern" :subprocess.Popen(["cmd3"])}) if not pids["kern"] else None, pids.update({"user" :subprocess.Popen(["cmd4"])}) if not pids["user"] else None, and adding a comment to say something like # starting a series of processes via lambda tuple sequence if process not running #pattern: p.update({"name":sp.Popen(cmd)}) if not p["name"] else None, From VASKOTechDesign at outlook.com Fri Mar 10 18:27:50 2023 From: VASKOTechDesign at outlook.com (Jan Vasko) Date: Fri, 10 Mar 2023 23:27:50 +0000 Subject: Python installation not full and python not working 3.11.0 In-Reply-To: References: Message-ID: Hello all, I would like to ask you for help. I have been using Python 3.8 for almost 2 years and I decided to update to 3.11. Initially everything was correct. But at some point Windows shows me that Python is being reinstalled (I don't have a message print screen ..), but from that time I cannot run Python at all on my PC. So I tried to reinstall it several times with no success. All the time I receive this "The system cannot find the file C:\Users...\AppData\Local\Programs\Python\Python311\python.exe." But files are there: [cid:image001.png at 01D953B0.4E12E170] Even when I try to run "python.exe" directly I receive this error: [cid:image002.png at 01D953B0.4E12E170] System Variables are right (added it to both PATH): 1) User Variables: [cid:image003.png at 01D953B0.4E12E170] 2) System Variables [cid:image004.png at 01D953B0.4E12E170] Strange thing is that after RE-Installing Python the "pip.exe" is missing in subfolder "Python/Scripts/" (it is simply empty - not installed but I mark pip to be installed): [cid:image005.png at 01D953B0.4E12E170] I tried also Repair - no success. Details: System: Windows 10 (21H2) Python: 3.11.0 (full 64bit installer from python.org) * Downloaded from: Python Release Python 3.11.0 | Python.org cmd: [cid:image006.png at 01D953B0.4E12E170] This is resulting that I cannot use interpreter in VS Code and continue development. Any one Any Idea? Thank you S pozdravem Jan Va?ko From list1 at tompassin.net Fri Mar 10 21:51:53 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 10 Mar 2023 21:51:53 -0500 Subject: Python installation not full and python not working 3.11.0 In-Reply-To: References: Message-ID: <3fb5bb2f-bca7-4a87-2bf9-73bf1bc5307c@tompassin.net> On 3/10/2023 6:27 PM, Jan Vasko wrote: Please note that you can't attach images in these posts, at least not so we can read them. Instead, copy the messages from the console and paste them into your post. I suggest that you check to make sure that your system hasn't been damaged or corrupted - just to make sure. You can check it and have Windows restore any of the OS files if they have been damaged. If everything is OK, then that would remove one potential issue, so it's worth doing. It may take some time, but it's worth doing. Here's what to do. First, open a console with administrative privileges - the easiest way is to press and choose "Command Prompt (Admin). In the console, run dism /Online /Cleanup-Image /ScanHealth (see https://www.dell.com/support/kbdoc/en-us/000122035/how-to-use-the-deployment-image-servicing-and-management-tool-dism-to-repair-the-windows-system-store) If repairable problems are found, then run: dism /Online /Cleanup-Image /RestoreHealth Finally follow up by running sfc /scannow sfc can also repair some errors, and some people run it first, but I have read that it's more useful to run Dism first. If any errors were found and corrected, reboot and try to uninstall Python3.11, then re-install it. If no errors were found, report that back here and we'll try to go on from there. > I would like to ask you for help. I have been using Python 3.8 for almost 2 years and I decided to update to 3.11. Initially everything was correct. But at some point Windows shows me that Python is being reinstalled (I don't have a message print screen ..), but from that time I cannot run Python at all on my PC. > > So I tried to reinstall it several times with no success. All the time I receive this "The system cannot find the file C:\Users...\AppData\Local\Programs\Python\Python311\python.exe." > But files are there: > [cid:image001.png at 01D953B0.4E12E170] > Even when I try to run "python.exe" directly I receive this error: > [cid:image002.png at 01D953B0.4E12E170] > > System Variables are right (added it to both PATH): > 1) User Variables: > [cid:image003.png at 01D953B0.4E12E170] > > 2) System Variables > [cid:image004.png at 01D953B0.4E12E170] > > Strange thing is that after RE-Installing Python the "pip.exe" is missing in subfolder "Python/Scripts/" (it is simply empty - not installed but I mark pip to be installed): > [cid:image005.png at 01D953B0.4E12E170] > > I tried also Repair - no success. > > Details: > System: Windows 10 (21H2) > Python: 3.11.0 (full 64bit installer from python.org) > > * Downloaded from: Python Release Python 3.11.0 | Python.org > > cmd: > [cid:image006.png at 01D953B0.4E12E170] > > This is resulting that I cannot use interpreter in VS Code and continue development. Any one Any Idea? Thank you > > S pozdravem > > Jan Va?ko > From python at mrabarnett.plus.com Fri Mar 10 21:54:00 2023 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 11 Mar 2023 02:54:00 +0000 Subject: Python installation not full and python not working 3.11.0 In-Reply-To: References: Message-ID: <93d75975-c1aa-423a-9a7a-60c663cb14e3@mrabarnett.plus.com> On 2023-03-10 23:27, Jan Vasko wrote: > Hello all, > > > I would like to ask you for help. I have been using Python 3.8 for almost 2 years and I decided to update to 3.11. Initially everything was correct. But at some point Windows shows me that Python is being reinstalled (I don't have a message print screen ..), but from that time I cannot run Python at all on my PC. > > So I tried to reinstall it several times with no success. All the time I receive this "The system cannot find the file C:\Users...\AppData\Local\Programs\Python\Python311\python.exe." > But files are there: > [cid:image001.png at 01D953B0.4E12E170] > Even when I try to run "python.exe" directly I receive this error: > [cid:image002.png at 01D953B0.4E12E170] > > System Variables are right (added it to both PATH): > 1) User Variables: > [cid:image003.png at 01D953B0.4E12E170] > > 2) System Variables > [cid:image004.png at 01D953B0.4E12E170] > > Strange thing is that after RE-Installing Python the "pip.exe" is missing in subfolder "Python/Scripts/" (it is simply empty - not installed but I mark pip to be installed): > [cid:image005.png at 01D953B0.4E12E170] > > I tried also Repair - no success. > > Details: > System: Windows 10 (21H2) > Python: 3.11.0 (full 64bit installer from python.org) > > * Downloaded from: Python Release Python 3.11.0 | Python.org > > cmd: > [cid:image006.png at 01D953B0.4E12E170] > > This is resulting that I cannot use interpreter in VS Code and continue development. Any one Any Idea? Thank you > This list is text-only; images are automatically stripped. Please copy and paste any relevant text that they might contain. From list1 at tompassin.net Fri Mar 10 22:16:05 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 10 Mar 2023 22:16:05 -0500 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: <4e82452b-23fc-8d30-6f21-268aabd7d623@tompassin.net> Message-ID: <936687d2-9ddd-61ff-e5f9-9abbb6a042e1@tompassin.net> On 3/10/2023 7:07 PM, aapost wrote: > which does start to break down readability due to line length, as there > isn't really an indention rule set for something uncommonly used. > > but some renaming makes the pattern clearer > > pids.update({"messages" :subprocess.Popen(["cmd1"])}) if not > pids["messages"] else None, > pids.update({"syslog" :subprocess.Popen(["cmd2"])}) if not > pids["syslog"] else None, > pids.update({"kern" :subprocess.Popen(["cmd3"])}) if not pids["kern"] > else None, > pids.update({"user" :subprocess.Popen(["cmd4"])}) if not pids["user"] > else None, I'd make the pattern in this example even more understandable and less error-prone: def update_pids(target): cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] pids.update({target: subprocess.Popen(cmd)}) if not \ pids[target] else None lambda x: ( # The Tk callback includes an event arg, doesn't it? update_pids('messages'), update_pids('syslog'), # etc ) From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Mar 10 22:37:43 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Fri, 10 Mar 2023 21:37:43 -0600 Subject: Lambda returning tuple question, multi-expression In-Reply-To: <936687d2-9ddd-61ff-e5f9-9abbb6a042e1@tompassin.net> References: <4e82452b-23fc-8d30-6f21-268aabd7d623@tompassin.net> <936687d2-9ddd-61ff-e5f9-9abbb6a042e1@tompassin.net> Message-ID: On 2023-03-10 at 22:16:05 -0500, Thomas Passin wrote: > I'd make the pattern in this example even more understandable and less > error-prone: > > def update_pids(target): > cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] > pids.update({target: subprocess.Popen(cmd)}) if not \ > pids[target] else None I might be missing something, but how is that more understandable and less error prone than any of the following: if not pids[target]: cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] pids.update({target: subprocess.Popen(cmd)}) or: cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] pids[target] or pids.update({target: subprocess.Popen(cmd)}) or: if pids[target]: pass else: cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] pids.update({target: subprocess.Popen(cmd)}) Picking a nit, that's not a good place to continue that line with the backslash, either. IMO, "not pids[target]" should be atomic. From list1 at tompassin.net Fri Mar 10 22:32:55 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 10 Mar 2023 22:32:55 -0500 Subject: Python installation not full and python not working 3.11.0 In-Reply-To: <3fb5bb2f-bca7-4a87-2bf9-73bf1bc5307c@tompassin.net> References: <3fb5bb2f-bca7-4a87-2bf9-73bf1bc5307c@tompassin.net> Message-ID: <70d3215f-2c74-aa10-f92f-94f7eaac8fdf@tompassin.net> On 3/10/2023 9:51 PM, Thomas Passin wrote: > On 3/10/2023 6:27 PM, Jan Vasko wrote: > > Please note that you can't attach images in these posts, at least not so > we can read them.? Instead, copy the messages from the console and paste > them into your post. > > I suggest that you check to make sure that your system hasn't been > damaged or corrupted - just to make sure.? You can check it and have > Windows restore any of the OS files if they have been damaged.? If > everything is OK, then that would remove one potential issue, so it's > worth doing.? It may take some time, but it's worth doing. > > Here's what to do. First, open a console with administrative privileges > - the easiest way is to press and choose "Command Prompt > (Admin).? In the console, run > > dism /Online /Cleanup-Image /ScanHealth > > (see > https://www.dell.com/support/kbdoc/en-us/000122035/how-to-use-the-deployment-image-servicing-and-management-tool-dism-to-repair-the-windows-system-store) > > If repairable problems are found, then run: > > dism /Online /Cleanup-Image /RestoreHealth > > Finally follow up by running > > sfc /scannow > > sfc can also repair some errors, and some people run it first, but I > have read that it's more useful to run Dism first. > > If any errors were found and corrected, reboot and try to uninstall > Python3.11, then re-install it. > > If no errors were found, report that back here and we'll try to go on > from there. If it were me, the next thing I'd try is to install Python 3.10.x. I'd get a 64-bit installer from python.org. Yes, I know you want to install 3.11, but this way will give you a clean, fresh installer to try. If the installation succeeds, it would be a good data point and also give you a (somewhat) updated version of Python on your system. >> I would like to ask you for help. I have been using Python 3.8 for >> almost 2 years and I decided to update to 3.11. Initially everything >> was correct. But at some point Windows shows me that Python is being >> reinstalled (I don't have a message print screen ..), but from that >> time I cannot run Python at all on my PC. >> >> So I tried to reinstall it several times with no success. All the time >> I receive this "The system cannot find the file >> C:\Users...\AppData\Local\Programs\Python\Python311\python.exe." >> But files are there: >> [cid:image001.png at 01D953B0.4E12E170] >> Even when I try to run "python.exe" directly I receive this error: >> [cid:image002.png at 01D953B0.4E12E170] >> >> System Variables are right (added it to both PATH): >> 1) User Variables: >> [cid:image003.png at 01D953B0.4E12E170] >> >> 2) System Variables >> [cid:image004.png at 01D953B0.4E12E170] >> >> Strange thing is that after RE-Installing Python the "pip.exe" is >> missing in subfolder "Python/Scripts/" (it is simply empty - not >> installed but I mark pip to be installed): >> [cid:image005.png at 01D953B0.4E12E170] >> >> I tried also Repair - no success. >> >> Details: >> System: Windows 10 (21H2) >> Python: 3.11.0 (full 64bit installer from python.org) >> >> ?? *?? Downloaded from: Python Release Python 3.11.0 | >> Python.org >> >> cmd: >> [cid:image006.png at 01D953B0.4E12E170] >> >> This is resulting that I cannot use interpreter in VS Code and >> continue development. Any one Any Idea? Thank you >> >> S pozdravem >> >> Jan Va?ko >> > From list1 at tompassin.net Fri Mar 10 23:10:47 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 10 Mar 2023 23:10:47 -0500 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: <4e82452b-23fc-8d30-6f21-268aabd7d623@tompassin.net> <936687d2-9ddd-61ff-e5f9-9abbb6a042e1@tompassin.net> Message-ID: <7a3bc6f9-fb4b-02e4-fca6-821143b27d80@tompassin.net> On 3/10/2023 10:37 PM, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > On 2023-03-10 at 22:16:05 -0500, > Thomas Passin wrote: > >> I'd make the pattern in this example even more understandable and less >> error-prone: >> >> def update_pids(target): >> cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] >> pids.update({target: subprocess.Popen(cmd)}) if not \ >> pids[target] else None > > I might be missing something, but how is that more understandable and > less error prone than any of the following: The main point is that there can be an easy-to-read and easy-to-understand expression to use in the lambda. I don't care about the exact details here. The command wasn't even mine. But you only have to scan it and grasp it once, in the def:, and then only until you get it working. In the lambda, my suggestions makes it much easier to understand what the lambda is expected to do - and it will still be clear in three months when the code gets revisited. > if not pids[target]: > cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] > pids.update({target: subprocess.Popen(cmd)}) > > or: > > cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] > pids[target] or pids.update({target: subprocess.Popen(cmd)}) > > or: > > if pids[target]: > pass > else: > cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] > pids.update({target: subprocess.Popen(cmd)}) > > Picking a nit, that's not a good place to continue that line with the > backslash, either. I only continued the line for the purposes of the post because it would have gotten line wrapped otherwise. If it were my code in a real module I would probably have treated it differently. > IMO, "not pids[target]" should be atomic. Again, it wasn't my code. I don't even know if the code fragments would actually work - they were presented as illustrative examples by the OP. And anyway, these nits obscure the point of my post. In a nutshell, it is to use good naming and encapsulation to make your code as close to self-documenting and as error-free as is reasonably possible, whenever you can. Good function names are only one step towards this goal. Lambdas often work against this goal, so it's worthwhile spending some effort to see how to counteract this tendency. And it's a goal. You can never meet it 100%. That's OK. There will always be a matter of taste involved. That's OK too. It's still a worthwhile goal. From aapost at idontexist.club Fri Mar 10 23:15:56 2023 From: aapost at idontexist.club (aapost) Date: Fri, 10 Mar 2023 23:15:56 -0500 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: <4e82452b-23fc-8d30-6f21-268aabd7d623@tompassin.net> <936687d2-9ddd-61ff-e5f9-9abbb6a042e1@tompassin.net> Message-ID: On 3/10/23 22:16, Thomas Passin wrote: > On 3/10/2023 7:07 PM, aapost wrote: >> which does start to break down readability due to line length, as >> there isn't really an indention rule set for something uncommonly used. >> >> but some renaming makes the pattern clearer >> >> pids.update({"messages" :subprocess.Popen(["cmd1"])}) if not >> pids["messages"] else None, >> pids.update({"syslog" :subprocess.Popen(["cmd2"])}) if not >> pids["syslog"] else None, >> pids.update({"kern" :subprocess.Popen(["cmd3"])}) if not pids["kern"] >> else None, >> pids.update({"user" :subprocess.Popen(["cmd4"])}) if not pids["user"] >> else None, > > I'd make the pattern in this example even more understandable and less > error-prone: > > def update_pids(target): > ??? cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] > ??? pids.update({target: subprocess.Popen(cmd)}) if not \ > ??????? pids[target] else None > > lambda x: ( # The Tk callback includes an event arg, doesn't it? > ??????????? update_pids('messages'), > ??????????? update_pids('syslog'), > ??????????? # etc > ????????? ) > So yeah, that's along the same lines. cmd could be in a function, or just outside the lambdas. Could also do from subprocess import Popen to shorten that, etc. The .trace( on the tkinter Vars use events, so you have to do something like lambda _a, _b, _c: stuff But not in the above case. My focus these last couple week hasn't used any of those so the specifics aren't as fresh (still heading back in that direction), when required python will definitely let you know, lol. The additional note in the above is, when taking the def route above, the thing you would have to consider is what scope is the dictionary pids? Do you need to submit it to the lambda and subsequently the function such as lambda pids=pids: ( update_pids("messages", pids), update_pids("syslog", pids), So that update_pids can access it? Or in your design do you have a separate management of it that def update_pids already has access to? (either is valid depending on design intent). In the direction I am going, in trying to build some compound widgets, and I need to grab stuff from one widget and send it to another within the same widget group, so in cases where it goes to an external function, it has to be sent as an arg through the lambda whatever=whatever: ( function(whatever), ) From list1 at tompassin.net Sat Mar 11 00:45:01 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 11 Mar 2023 00:45:01 -0500 Subject: Lambda returning tuple question, multi-expression In-Reply-To: References: <4e82452b-23fc-8d30-6f21-268aabd7d623@tompassin.net> <936687d2-9ddd-61ff-e5f9-9abbb6a042e1@tompassin.net> Message-ID: <48f10b33-8f88-442d-52a9-408145417495@tompassin.net> On 3/10/2023 11:15 PM, aapost wrote: > On 3/10/23 22:16, Thomas Passin wrote: [...] > The additional note in the above is, when taking the def route above, > the thing you would have to consider is what scope is the dictionary pids? > > Do you need to submit it to the lambda and subsequently the function > such as > lambda pids=pids: ( > ??? update_pids("messages", pids), > ??? update_pids("syslog", pids), > > So that update_pids can access it? Or in your design do you have a > separate management of it that def update_pids already has access to? > (either is valid depending on design intent). It's easy enough to try out. I'm not going to simulate the dictionary, because it's basically just another argument, and I assume that your example code uses it because it needs to be in that form. For the scope question, see below after the basic example. >>> def printme(x): print(x) # Let's not quibble about inline defs! >>> printme('xxx') xxx >>> cmd = lambda x: ( ... printme('this'), ... printme('is'), ... printme('a test') ... ) (Yes, I know it's not recommended to assign a lambda to a variable name, but I'm doing it here just to demonstrate that the lambda works as desired). >>> cmd(2) this is a test (None, None, None) So it executes the intended steps and returns a tuple of three None values, as expected. When used as the target of the "command" arg in the Tk control constructor, I presume the tuple would be ignored just as a return of None would be. But that would need to be tested. If returning a tuple instead of None were to cause a problem, you could do this: cmd = lambda x: ( printme('this'), printme('is'), printme('a test') ) and None >>> cmd(2) this is a test But now you are introducing a construct whose purpose is not totally obvious, does not cause any intended effect, and in fact is only required by the nature of the code receiving the callback, which you cannot know by reading this code. So if this construct turns out to be needed, we're forced to take a step away from having the code be as direct and understandable as possible. It's still better in that way than the earlier illustrations (which BTW would also have required the "and None" construct). To test out the scope question: >>> def printme(x): print(y) # Print some other variable, not "x" >>> y = 'I am y' # Will "y" get passed through into the lambda? >>> cmd = lambda x: ( ... printme('this'), ... printme('is'), ... printme('a test') ... ) and None >>> cmd(2) I am y I am y I am y But maybe the original value of "y" gets baked in at compile time. Let's see: >>> y = 'I am a post-compile assignment' >>> cmd(2) I am a post-compile assignment I am a post-compile assignment I am a post-compile assignment Good, the current value of "y" gets used. From manta103g at gmail.com Sat Mar 11 18:54:08 2023 From: manta103g at gmail.com (a a) Date: Sat, 11 Mar 2023 15:54:08 -0800 (PST) Subject: Can you process seismographic signals in Python or should I switch to Matlab ? Message-ID: My project https://www.mathworks.com/help/matlab/matlab_prog/loma-prieta-earthquake.html From avi.e.gross at gmail.com Sat Mar 11 23:36:08 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 11 Mar 2023 23:36:08 -0500 Subject: Can you process seismographic signals in Python or should I switch to Matlab ? In-Reply-To: References: Message-ID: <000b01d9549c$2abe0d70$803a2850$@gmail.com> A a, Consider asking a more specific question. Many things can be done in many different programming languages. Are you asking if there are helpers you can use such as modules that implement parts of the algorithms you need? Are you asking about speed or efficiency? Have you considered how few people here are likely to know much about a specialized field and perhaps a search using a search engine might get you something like this: https://www.google.com/search?q=python+process+seimographic+signals&oq=pytho n+process+seimographic+signals&aqs=chrome..69i57j0i546l5.16718j0j7&sourceid= chrome&ie=UTF-8 For example: https://www.geophysik.uni-muenchen.de/~megies/www_obsrise/ You can of course search for say signal processing or whatever makes sense to you. My answer, if not clear, is that your question may not be primarily about Python and about finding whatever environment gives you both access to software that helps you as well as a language that lets you wrap lots of it together, make reports and so on. Python is likely a decent choice but perhaps others are better for your own situation, such as having others nearby you can learn from. Good luck. -----Original Message----- From: Python-list On Behalf Of a a Sent: Saturday, March 11, 2023 6:54 PM To: python-list at python.org Subject: Can you process seismographic signals in Python or should I switch to Matlab ? My project https://www.mathworks.com/help/matlab/matlab_prog/loma-prieta-earthquake.htm l -- https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Sun Mar 12 00:02:11 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 12 Mar 2023 00:02:11 -0500 Subject: Can you process seismographic signals in Python or should I switch to Matlab ? In-Reply-To: References: Message-ID: <5dc020b7-d996-23b7-f666-242476ea2178@tompassin.net> On 3/11/2023 6:54 PM, a a wrote: > My project > https://www.mathworks.com/help/matlab/matlab_prog/loma-prieta-earthquake.html If your goal is to step through this Matlab example, then clearly you should use Matlab. If you do not have access to Matlab or cannot afford it, then you would have to use something else, and Python would be a prime candidate. However, each of the techniques and graphs in the lesson have been pre-packaged for you in the Matlab case but not with Python (many other case studies on various topics that use Python Python can be found, though). Everything in the Matlab analysis can be done with Python and associated libraries. You would have to learn various processing and graphing techniques. You would also have to get the data from somewhere. It's prepackaged for this analysis and you would have to figure out where to get it. There is at least one Python package that can read and convert Matlab files - I do not remember its name, though. A more important question is whether doing the Matlab example prepares you to do any other analyses on your own. To shed some light on this, here is a post on some rather more advanced analysis using data on the same earthquake, done with Python tools - https://towardsdatascience.com/earthquake-time-series-forecasts-using-a-hybrid-clustering-lstm-approach-part-i-eda-6797b22aed8c From avi.e.gross at gmail.com Sun Mar 12 00:17:29 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sun, 12 Mar 2023 00:17:29 -0500 Subject: Can you process seismographic signals in Python or should I switch to Matlab ? In-Reply-To: <5dc020b7-d996-23b7-f666-242476ea2178@tompassin.net> References: <5dc020b7-d996-23b7-f666-242476ea2178@tompassin.net> Message-ID: <001101d954a1$f11085c0$d3319140$@gmail.com> I have used GNU Octave as a sort of replacement for MATLAB as a free resource. I have no idea if it might meet your needs. Although Python is a good environment for many things, if you have no knowledge of it yet, it can take a while to know enough and if you just need it for one project, ... -----Original Message----- From: Python-list On Behalf Of Thomas Passin Sent: Sunday, March 12, 2023 12:02 AM To: python-list at python.org Subject: Re: Can you process seismographic signals in Python or should I switch to Matlab ? On 3/11/2023 6:54 PM, a a wrote: > My project > https://www.mathworks.com/help/matlab/matlab_prog/loma-prieta-earthquake.htm l If your goal is to step through this Matlab example, then clearly you should use Matlab. If you do not have access to Matlab or cannot afford it, then you would have to use something else, and Python would be a prime candidate. However, each of the techniques and graphs in the lesson have been pre-packaged for you in the Matlab case but not with Python (many other case studies on various topics that use Python Python can be found, though). Everything in the Matlab analysis can be done with Python and associated libraries. You would have to learn various processing and graphing techniques. You would also have to get the data from somewhere. It's prepackaged for this analysis and you would have to figure out where to get it. There is at least one Python package that can read and convert Matlab files - I do not remember its name, though. A more important question is whether doing the Matlab example prepares you to do any other analyses on your own. To shed some light on this, here is a post on some rather more advanced analysis using data on the same earthquake, done with Python tools - https://towardsdatascience.com/earthquake-time-series-forecasts-using-a-hybr id-clustering-lstm-approach-part-i-eda-6797b22aed8c -- https://mail.python.org/mailman/listinfo/python-list From aapost at idontexist.club Sun Mar 12 15:48:32 2023 From: aapost at idontexist.club (aapost) Date: Sun, 12 Mar 2023 15:48:32 -0400 Subject: Problem with wxPython form In-Reply-To: References: <694ffeeb-1b2e-ec70-76df-579445cc0364@candp-ent.com> Message-ID: On 3/10/23 15:15, Chris wrote: > Hi everyone. I'm new to Python and wxPython. I've got a form I use to > calculate the Sq In of a leather project. > > I'm using python 3.9.13 and wxPython 4.20 > > I'm having the following issues: > 1) When I come into the form, no grid cell has the focus set - I start > typing and nothing happens. I have to click the cell. > If I hit Tab or Enter, the OnKeyDown fires, but does not move to the > appropriate cell - it does nothing but run the update and move off of > the current cell. > The action I'm trying to make is this > ENTER KEY: Always go down 1 row and to col 0 > TAB, if Col 0 Move to Col 1 on same row, if Col 1 go to Row +1, Col 0 > I also need to have what3ever cell it is supposed to land on to get the > focus so I can just type. > Currently I have to click in each cell I want/need to add. > There could be up to 20 pieces of leather with differing sizes, so in > order to accurately calculate the Sq In, I need to get all the > measurements in. > The form, one of several tabs, comes up and does everything else I've > coded for great. Just no navigation. > Can anyone assist? Here is the module with the form Your source was badly mangled by whatever you submitted it in, so it was very difficult to parse. Additionally, it is usually best to strip your code down to a minimal example of the issue, and remove any references to modules that are likely not publicly available (i.e. alwlogic) (putting basic dummy data in place if need be). That being said: 2 things will likely address your issue, remove self.grid.SetCellHighlightPenWidth(0) since this is making the highlight box of the selected cell invisible, this is preventing you from seeing that your tabs and enters are working as you are expecting. Next, the wx.EVT_KEY_DOWN binding is grabbing all key presses, and your function is only addressing 2 keys, you need to add an else: to the end with an event.Skip() to allow the default behaviors of the grid cells to pass through for other keys (i.e. typing). That should get you the behavior you need. From scruelt at hotmail.com Mon Mar 13 04:59:12 2023 From: scruelt at hotmail.com (scruel tao) Date: Mon, 13 Mar 2023 08:59:12 +0000 Subject: How to exit program with custom code and custom message? Message-ID: Currently, I use `sys.exit([arg])` for exiting program and it works fine. As described in the document: > If another type of object is passed, None is equivalent to passing zero, and any other object is printed to stderr and results in an exit code of 1. However, if I want to exit the program with status 0 (or any numbers else except 1) and print necessary messages before exiting, I have to write: ```python print("message") sys.exit() ``` So why `sys.exit` takes a list of arguments (`[arg]`) as its parameter? Rather than something like `sys.exit(code:int=0, msg:str=None)`? From rosuav at gmail.com Mon Mar 13 05:27:19 2023 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Mar 2023 20:27:19 +1100 Subject: How to exit program with custom code and custom message? In-Reply-To: References: Message-ID: On Mon, 13 Mar 2023 at 20:00, scruel tao wrote: > > Currently, I use `sys.exit([arg])` for exiting program and it works fine. > As described in the document: > > If another type of object is passed, None is equivalent to passing zero, and any other object is printed to stderr and results in an exit code of 1. > > However, if I want to exit the program with status 0 (or any numbers else except 1) and print necessary messages before exiting, I have to write: > ```python > print("message") > sys.exit() > ``` > So why `sys.exit` takes a list of arguments (`[arg]`) as its parameter? Rather than something like `sys.exit(code:int=0, msg:str=None)`? It doesn't actually take a list of arguments; the square brackets indicate that arg is optional here. So you can either quickly print out an error message and exit, or you can exit with any return code you like, but for anything more complicated, just print and then exit. It's worth noting, by the way, that sys.exit("error message") will print that to STDERR, not to STDOUT, which mean that the equivalent is: print("error message", file=sys.stderr) sys.exit(1) Which is another reason to do things differently on success; if you're returning 0, you most likely want your output on STDOUT. ChrisA From scruelt at hotmail.com Mon Mar 13 06:18:26 2023 From: scruelt at hotmail.com (scruel tao) Date: Mon, 13 Mar 2023 10:18:26 +0000 Subject: =?gb2312?B?16q3ojogSG93IHRvIGV4aXQgcHJvZ3JhbSB3aXRoIGN1c3RvbSBjb2RlIGFu?= =?gb2312?Q?d_custom_message=3F?= In-Reply-To: References: Message-ID: Chris: > It doesn't actually take a list of arguments; the square brackets indicate that arg is optional here. Oh, I see, it seems that I mistunderstood the document. > but for anything more complicated, just print and then exit. > It's worth noting, by the way, that sys.exit("error message") will > print that to STDERR, not to STDOUT, which mean that the equivalent > is: Yes, I know, but don?t you think if `sys.exit` can take more parameters and have a default output channel selection strategy will be better? Thanks. From lal at solute.de Mon Mar 13 10:16:34 2023 From: lal at solute.de (Lars Liedtke) Date: Mon, 13 Mar 2023 15:16:34 +0100 Subject: =?UTF-8?B?UmU6IOi9rOWPkTogSG93IHRvIGV4aXQgcHJvZ3JhbSB3aXRoIGN1c3Rv?= =?UTF-8?Q?m_code_and_custom_message=3f?= In-Reply-To: References: Message-ID: I totally understand your reasoning here, but in some way it follows the unix philosophy: Do only one thing, but do that good. And exiting is something different from printing to STDOUT or STDERR. Yes sometimes you want to print something before exiting. But then you should do that explicitly and to the output you want and not implicitly rely on adfdtitional parameters of exit. Yes, not all functions work this way. But that does not mean they shouln't ;-) Cheers Lars On 13.03.23 11:18, scruel tao wrote: Chris: It doesn't actually take a list of arguments; the square brackets indicate that arg is optional here. Oh, I see, it seems that I mistunderstood the document. but for anything more complicated, just print and then exit. It's worth noting, by the way, that sys.exit("error message") will print that to STDERR, not to STDOUT, which mean that the equivalent is: Yes, I know, but don?t you think if `sys.exit` can take more parameters and have a default output channel selection strategy will be better? Thanks. Lars Liedtke Software Entwickler [Tel.] +49 721 98993- [Fax] +49 721 98993- [E-Mail] lal at solute.de solute GmbH Zeppelinstra?e 15 76185 Karlsruhe Germany [Logo Solute] Marken der solute GmbH | brands of solute GmbH [Marken] [Advertising Partner] Gesch?ftsf?hrer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php From manta103g at gmail.com Mon Mar 13 00:39:07 2023 From: manta103g at gmail.com (a a) Date: Sun, 12 Mar 2023 21:39:07 -0700 (PDT) Subject: Can you process seismographic signals in Python or should I switch to Matlab ? In-Reply-To: References: <001101d954a1$f11085c0$d3319140$@gmail.com> <5dc020b7-d996-23b7-f666-242476ea2178@tompassin.net> Message-ID: <6a7323be-e6aa-4fe3-8e1b-87a658b07f8fn@googlegroups.com> On Sunday, 12 March 2023 at 06:17:54 UTC+1, avi.e... at gmail.com wrote: > I have used GNU Octave as a sort of replacement for MATLAB as a free > resource. I have no idea if it might meet your needs. > > Although Python is a good environment for many things, if you have no > knowledge of it yet, it can take a while to know enough and if you just need > it for one project, ... > -----Original Message----- > From: Python-list On > Behalf Of Thomas Passin > Sent: Sunday, March 12, 2023 12:02 AM > To: pytho... at python.org > Subject: Re: Can you process seismographic signals in Python or should I > switch to Matlab ? > On 3/11/2023 6:54 PM, a a wrote: > > My project > > > https://www.mathworks.com/help/matlab/matlab_prog/loma-prieta-earthquake.htm > l > > If your goal is to step through this Matlab example, then clearly you > should use Matlab. If you do not have access to Matlab or cannot afford > it, then you would have to use something else, and Python would be a > prime candidate. However, each of the techniques and graphs in the > lesson have been pre-packaged for you in the Matlab case but not with > Python (many other case studies on various topics that use Python Python > can be found, though). > > Everything in the Matlab analysis can be done with Python and associated > libraries. You would have to learn various processing and graphing > techniques. You would also have to get the data from somewhere. It's > prepackaged for this analysis and you would have to figure out where to > get it. There is at least one Python package that can read and convert > Matlab files - I do not remember its name, though. > > A more important question is whether doing the Matlab example prepares > you to do any other analyses on your own. To shed some light on this, > here is a post on some rather more advanced analysis using data on the > same earthquake, done with Python tools - > > https://towardsdatascience.com/earthquake-time-series-forecasts-using-a-hybr > id-clustering-lstm-approach-part-i-eda-6797b22aed8c > -- > https://mail.python.org/mailman/listinfo/python-list Thank you my dear friends for your kind opinions. Matlab is pro, commercial, paid and demo is available for tests only. So it's hard to dicuss projects, apps in Matlab if cannot be verified by peers. What is hot today is the following 3D plot animation in Matplotlib https://twitter.com/gmrpetricca/status/1633477532526817281 But some unknown reasons Matplotlib and numpy crash my Python 3.8 for Windows , 32-bit and no support is offered Ok, I can read 100 research papers daily, preview hundreds pages of text from search engines. But what I need is analysis of seismograms from 4,000 seismographs world wide to detect P-wave energy distribution underground around the earthquake to verify EQ Domino Effect As you can see below, the Matlab project named in my first submission turned into Python project and EQ energy envelope makes sense. But I would prefer to join 100+ man project in seismology since it may take me months to download seismograms, process seismograms, preview, select features and build EQ energy envelope 3D plots for earthquakes in Turkey alone. To develop another theory, to get data, process data and get results for analysis to verify EQ energy envelope Domino Effect I am afraid there are no team research projects in seismology. What is published and discussed is one-man project. ---- PICOSS: Python Interface for the Classification of Seismic Signals A. Buenoa, L. Zuccarellob,c, A. D ??az-Morenod, J. Woolamd, M. Titosb, L. Garc ??aa, I. ?Alvareza, J. Prudenciob, S. De Angelisd aDepartment of Signal Theory, Telematic and Communications, University of Granada, Spain. bDepartment of Theoretical Physics and Cosmos, University of Granada, Spain. cIstituto Nazionale di Geofisica e Vulcanologia, Sezione di Pisa, Italy dDepartment of Earth, Ocean and Ecological Sciences, University of Liverpool, UK https://core.ac.uk/download/pdf/334413225.pdf seismic-signal https://github.com/topics/seismic-signal STA-LTA Algorithm and Seismometer Trajectory visualization in 3D Tonumoy / STA-LTA-Algorithm-and-Seismometer-Trajectory-visualization-in-3D https://github.com/Tonumoy/STA-LTA-Algorithm-and-Seismometer-Trajectory-visualization-in-3D PICOSS A Python Interface for the Classification of Seismic Signals. PICOSS is a Python GUI designed as a modular data-curator platform for volcano-seismic data analysis. Detection, segmentation and classification. With exportability and standardization at its core, users can select automatic or manual workflows to annotate seismic data from the suite of included tools. Originally, PICOSS was designed for the purposes of seismicity research as a collaboration between University of Granada (UGR) and University of Liverpool (UoL). However, the system can be used within a wide range of geophysical applications. We are currently working on switching the interface from Python 2.7 to Python 3.0+ https://github.com/srsudo/PICOSS https://github.com/srsudo/PICOSS/blob/master/info/tutorials/howto.md Simulations of the Loma Prieta earthquake using an energy-based envelope shape. https://www.researchgate.net/figure/Simulations-of-the-Loma-Prieta-earthquake-using-an-energy-based-envelope-shape-Response_fig12_315724830 From list1 at tompassin.net Mon Mar 13 11:11:32 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 13 Mar 2023 11:11:32 -0400 Subject: Can you process seismographic signals in Python or should I switch to Matlab ? In-Reply-To: <6a7323be-e6aa-4fe3-8e1b-87a658b07f8fn@googlegroups.com> References: <001101d954a1$f11085c0$d3319140$@gmail.com> <5dc020b7-d996-23b7-f666-242476ea2178@tompassin.net> <6a7323be-e6aa-4fe3-8e1b-87a658b07f8fn@googlegroups.com> Message-ID: <3424c4d6-fcf6-7959-3425-54895f3ac250@tompassin.net> On 3/13/2023 12:39 AM, a a wrote: > But some unknown reasons Matplotlib and numpy crash my Python 3.8 for Windows , 32-bit and no support is offered It is possible, using pip, to downgrade versions (e.g., of Matplotlob and numpy) to see if you can find versions that work. Of course moving to 64-bit Python >= 3.10 would be better, but if that were possible I imagine you would have done it already. BTW, it would be useful if you said what operating system you are using (I've been assuming Windows). From list1 at tompassin.net Mon Mar 13 11:15:59 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 13 Mar 2023 11:15:59 -0400 Subject: Can you process seismographic signals in Python or should I switch to Matlab ? In-Reply-To: <6a7323be-e6aa-4fe3-8e1b-87a658b07f8fn@googlegroups.com> References: <001101d954a1$f11085c0$d3319140$@gmail.com> <5dc020b7-d996-23b7-f666-242476ea2178@tompassin.net> <6a7323be-e6aa-4fe3-8e1b-87a658b07f8fn@googlegroups.com> Message-ID: <9e6d1728-7e53-a94e-ca16-bc720492eb92@tompassin.net> On 3/13/2023 12:39 AM, a a wrote: > But what I need is analysis of seismograms from 4,000 seismographs world wide to detect P-wave energy distribution underground around the earthquake to verify EQ Domino Effect In that case, you will have to do a great deal of work to get all that data into a common usable form, cleaned and errors removed. That will be a lot of effort no matter what language you use. In the Matplotlib lesson you pointed to, the work was already done, for one one earthquake at one location. The reference I gave, https://towardsdatascience.com/earthquake-time-series-forecasts-using-a-hybr id-clustering-lstm-approach-part-i-eda-6797b22aed8c actually includes a Python script that does this work for some selected ranges of data, so it might be a good starting point. From rshepard at appl-ecosys.com Mon Mar 13 11:23:15 2023 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 13 Mar 2023 08:23:15 -0700 (PDT) Subject: Can you process seismographic signals in Python or should I switch to Matlab ? In-Reply-To: <9e6d1728-7e53-a94e-ca16-bc720492eb92@tompassin.net> References: <001101d954a1$f11085c0$d3319140$@gmail.com> <5dc020b7-d996-23b7-f666-242476ea2178@tompassin.net> <6a7323be-e6aa-4fe3-8e1b-87a658b07f8fn@googlegroups.com> <9e6d1728-7e53-a94e-ca16-bc720492eb92@tompassin.net> Message-ID: On Mon, 13 Mar 2023, Thomas Passin wrote: >> But what I need is analysis of seismograms from 4,000 seismographs world >> wide to detect P-wave energy distribution underground around the earthquake >> to verify EQ Domino Effect > In that case, you will have to do a great deal of work to get all that > data into a common usable form, cleaned and errors removed. That will be a > lot of effort no matter what language you use. In the Matplotlib lesson > you pointed to, the work was already done, for one one earthquake at one > location. Wouldn't Pandas help here? Rich From list1 at tompassin.net Mon Mar 13 11:41:39 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 13 Mar 2023 11:41:39 -0400 Subject: Can you process seismographic signals in Python or should I switch to Matlab ? In-Reply-To: References: <001101d954a1$f11085c0$d3319140$@gmail.com> <5dc020b7-d996-23b7-f666-242476ea2178@tompassin.net> <6a7323be-e6aa-4fe3-8e1b-87a658b07f8fn@googlegroups.com> <9e6d1728-7e53-a94e-ca16-bc720492eb92@tompassin.net> Message-ID: <72f547d5-34b9-2203-23eb-9987980dcdd6@tompassin.net> On 3/13/2023 11:23 AM, Rich Shepard wrote: > On Mon, 13 Mar 2023, Thomas Passin wrote: > >>> But what I need is analysis of seismograms from 4,000 seismographs >>> world wide to detect P-wave energy distribution underground around >>> the earthquake to verify EQ Domino Effect > >> In that case, you will have to do a great deal of work to get all that >> data into a common usable form, cleaned and errors removed. That will >> be a >> lot of effort no matter what language you use. In the Matplotlib lesson >> you pointed to, the work was already done, for one one earthquake at one >> location. > > Wouldn't Pandas help here? No doubt, depending on the data formats used. But it's still going to be a big task. From rshepard at appl-ecosys.com Mon Mar 13 13:46:26 2023 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 13 Mar 2023 10:46:26 -0700 (PDT) Subject: Can you process seismographic signals in Python or should I switch to Matlab ? Message-ID: <5881496b-6fa8-7a81-135a-a2e4f983fa9@appl-ecosys.com> On Mon, 13 Mar 2023, Thomas Passin wrote: > No doubt, depending on the data formats used. But it's still going to be a > big task. Thomas, True, but once you have a dataframe with all the information about all the earthquakes you can extract data for every analysis you want to do. If you've not read Wes McKinney's "Python for Data Analysis: Data Wrangling with Pandas, NumPy, and IPython" I encourage you to do so. Regards, Rich From list1 at tompassin.net Mon Mar 13 14:10:14 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 13 Mar 2023 14:10:14 -0400 Subject: Can you process seismographic signals in Python or should I switch to Matlab ? In-Reply-To: <5881496b-6fa8-7a81-135a-a2e4f983fa9@appl-ecosys.com> References: <5881496b-6fa8-7a81-135a-a2e4f983fa9@appl-ecosys.com> Message-ID: <4dcc9e59-add3-6d3c-a9f7-612c35a6d076@tompassin.net> On 3/13/2023 11:54 AM, Rich Shepard wrote:> On Mon, 13 Mar 2023, Thomas Passin wrote: > >> No doubt, depending on the data formats used. But it's still going >> to be a big task. > > Thomas, > > True, but once you have a dataframe with all the information about > all the earthquakes you can extract data for every analysis you want > to do. This message would better have gone to the list instead of just me. I'm not saying that Pandas is a bad choice! I'm saying that getting all that data into shape so that it can be ingested into a usable dataframe will be a lot of hard work. > If you've not read Wes McKinney's "Python for Data Analysis: Data > Wrangling with Pandas, NumPy, and IPython" I encourage you to do so. I've been interested in that title, but since I don't currently have any large, complex data wrangling problems I've put it off. From avi.e.gross at gmail.com Mon Mar 13 15:00:54 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Mon, 13 Mar 2023 15:00:54 -0400 Subject: Can you process seismographic signals in Python or should I switch to Matlab ? In-Reply-To: <4dcc9e59-add3-6d3c-a9f7-612c35a6d076@tompassin.net> References: <5881496b-6fa8-7a81-135a-a2e4f983fa9@appl-ecosys.com> <4dcc9e59-add3-6d3c-a9f7-612c35a6d076@tompassin.net> Message-ID: <006e01d955de$236347f0$6a29d7d0$@gmail.com> Hi, This seems again to be a topic wandering. Was the original question whether Python could be used for dealing with Seismic data of some unspecified sort as in PROCESSING it and now we are debating how to clean various aspects of data and make things like data.frames and extract subsets for analysis? Plenty of the above can be done in any number of places ranging from languages like Python and R to databases and SQL. If the result you want to analyze can then be written in a format with rows and columns containing the usual suspects like numbers and text and dates and so on, then this part of the job can be done anywhere you want. And when you have assembled your data and now want to make a query to generate a subset such as data in a date range that is from a set of measuring stations and with other qualities, then you can simply save the data to a file in whatever format, often something like a .CSV. It is the following steps where you want to choose your language based on what is available. Are you using features like a time series, for example? Are you looking or periodicity. Is graphing a major aspect and do you need some obscure graph types not easily found but that are parts of packages/modules in some language like R or Python? Do you need the analysis to have interactive aspects such as from a GUI, or a web page? Does any aspect of your work include things like statistical analyses or machine learning? The list goes on. As mentioned, people who do lots of stuff along these lines can share some tools in python, or elsewhere, they find useful and that might help fit the needs of the OP but they work best when they have a better idea of what exactly you want to do. Part of what I gleaned, was a want to do a 3-D graph that rotates. Python has multiple graphics packages and so on as do languages like R. The likelihood of finding something useful goes up if you identify if there are communities of people doing similar work and can share some of their tools. Hence the idea of focused searches. Asking here will largely get you people mainly who use Python and if it turns out R or something entirely else meets your needs better, perhaps Mathematica even if you have to pay for it if that is expected by your peers. My guess is that python would be a decent choice as it can do almost anything, but for practical purposes, you do not want to stick with what is in the base and probably want to use extensions like numpy/pandas and perhaps others like scipy and if doing graphics, there are too many including matplotlib and seaborn but you may need something specialized for your needs. I cannot stress the importance of making sure the people evaluating and using your work can handle it. Python is fairly mainstream and free enough that it can foot your bill. But it has various versions and clearly nobody would advise you to use version 2. Some versions are packaged with many of the tools you may want to use, such as Anaconda. It depends on your level of expertise already and how much you want to learn to get this task done. You make it sound like your kind of work must be done alone, and that can simplify things but also mean more work for you. -----Original Message----- From: Python-list On Behalf Of Thomas Passin Sent: Monday, March 13, 2023 2:10 PM To: python-list at python.org Subject: Re: Can you process seismographic signals in Python or should I switch to Matlab ? On 3/13/2023 11:54 AM, Rich Shepard wrote:> On Mon, 13 Mar 2023, Thomas Passin wrote: > >> No doubt, depending on the data formats used. But it's still going >> to be a big task. > > Thomas, > > True, but once you have a dataframe with all the information about > all the earthquakes you can extract data for every analysis you want > to do. This message would better have gone to the list instead of just me. I'm not saying that Pandas is a bad choice! I'm saying that getting all that data into shape so that it can be ingested into a usable dataframe will be a lot of hard work. > If you've not read Wes McKinney's "Python for Data Analysis: Data > Wrangling with Pandas, NumPy, and IPython" I encourage you to do so. I've been interested in that title, but since I don't currently have any large, complex data wrangling problems I've put it off. -- https://mail.python.org/mailman/listinfo/python-list From cs at cskk.id.au Mon Mar 13 16:35:48 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 14 Mar 2023 07:35:48 +1100 Subject: =?utf-8?B?6L2s5Y+R?= =?utf-8?Q?=3A?= How to exit program with custom code and custom message? In-Reply-To: References: Message-ID: On 13Mar2023 10:18, scruel tao wrote: >Chris: >> but for anything more complicated, just print and then exit. >> It's worth noting, by the way, that sys.exit("error message") will >> print that to STDERR, not to STDOUT, which mean that the equivalent >> is: > >Yes, I know, but don?t you think if `sys.exit` can take more parameters >and have a default output channel selection strategy will be better? That kind of thing is an open ended can of worms. You're better off writing your own `aort()` function such as: def abort(message, *a, output=None, exit_code=1): if a: message = message %a if output is None: output = sys.stderr print(message, file=output) exit(exit_code) which can be extended with whatever (potentially _many_) custom options you like. `sys.exit()` itself is just to abort your programme, and doesn't want a lot of knobs. The more knobs, the more things which have to be implemented, and if the knobs are not independent that gets complicated very quickly. Not to mention agreeing on what knobs to provide. BTW, `sys.exit()` actually raises a `SystemExit` exception which is handled by the `sys.excepthook` callback which handles any exception which escapes from the programme uncaught. Finally, in larger programs it is uncommon to call `sys.exit()` except in the very outermost "main function", and even there I tend to just `return`, myself. Example: def main(argv=None): if argv is None: argv = sys.argv xit = 0 .... handle the command line arguments, run code ... ... errors set xit=1 or maybe xit="message" ... return xit if __name__ == '__main__': sys.exit(main(sys.argv)) Notice that the only call to `sys.exit()` is right at the bottom. Everything else is just regularfunction returns. Cheers, Cameron Simpson From manta103g at gmail.com Mon Mar 13 11:30:12 2023 From: manta103g at gmail.com (a a) Date: Mon, 13 Mar 2023 08:30:12 -0700 (PDT) Subject: Can you process seismographic signals in Python or should I switch to Matlab ? In-Reply-To: References: <001101d954a1$f11085c0$d3319140$@gmail.com> <5dc020b7-d996-23b7-f666-242476ea2178@tompassin.net> <3424c4d6-fcf6-7959-3425-54895f3ac250@tompassin.net> <6a7323be-e6aa-4fe3-8e1b-87a658b07f8fn@googlegroups.com> Message-ID: <05298e58-bb1e-440e-a5cf-ae8ef2e20ec1n@googlegroups.com> On Monday, 13 March 2023 at 16:12:04 UTC+1, Thomas Passin wrote: > On 3/13/2023 12:39 AM, a a wrote: > > But some unknown reasons Matplotlib and numpy crash my Python 3.8 for Windows , 32-bit and no support is offered > It is possible, using pip, to downgrade versions (e.g., of Matplotlob > and numpy) to see if you can find versions that work. Of course moving > to 64-bit Python >= 3.10 would be better, but if that were possible I > imagine you would have done it already. > > BTW, it would be useful if you said what operating system you are using > (I've been assuming Windows). sorry Windows 7 My concept in building Earthquake Prediction System based on Precognition is to use RTL Software Defined Radio (SDR) to receive data from outdoor seismic sensors (smartphones turned into seismographs - sending acceleration data via audio output, to be transmitted by radio transmitter to a remote RTL SDR station, for real time processing, P-wave energy envelope calculation, earthquake depth calculation sine in case of Turkey, USGS assigns 10km depth value by default to a single EQ event. Why SDR ? Since I don't expect Cellular network to work and be operational in remote, mountain regions of Turkey after the strong 7,8 earthquake, so SDR should work as backup for cellular 3G/LTE network in the region. In case of Android smartphones I need to switch to Python for Android to get flexibility offered by scripting to support earthquake study ideas just in time and to share such ideas with friends. --- python-for-android ? PyPI https://pypi.org/project/python-for-android python-for-android is a packaging tool for Python apps on Android. You can create your own Python distribution including the modules and dependencies you want, and bundle it in an APK or AAB along with your own code. Features include: Different app backends including Kivy, PySDL2, and a WebView with Pyt? See more Documentation Follow the quickstartinstructionsto install and begin creating APKs and AABs. Quick instructions: install python-for-android with: (for the develop branch: pip install git+https://github.com/kivy/? See more Contributing We love pull requests and discussing novel ideas. Check out the Kivyproject contribution guideandfeel free to improve python-for-android. See ou? See more Support If you need assistance, you can ask for help on our mailing list: 1. User Group: https://groups.google.com/group/kivy-users 2. Email: kivy-users at googlegroups.com ? See more History In 2015 these tools were rewritten to provide a new, easier-to-use andeasier-to-extend interface. If you'd like to browse the old toolchain, itsstatus is re? See more Explore further Global web icon Is there a way to run Python on Android? - Stack Overflow stackoverflow.com Global web icon How to Download and Install Python for Android mptricks.com Global web icon How to develop Android app completely using python? stackoverflow.com Global web icon How to download and install Python Latest Version on An? geeksforgeeks.org Global web icon An Introduction to Python for Android Development pythonpool.com Recommended to you based on what's popular ? Feedback >From pypi.org Content Documentation Support Contributing History Create and run Python apps on your Android phone https://opensource.com/article/20/8/python-android... WebAug 26, 2020 ? $ pkg install python Once the installation and auto set-up of configuration is complete, it?s time to build your application. Build an app for Android on Android Now that you have a terminal installed, you can ? GitHub - kivy/python-for-android: Turn your Python application ? https://github.com/kivy/python-for-android Webpython-for-android is a packaging tool for Python apps on Android. You can create your own Python distribution including the modules and dependencies you want, and bundle it in an APK or AAB along with your ? When did Python 2 stop supporting Android? See this and other topics on this result An introduction to Python on Android - Android Authority https://www.androidauthority.com/an-introduction... WebMar 31, 2017 ? Python is a particularly simple and elegant coding language that is designed with the beginner in mind. The problem is that learning to ? Reviews: 8 Estimated Reading Time: 9 mins Android - Python Wiki https://wiki.python.org/moin/Android WebThere are several ways to use Python on Android. The following table summarizes those projects which are currently active: BeeWare is a toolkit for developing cross-platform ? People also ask How to run Python on Android?Create and run Python apps on your Android phone 1 Install Termux on Android. First, install the Termux application. ... 2 Build an app for Android on Android. Now that you have a terminal installed, you can work on your Android phone largely as if it were just another Linux computer. 3 Write Python code on Android. You're all set up. ... Create and run Python apps on your Android phone opensource.com/article/20/8/python-android-mobile What is Python-for-Android?The result is a standalone Android project which can be used to generate any number of different APKs, even with different names, icons, Python code etc. The second function of python-for-android is to provide a simple interface to these distributions, to generate from such a project a Python APK with build parameters and Python code to taste. python-for-android ? python-for-android 0.1 documentation python-for-android.readthedocs.io/en/latest/ Is there a Python game for Android?I created an Android game that is completely developed in Python using Kivy. It is called CoinTex available here at Google Play: play.google.com/store/apps/details?id=coin.tex.cointexreactfast. The source code of the game is available here at GitHub: github.com/ahmedfgad/CoinTex. How to develop Android app completely using python? stackoverflow.com/questions/49955489/how-to-develop-? What version of Python for Android should I use?If you need to build targeting an api level below 21, you should use an older version of python-for-android (<=0.7.1). On March of 2020 we dropped support for creating apps that use Python 2. The latest python-for-android release that supported building Python 2 was version 2019.10.6. python-for-android ? PyPI pypi.org/project/python-for-android/ Feedback How to develop Android app completely using python? https://stackoverflow.com/questions/49955489 WebApr 20, 2018 ? To answer your first question: yes it is feasible to develop an android application in pure python, in order to achieve this I suggest you use BeeWare, which is ? How to establish a link between python and Android Dec 27, 2020 Is there a way to run Python on Android? See more results How To Write Android Apps In Python? - AskPython https://www.askpython.com/python/examples/write-android-apps-in-python WebNov 29, 2021 ? The framework for this task will be employed as Kivy and APK packaging will be executed by Buildozer. Using Kivy To Build Android Apps in Python Kivy is used to ? Download Python for Other Platforms | Python.org https://www.python.org/download/other WebPython is available for RISC OS, and can be obtained using the PackMan package manager. Python for Solaris You can purchase ActivePython (commercial and ? python-for-android ? python-for-android 0.1 ? https://python-for-android.readthedocs.io/en/latest Webpython-for-android is an open source build tool to let you package Python code into standalone android APKs. These can be passed around, installed, or uploaded to ? Python For Android - Apps on Google Play https://play.google.com/store/apps/details?id=... WebJul 1, 2022 ? About this app. Intelligent Python 3.6.9 IDE with syntax recognition and auto text formatting and more awesome feature from iLabs corporation. Python 3.6.9 IDE, Providing syntax recognition and... Related searches for Python for Android python android app python to apk py to apk qpython 3l qpython python for android download install python on android python f?r android app 1 2 3 4 5 Videos of Python for Android bing.com/videos App Python Android Python Icons Python App Development Python Application Install Python On Android Kivy Android-App Python for Beginners Python Mobile-App Python Apps Code Python App Download How to run Python on Android phones | Python for Android | Python on mobile | Great Learning Play How to run Python on Android phones | Python for Android | Python on mobile | Great Learning 9:22 How to run Python on Android phones | Python for Android ? 31,8K views ? Apr 7, 2021 YouTubeGreat Learning Android App Development in Python With Kivy 26:27 Android App Development in Python With Kivy 146,1K viewsJul 31, 2021 YouTubeNeuralNine Convert Python to Android with WINDOWS & LINUX + Fix Common Bugs 18:59 Convert Python to Android with WINDOWS & LINUX ? 134,7K viewsAug 5, 2021 YouTubePython Simplified See more videos From manta103g at gmail.com Mon Mar 13 11:40:46 2023 From: manta103g at gmail.com (a a) Date: Mon, 13 Mar 2023 08:40:46 -0700 (PDT) Subject: Can you process seismographic signals in Python or should I switch to Matlab ? In-Reply-To: References: <001101d954a1$f11085c0$d3319140$@gmail.com> <5dc020b7-d996-23b7-f666-242476ea2178@tompassin.net> <9e6d1728-7e53-a94e-ca16-bc720492eb92@tompassin.net> <6a7323be-e6aa-4fe3-8e1b-87a658b07f8fn@googlegroups.com> Message-ID: On Monday, 13 March 2023 at 16:16:28 UTC+1, Thomas Passin wrote: > On 3/13/2023 12:39 AM, a a wrote: > > But what I need is analysis of seismograms from 4,000 seismographs world wide to detect P-wave energy distribution underground around the earthquake to verify EQ Domino Effect > In that case, you will have to do a great deal of work to get all that > data into a common usable form, cleaned and errors removed. That will > be a lot of effort no matter what language you use. In the Matplotlib > lesson you pointed to, the work was already done, for one one earthquake > at one location. > > The reference I gave, > https://towardsdatascience.com/earthquake-time-series-forecasts-using-a-hybr > > id-clustering-lstm-approach-part-i-eda-6797b22aed8c > > actually includes a Python script that does this work for some selected > ranges of data, so it might be a good starting point. Thank you excellent example "The imported json files were heavily-nested; hence, during data cleaning, I ?denested? the json files, transformed them into dataframes, fixed the column datatypes, imputed the NaN values, and finally concatenated them into a global dataframe, which was workable. For a full description of data cleaning, visit my GitHub profile. Finally, I indexed the dataframe by timestamps as a time-series dataframe: https://towardsdatascience.com/earthquake-time-series-forecasts-using-a-hybrid-clustering-lstm-approach-part-i-eda-6797b22aed8c I would like to work with Saied Mighani one day but unfortunately, seismology projects, studies are one-man activity. I am success oriented in building Earthquake Prediction System and I am sure, P-wave energy envelope calculate for every earthquake, for every seismographic station can give valuable hints on how earthquake energy is distributed underground, since what is recorded by surface seismographs is some form of such P-wave envelope energy transferred at the direction of surface placed seismograph. Ideas are great but life is for real ;) thank you From morphex at gmail.com Mon Mar 13 17:26:20 2023 From: morphex at gmail.com (Morten W. Petersen) Date: Mon, 13 Mar 2023 22:26:20 +0100 Subject: =- and -= snag Message-ID: Hi. I was working in Python today, and sat there scratching my head as the numbers for calculations didn't add up. It went into negative numbers, when that shouldn't have been possible. Turns out I had a very small typo, I had =- instead of -=. Isn't it unpythonic to be able to make a mistake like that? Regards, Morten -- I am https://leavingnorway.info Videos at https://www.youtube.com/user/TheBlogologue Twittering at http://twitter.com/blogologue Blogging at http://blogologue.com Playing music at https://soundcloud.com/morten-w-petersen Also playing music and podcasting here: http://www.mixcloud.com/morten-w-petersen/ On Google+ here https://plus.google.com/107781930037068750156 On Instagram at https://instagram.com/morphexx/ From gherron at digipen.edu Mon Mar 13 20:28:16 2023 From: gherron at digipen.edu (Gary Herron) Date: Mon, 13 Mar 2023 17:28:16 -0700 Subject: =- and -= snag In-Reply-To: References: Message-ID: <7bc3eb74-622f-392f-b400-5e99cc7b0d29@digipen.edu> On 3/13/23 2:26 PM, morphex at gmail.com wrote: > Hi. > > I was working in Python today, and sat there scratching my head as the > numbers for calculations didn't add up. It went into negative numbers, > when that shouldn't have been possible. > > Turns out I had a very small typo, I had =- instead of -=. > > Isn't it unpythonic to be able to make a mistake like that? > > Regards, > > Morten > These all mean the same thing, but I don't see a good way to designate the second or third as an error. x = -5 x=-5 x =- 5 Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology From rosuav at gmail.com Mon Mar 13 21:07:19 2023 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Mar 2023 12:07:19 +1100 Subject: =- and -= snag In-Reply-To: <7bc3eb74-622f-392f-b400-5e99cc7b0d29@digipen.edu> References: <7bc3eb74-622f-392f-b400-5e99cc7b0d29@digipen.edu> Message-ID: On Tue, 14 Mar 2023 at 11:37, Gary Herron wrote: > > > On 3/13/23 2:26 PM, morphex at gmail.com wrote: > > Hi. > > > > I was working in Python today, and sat there scratching my head as the > > numbers for calculations didn't add up. It went into negative numbers, > > when that shouldn't have been possible. > > > > Turns out I had a very small typo, I had =- instead of -=. > > > > Isn't it unpythonic to be able to make a mistake like that? > > > > Regards, > > > > Morten > > > > These all mean the same thing, but I don't see a good way to designate > the second or third as an error. > > > x = -5 > x=-5 > x =- 5 > The second one isn't definitely an error, but the third is a failure of style. Many style guides mandate, for instance, equal whitespace either side of a binary operator. It's pretty straight-forward for a program to tokenize your code the exact same way that Python would, so it will interpret it thus: NAME "x" (whitespace " ") OP "=" OP "-" (whitespace " ") NUMBER "5" The whitespace parts aren't tokens in the normal sense, but worst case, you can count positions. And since there's one space prior to the "=" and none after, it violates the style rule, and can thus be flagged. (This is one reason that I detest autoformatters. You might notice the autoformatter relayout your code into "x = -5", but if you don't spot it right at that moment, there's a lower chance that it'll look like a problem. OTOH, something that simply flags the error and leaves it for you to fix, even if you don't notice it immediately, will bring this line to your attention and let you wonder whether it's misformatted or miscoded.) Of course, all this is predicated on you actually putting whitespace around your equals signs. If you write it all crunched together as "x=-5", there's no extra clues to work with. Linters and code reviewers can make use of all the available information, including whitespace, to determine programmer intent. ChrisA From python at mrabarnett.plus.com Mon Mar 13 21:05:55 2023 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 14 Mar 2023 01:05:55 +0000 Subject: =- and -= snag In-Reply-To: <7bc3eb74-622f-392f-b400-5e99cc7b0d29@digipen.edu> References: <7bc3eb74-622f-392f-b400-5e99cc7b0d29@digipen.edu> Message-ID: On 2023-03-14 00:28, Gary Herron wrote: > > On 3/13/23 2:26 PM, morphex at gmail.com wrote: >> Hi. >> >> I was working in Python today, and sat there scratching my head as the >> numbers for calculations didn't add up. It went into negative numbers, >> when that shouldn't have been possible. >> >> Turns out I had a very small typo, I had =- instead of -=. >> >> Isn't it unpythonic to be able to make a mistake like that? >> >> Regards, >> >> Morten >> > > These all mean the same thing, but I don't see a good way to designate > the second or third as an error. > > > x = -5 > x=-5 > x =- 5 > The third one could be picked up as suspicious by a linter due to its unusual spacing. From avi.e.gross at gmail.com Mon Mar 13 21:09:52 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Mon, 13 Mar 2023 21:09:52 -0400 Subject: =- and -= snag In-Reply-To: References: Message-ID: <009901d95611$aea10040$0be300c0$@gmail.com> Morten, Suggesting something is UNPYTHONIC is really not an argument I take seriously. You wrote VALID code by the rules of the game and it is not a requirement that it guesses at what you are trying to do and calls you an idiot! More seriously, python lets you do some completely obscure things such as check whether some random object or expression is truthy or not. There is no way in hell the language, as defined, can catch all kinds of mistakes. Now some languages or their linters have chosen to provide warnings of code that may be valid but is often an error. Consider: x = 1 y = 0 x = y Do I want to rest x to the value of y? Maybe. Or do I want the interpreter to print out whether x == y perhaps? Well what if the third line above was x == y Is that too a warning? To add to the confusion some languages have an ===, :=, +=, -=, /=, |= or oddities like %=% and many of these are all variations on meanings vaguely related to equality before or after ... So, no, it is not only not unpythonic, in my opinion, but quite pythonic to let the interpreter interpret what you wrote and not know what you meant. Is there possible a flag that would require your code to use spaces in many places that might cut down on mistakes? There could be and so your example of something like "new =- old" might be asked to be rewritten as "new = - old" or even "new = (-old)" but for now, you may want to be more careful. I do sympathize with the problem of a hard to find bug because it LOOKS RIGHT to you. But it is what it is. Avi -----Original Message----- From: Python-list On Behalf Of Morten W. Petersen Sent: Monday, March 13, 2023 5:26 PM To: python-list Subject: =- and -= snag Hi. I was working in Python today, and sat there scratching my head as the numbers for calculations didn't add up. It went into negative numbers, when that shouldn't have been possible. Turns out I had a very small typo, I had =- instead of -=. Isn't it unpythonic to be able to make a mistake like that? Regards, Morten -- I am https://leavingnorway.info Videos at https://www.youtube.com/user/TheBlogologue Twittering at http://twitter.com/blogologue Blogging at http://blogologue.com Playing music at https://soundcloud.com/morten-w-petersen Also playing music and podcasting here: http://www.mixcloud.com/morten-w-petersen/ On Google+ here https://plus.google.com/107781930037068750156 On Instagram at https://instagram.com/morphexx/ -- https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Mon Mar 13 21:37:27 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 13 Mar 2023 21:37:27 -0400 Subject: =- and -= snag In-Reply-To: References: <7bc3eb74-622f-392f-b400-5e99cc7b0d29@digipen.edu> Message-ID: <5f79b38c-f426-94b9-6998-490367e1223d@tompassin.net> On 3/13/2023 9:07 PM, Chris Angelico wrote: > Of course, all this is predicated on you actually putting whitespace > around your equals signs. If you write it all crunched together as > "x=-5", there's no extra clues to work with. > > Linters and code reviewers can make use of all the available > information, including whitespace, to determine programmer intent. This is the kind of thing that unit tests can catch. From rosuav at gmail.com Mon Mar 13 21:47:58 2023 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Mar 2023 12:47:58 +1100 Subject: =- and -= snag In-Reply-To: <5f79b38c-f426-94b9-6998-490367e1223d@tompassin.net> References: <7bc3eb74-622f-392f-b400-5e99cc7b0d29@digipen.edu> <5f79b38c-f426-94b9-6998-490367e1223d@tompassin.net> Message-ID: On Tue, 14 Mar 2023 at 12:38, Thomas Passin wrote: > > On 3/13/2023 9:07 PM, Chris Angelico wrote: > > Of course, all this is predicated on you actually putting whitespace > > around your equals signs. If you write it all crunched together as > > "x=-5", there's no extra clues to work with. > > > > Linters and code reviewers can make use of all the available > > information, including whitespace, to determine programmer intent. > > This is the kind of thing that unit tests can catch. > Maybe, but that's quite orthogonal. The linter would highlight the exact line of code with the odd whitespace; a unit test would merely point out that the overall behaviour is incorrect, which would have been no further information beyond what the OP already knew (the numbers weren't adding up). ChrisA From list1 at tompassin.net Mon Mar 13 22:23:38 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 13 Mar 2023 22:23:38 -0400 Subject: =- and -= snag In-Reply-To: References: <7bc3eb74-622f-392f-b400-5e99cc7b0d29@digipen.edu> <5f79b38c-f426-94b9-6998-490367e1223d@tompassin.net> Message-ID: <81191265-466b-1152-93f9-d4ea24794843@tompassin.net> On 3/13/2023 9:47 PM, Chris Angelico wrote: > On Tue, 14 Mar 2023 at 12:38, Thomas Passin wrote: >> >> On 3/13/2023 9:07 PM, Chris Angelico wrote: >>> Of course, all this is predicated on you actually putting whitespace >>> around your equals signs. If you write it all crunched together as >>> "x=-5", there's no extra clues to work with. >>> >>> Linters and code reviewers can make use of all the available >>> information, including whitespace, to determine programmer intent. >> >> This is the kind of thing that unit tests can catch. >> > > Maybe, but that's quite orthogonal. The linter would highlight the > exact line of code with the odd whitespace; a unit test would merely > point out that the overall behaviour is incorrect, which would have > been no further information beyond what the OP already knew (the > numbers weren't adding up). > > ChrisA *This* time the OP happened to know. People in the thread have been discussing how to pick this kind of mistake with linters or what have you. Even with a linter, whether or not this would have been picked up depends on how it has been configured. Really, the only defense against these kind of potential mistakes or typos is not to use constructions that may be more likely to get wrong (or be typoed). In this particular case, that would probably be too great a limitation for most of us. But the general principle is a good one. Douglas Crockford wrote a book on using just the better parts of Javascript (JavaScript: The Good Parts - rather dated by now but still worth the reading). Of course, anyone can have a brain blip on any given day! From scruelt at hotmail.com Mon Mar 13 22:34:37 2023 From: scruelt at hotmail.com (scruel tao) Date: Tue, 14 Mar 2023 02:34:37 +0000 Subject: How to exit program with custom code and custom message? In-Reply-To: References: Message-ID: Lars: > I totally understand your reasoning here, but in some way it follows the unix philosophy: Do only one thing, but do that good. I understand, python is not strongly typed, so `sys.exit` will be able to accept any types parameters rather than just integer. In order to handle such ?other? types logic, I think this function already violated the unix philosophy, and there is no way to avoid it. Cameron: > That kind of thing is an open ended can of worms. You're better off > writing your own `aort()` function Thank you for your advice and example, I applied such wrappers for many years, this question comes more from ?pythonic? discussion, because as I mentioned above, `sys.exit` can accept any types. > BTW, `sys.exit()` actually raises a `SystemExit` exception which is > handled by the `sys.excepthook` callback which handles any exception > which escapes from the programme uncaught. Interesting, `raise SystemExit` seems to have the same behavior as `sys.exit`: ```shell python -c "raise SystemExit(100)" echo $? <<< 100 python -c " import sys; sys.exit(100)" echo $? <<< 100 python -c "raise SystemExit('a?)" <<< a echo $? <<< 1 python -c " import sys; sys.exit('a?)" <<< a echo $? <<< 1 ``` So, `sys.exit` is just a shortcut for `raise SystemExit`, or not? (Haven?t yet check the cpython source code) From list1 at tompassin.net Mon Mar 13 23:29:06 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 13 Mar 2023 23:29:06 -0400 Subject: How to exit program with custom code and custom message? In-Reply-To: References: Message-ID: On 3/13/2023 10:34 PM, scruel tao wrote: > Lars: >> I totally understand your reasoning here, but in some way it >> follows the unix philosophy: Do only one thing, but do that good. > I understand, python is not strongly typed, so `sys.exit` will be > able to accept any types parameters rather than just integer. In > order to handle such ?other? types logic, I think this function > already violated the unix philosophy, and there is no way to avoid > it. Most Python folks will say the Python *is* fairly strongly typed, but for a different definition of "type". That is, duck typing. From python at mrabarnett.plus.com Mon Mar 13 23:50:12 2023 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 14 Mar 2023 03:50:12 +0000 Subject: How to exit program with custom code and custom message? In-Reply-To: References: Message-ID: <6a91fc9c-4843-edcc-b9b7-427e9915f464@mrabarnett.plus.com> On 2023-03-14 03:29, Thomas Passin wrote: > On 3/13/2023 10:34 PM, scruel tao wrote: >> Lars: >>> I totally understand your reasoning here, but in some way it >>> follows the unix philosophy: Do only one thing, but do that good. > >> I understand, python is not strongly typed, so `sys.exit` will be >> able to accept any types parameters rather than just integer. In >> order to handle such ?other? types logic, I think this function >> already violated the unix philosophy, and there is no way to avoid >> it. > > Most Python folks will say the Python *is* fairly strongly typed, but > for a different definition of "type". That is, duck typing. > It's strongly typed but not statically typed, unless you count type hints, which are optional. From list1 at tompassin.net Tue Mar 14 00:18:59 2023 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 14 Mar 2023 00:18:59 -0400 Subject: How to exit program with custom code and custom message? In-Reply-To: <6a91fc9c-4843-edcc-b9b7-427e9915f464@mrabarnett.plus.com> References: <6a91fc9c-4843-edcc-b9b7-427e9915f464@mrabarnett.plus.com> Message-ID: <166297b5-4bed-1d96-f061-57510b747e95@tompassin.net> On 3/13/2023 11:50 PM, MRAB wrote: > On 2023-03-14 03:29, Thomas Passin wrote: >> On 3/13/2023 10:34 PM, scruel tao wrote: >>> Lars: >>>> I totally understand your reasoning here, but in some way it >>>> follows the unix philosophy: Do only one thing, but do that good. >> >>> I understand, python is not strongly typed, so `sys.exit` will be >>> able to accept any types parameters rather than just integer. In >>> order to handle such ?other? types logic, I think this function >>> already violated the unix philosophy, and there is no way to avoid >>> it. >> >> Most Python folks will say the Python *is* fairly strongly typed, but >> for a different definition of "type". That is, duck typing. >> > It's strongly typed but not statically typed, unless you count type > hints, which are optional. Yes, of course. That's pretty common knowledge. From list1 at tompassin.net Tue Mar 14 00:17:25 2023 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 14 Mar 2023 00:17:25 -0400 Subject: How to exit program with custom code and custom message? In-Reply-To: References: Message-ID: On 3/13/2023 10:34 PM, scruel tao wrote: > Interesting, `raise SystemExit` seems to have the same behavior as `sys.exit`: > > ```shell > python -c "raise SystemExit(100)" > echo $? > <<< 100 > > python -c " import sys; sys.exit(100)" > echo $? > <<< 100 OTOH, you don't want to get too tricky: (on Windows, obviously) C:\Users\tom>py -c "import sys; sys.exit(type(100) == type('a'))" C:\Users\tom>echo %ERRORLEVEL% 0 Presumably we wouldn't want to get an exit value of 0 for this case! From rosuav at gmail.com Tue Mar 14 00:58:39 2023 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Mar 2023 15:58:39 +1100 Subject: How to exit program with custom code and custom message? In-Reply-To: References: Message-ID: On Tue, 14 Mar 2023 at 15:28, Thomas Passin wrote: > > On 3/13/2023 10:34 PM, scruel tao wrote: > > Interesting, `raise SystemExit` seems to have the same behavior as `sys.exit`: > > > > ```shell > > python -c "raise SystemExit(100)" > > echo $? > > <<< 100 > > > > python -c " import sys; sys.exit(100)" > > echo $? > > <<< 100 > > OTOH, you don't want to get too tricky: > > (on Windows, obviously) > C:\Users\tom>py -c "import sys; sys.exit(type(100) == type('a'))" > > C:\Users\tom>echo %ERRORLEVEL% > 0 > > Presumably we wouldn't want to get an exit value of 0 for this case! > Why? You passed the value False, which is 0. So it should behave as documented, and exit 0. ChrisA From research at johnohagan.com Tue Mar 14 06:54:09 2023 From: research at johnohagan.com (John O'Hagan) Date: Tue, 14 Mar 2023 21:54:09 +1100 Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app Message-ID: Hi list I'm trying to use cv2 to display images created as numpy arrays, from within a tkinter app (which does other things with the arrays before they are displayed as images). The arrays are colour-coded visualisations of genomes and can be over a billion elements in size, and I've found the PIL methods to display images in tkinter are too slow and memory-heavy. Here is minimal code that demonstrates the problem in the subject line: import cv2 from tkinter import * images=['a.jpg', 'b.jpg', 'c.jpg'] #change to image paths cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN) cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN,? cv2.WINDOW_FULLSCREEN) counter=[0] def show(): cv2.imshow('W', cv2.imread(images[counter[0] % len(images)])) cv2.waitKey(1) counter[0] += 1 root=Tk() root.wm_attributes("-topmost", 1) Button(root, text=' Show ', command=show).pack() mainloop() It works up to a point - I can cycle through the images by clicking the button - but if I mouse-click on the displayed image (e.g. to use the zooming and panning features of cv2), nothing happens, and a few seconds later the image greys out and a popup appears saying "'Unknown' is not responding" and giving the option of waiting or forcing close (but sometimes these options are greyed out too). Clicking "wait", if available, closes the popup but it comes back a few seconds later. If I then click on the tkinter window titlebar, the popup changes to?"'Tk' is not responding". Clicking on the button still works and after a few clicks the popup closes. This happens under both x11 and wayland, but under wayland, I ?also get this error: "QSocketNotifier: Can only be used with threads started with QThread qt.qpa.wayland: Wayland does not support QWindow::requestActivate()" and only every second button press displays a new image ,with only every second image displayed. I think this particular popup is a Gnome thing, but AIUI most DEs have something similar to detect stuck apps. But the app is not stuck. I suspect this is some kind of interaction between the call to cv2.waitKey (which is necessary but I've never understood why!) and the tkinter event loop, but it's beyond my knowledge. Any suggestions about causes or workarounds? Thanks -- John From list1 at tompassin.net Tue Mar 14 08:07:19 2023 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 14 Mar 2023 08:07:19 -0400 Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app In-Reply-To: References: Message-ID: <2ec2f29b-02f7-f85f-e3c8-4e43e2effde8@tompassin.net> On 3/14/2023 6:54 AM, John O'Hagan wrote: > Hi list > > I'm trying to use cv2 to display images created as numpy arrays, from > within a tkinter app (which does other things with the arrays before > they are displayed as images). The arrays are colour-coded > visualisations of genomes and can be over a billion elements in size, > and I've found the PIL methods to display images in tkinter are too > slow and memory-heavy. > > Here is minimal code that demonstrates the problem in the subject line: > > import cv2 > from tkinter import * > > images=['a.jpg', 'b.jpg', 'c.jpg'] #change to image paths > > cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN) > cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN, > cv2.WINDOW_FULLSCREEN) > counter=[0] > def show(): > cv2.imshow('W', cv2.imread(images[counter[0] % len(images)])) > cv2.waitKey(1) > counter[0] += 1 > > root=Tk() > root.wm_attributes("-topmost", 1) > Button(root, text=' Show ', command=show).pack() > mainloop() > > It works up to a point - I can cycle through the images by clicking the > button - but if I mouse-click on the displayed image (e.g. to use the > zooming and panning features of cv2), nothing happens, and a few > seconds later the image greys out and a popup appears saying "'Unknown' > is not responding" and giving the option of waiting or forcing close > (but sometimes these options are greyed out too). Clicking "wait", if > available, closes the popup but it comes back a few seconds later. If I > then click on the tkinter window titlebar, the popup changes to?"'Tk' > is not responding". Clicking on the button still works and after a few > clicks the popup closes. > > This happens under both x11 and wayland, but under wayland, I ?also get > this error: > > "QSocketNotifier: Can only be used with threads started with QThread > qt.qpa.wayland: Wayland does not support QWindow::requestActivate()" > > and only every second button press displays a new image ,with only > every second image displayed. > > I think this particular popup is a Gnome thing, but AIUI most DEs have > something similar to detect stuck apps. But the app is not stuck. > > I suspect this is some kind of interaction between the call to > cv2.waitKey (which is necessary but I've never understood why!) and the > tkinter event loop, but it's beyond my knowledge. > > Any suggestions about causes or workarounds? > I don't know anything about the specifics here, but with billions of elements you will not be able to show more than a small fraction on the screen. So I think that a progressive disclosure approach would pay off. Sample the arrays down to a more workable size before creating the screen images. If you want to zoom in, resample them and recreate new images that only cover the zoomed in region in more detail. It would also be useful to cache the generated images so they can be re-displayed without needing to be regenerated each time. From gweatherby at uchc.edu Tue Mar 14 09:52:04 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Tue, 14 Mar 2023 13:52:04 +0000 Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app In-Reply-To: References: Message-ID: Assuming you?re using opencv-python, I?d post query at https://github.com/opencv/opencv-python/issues. From: Python-list on behalf of John O'Hagan Date: Tuesday, March 14, 2023 at 6:56 AM To: Python list Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Hi list I'm trying to use cv2 to display images created as numpy arrays, from within a tkinter app (which does other things with the arrays before they are displayed as images). The arrays are colour-coded visualisations of genomes and can be over a billion elements in size, and I've found the PIL methods to display images in tkinter are too slow and memory-heavy. Here is minimal code that demonstrates the problem in the subject line: import cv2 from tkinter import * images=['a.jpg', 'b.jpg', 'c.jpg'] #change to image paths cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN) cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) counter=[0] def show(): cv2.imshow('W', cv2.imread(images[counter[0] % len(images)])) cv2.waitKey(1) counter[0] += 1 root=Tk() root.wm_attributes("-topmost", 1) Button(root, text=' Show ', command=show).pack() mainloop() It works up to a point - I can cycle through the images by clicking the button - but if I mouse-click on the displayed image (e.g. to use the zooming and panning features of cv2), nothing happens, and a few seconds later the image greys out and a popup appears saying "'Unknown' is not responding" and giving the option of waiting or forcing close (but sometimes these options are greyed out too). Clicking "wait", if available, closes the popup but it comes back a few seconds later. If I then click on the tkinter window titlebar, the popup changes to "'Tk' is not responding". Clicking on the button still works and after a few clicks the popup closes. This happens under both x11 and wayland, but under wayland, I also get this error: "QSocketNotifier: Can only be used with threads started with QThread qt.qpa.wayland: Wayland does not support QWindow::requestActivate()" and only every second button press displays a new image ,with only every second image displayed. I think this particular popup is a Gnome thing, but AIUI most DEs have something similar to detect stuck apps. But the app is not stuck. I suspect this is some kind of interaction between the call to cv2.waitKey (which is necessary but I've never understood why!) and the tkinter event loop, but it's beyond my knowledge. Any suggestions about causes or workarounds? Thanks -- John -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!iHFg1AtgcwsfEeHXaH_Nasebf9SGreVlDs-DevEIQbFiwUQThx-_rah1QkSHRJEotJFyd-d6OCQ3GuQa1MxvsnGA$ From aapost at idontexist.club Mon Mar 13 23:09:20 2023 From: aapost at idontexist.club (aapost) Date: Mon, 13 Mar 2023 23:09:20 -0400 Subject: =- and -= snag In-Reply-To: References: Message-ID: On 3/13/23 17:26, Morten W. Petersen wrote: > It went into negative numbers, > when that shouldn't have been possible. > > Turns out I had a very small typo, I had =- instead of -=. > > Isn't it unpythonic to be able to make a mistake like that? > That is why I tell Alice it is always best to stay positive and use x-=-1 to avoid situations like that. *shrugs* From alexandernst at gmail.com Tue Mar 14 03:48:24 2023 From: alexandernst at gmail.com (Alexander Nestorov) Date: Tue, 14 Mar 2023 16:48:24 +0900 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> Message-ID: I'm working on an NLP and I got bitten by an unreasonably slow behaviour in Python while operating with small amounts of numbers. I have the following code: ```python import random, time from functools import reduce def trainPerceptron(perceptron, data): ??learningRate = 0.002 ??weights = perceptron['weights'] ??error = 0 ??for chunk in data: ?? ? ?input = chunk['input'] ?? ? ?output = chunk['output'] ?? ? ?# 12x slower than equivalent JS ?? ? ?sum_ = 0 ?? ? ?for key in input: ?? ? ? ? ?v = weights[key] ?? ? ? ? ?sum_ += v ?? ? ?# 20x slower than equivalent JS ?? ? ?#sum_ = reduce(lambda acc, key: acc + weights[key], input) ?? ? ?actualOutput = sum_ if sum_ > 0 else 0 ?? ? ?expectedOutput = 1 if output == perceptron['id'] else 0 ?? ? ?currentError = expectedOutput - actualOutput ?? ? ?if currentError: ?? ? ? ? ?error += currentError ** 2 ?? ? ? ? ?change = currentError * learningRate ?? ? ? ? ?for key in input: ?? ? ? ? ? ? ?weights[key] += change ??return error # Build mock data structure data = [{ ? ?'input': random.sample(range(0, 5146), 10), ? ?'output': 0 } for _ in range(11514)] perceptrons = [{ ? ?'id': i, ? ?'weights': [0.0] * 5147, } for i in range(60)] # simulate 60 perceptrons # Simulate NLU for i in range(151): # 150 iterations ??hrstart = time.perf_counter() ??for perceptron in perceptrons: ?? ?trainPerceptron(perceptron, data) ??hrend = time.perf_counter() ??print(f'Epoch {i} - Time for training: {int((hrend - hrstart) * 1000)}ms') ``` Running it on my M1 MBP I get the following numbers. ``` Epoch 0 - Time for training: 199ms Epoch 1 - Time for training: 198ms Epoch 2 - Time for training: 199ms Epoch 3 - Time for training: 197ms Epoch 4 - Time for training: 199ms ... Epoch 146 - Time for training: 198ms Epoch 147 - Time for training: 200ms Epoch 148 - Time for training: 198ms Epoch 149 - Time for training: 198ms Epoch 150 - Time for training: 198ms ``` Each epoch is taking around 200ms, which is unreasonably slow given the small amount of numbers that are being processed. I profiled the code with `cProfile` in order to find out what is going on: ``` ? ? ? ? ?655306 function calls (655274 primitive calls) in 59.972 seconds ? ?Ordered by: cumulative time ? ?ncalls??tottime??percall??cumtime??percall filename:lineno(function) ?? ? ?3/1?? ?0.000?? ?0.000? ?59.972? ?59.972 {built-in method builtins.exec} ?? ? ? ?1?? ?0.005?? ?0.005? ?59.972? ?59.972 poc-small.py:1() ? ? ?9060? ?59.850?? ?0.007? ?59.850?? ?0.007 poc-small.py:4(trainPerceptron) ?? ? ? ?1?? ?0.006?? ?0.006?? ?0.112?? ?0.112 poc-small.py:34() ?? ?11514?? ?0.039?? ?0.000?? ?0.106?? ?0.000 random.py:382(sample) ? ?115232?? ?0.034?? ?0.000?? ?0.047?? ?0.000 random.py:235(_randbelow_with_getrandbits) ?? ?11548?? ?0.002?? ?0.000?? ?0.012?? ?0.000 {built-in method builtins.isinstance} ?? ?11514?? ?0.002?? ?0.000?? ?0.010?? ?0.000 :117(__instancecheck__) ? ?183616?? ?0.010?? ?0.000?? ?0.010?? ?0.000 {method 'getrandbits' of '_random.Random' objects} ?? ?11514?? ?0.002?? ?0.000?? ?0.008?? ?0.000 {built-in method _abc._abc_instancecheck} ?? ?11514?? ?0.002?? ?0.000?? ?0.006?? ?0.000 :121(__subclasscheck__) ? ?115140?? ?0.005?? ?0.000?? ?0.005?? ?0.000 {method 'add' of 'set' objects} ?? ?11514?? ?0.003?? ?0.000?? ?0.004?? ?0.000 {built-in method _abc._abc_subclasscheck} ? ?115232?? ?0.004?? ?0.000?? ?0.004?? ?0.000 {method 'bit_length' of 'int' objects} ?? ? ?151?? ?0.003?? ?0.000?? ?0.003?? ?0.000 {built-in method builtins.print} ``` This wasn't too helpful, so I tried with [line_profiler][1]: ``` Timer unit: 1e-06 s Total time: 55.2079 s File: poc-small.py Function: trainPerceptron at line 4 Line #?? ? ?Hits? ? ? ? ?Time??Per Hit? ?% Time??Line Contents ============================================================== ? ? ?4? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?@profile ? ? ?5? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?def trainPerceptron(perceptron, data): ? ? ?6?? ? ?1214?? ? ? ?301.0?? ? ?0.2?? ? ?0.0?? ?learningRate = 0.002 ? ? ?7?? ? ?1214?? ? ? ?255.0?? ? ?0.2?? ? ?0.0?? ?weights = perceptron['weights'] ? ? ?8?? ? ?1214?? ? ? ?114.0?? ? ?0.1?? ? ?0.0?? ?error = 0 ? ? ?9??13973840?? ?1742427.0?? ? ?0.1?? ? ?3.2?? ?for chunk in data: ?? ?10??13973840?? ?1655043.0?? ? ?0.1?? ? ?3.0?? ? ? ?input = chunk['input'] ?? ?11??13973840?? ?1487543.0?? ? ?0.1?? ? ?2.7?? ? ? ?output = chunk['output'] ?? ?12 ?? ?13? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# 12x slower than equivalent JS ?? ?14??13973840?? ?1210755.0?? ? ?0.1?? ? ?2.2?? ? ? ?sum_ = 0 ?? ?15 139738397? ?13821056.0?? ? ?0.1? ? ?25.0?? ? ? ?for key in input: ?? ?16 139738397? ?13794656.0?? ? ?0.1? ? ?25.0?? ? ? ? ? ?v = weights[key] ?? ?17 139738396? ?14942692.0?? ? ?0.1? ? ?27.1?? ? ? ? ? ?sum_ += v ?? ?18 ?? ?19? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# 20x slower than equivalent JS ?? ?20? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#sum_ = reduce(lambda acc, key: acc + weights[key], input) ?? ?21 ?? ?22??13973839?? ?1618273.0?? ? ?0.1?? ? ?2.9?? ? ? ?actualOutput = sum_ if sum_ > 0 else 0 ?? ?23 ?? ?24??13973839?? ?1689194.0?? ? ?0.1?? ? ?3.1?? ? ? ?expectedOutput = 1 if output == perceptron['id'] else 0 ?? ?25??13973839?? ?1365346.0?? ? ?0.1?? ? ?2.5?? ? ? ?currentError = expectedOutput - actualOutput ?? ?26??13732045?? ?1211916.0?? ? ?0.1?? ? ?2.2?? ? ? ?if currentError: ?? ?27?? ?241794?? ? ?38375.0?? ? ?0.2?? ? ?0.1?? ? ? ? ? ?error += currentError ** 2 ?? ?28?? ?241794?? ? ?25377.0?? ? ?0.1?? ? ?0.0?? ? ? ? ? ?change = currentError * learningRate ?? ?29? ?2417940? ? ?271237.0?? ? ?0.1?? ? ?0.5?? ? ? ? ? ?for key in input: ?? ?30? ?2417940? ? ?332890.0?? ? ?0.1?? ? ?0.6?? ? ? ? ? ? ? ?weights[key] += change ?? ?31 ?? ?32?? ? ?1213?? ? ? ?405.0?? ? ?0.3?? ? ?0.0?? ?return error ``` This shows that these 3 lines (that are adding the numbers) are taking the entire runtime budget: ```python for key in input: ? ?v = weights[key] ? ?sum_ += v ``` I thought throwing numpy at the problem in order to speed it up, but `input` has a very small size, which means that the overhead of calling numpy will hurt the performance more than the gains obtained by making the math operations with it. Anyhow, adding numbers shouldn't be that slow, which makes me believe something weird is going on with Python. In order to confirm my theory, I ported the code to Javascript. This is the result: ```js function trainPerceptron(perceptron, data) { ??const learningRate = 0.002; ??const weights = perceptron['weights']; ??let error = 0; ??for (const chunk of data) { ?? ?const input = chunk['input']; ?? ?const output = chunk['output']; ?? ?const sum = input.reduce((acc, key) => acc + weights[key], 0); ?? ?const actualOutput = sum > 0 ? sum : 0; ?? ?const expectedOutput = output === perceptron['id'] ? 1 : 0; ?? ?const currentError = expectedOutput - actualOutput; ?? ?if (currentError) { ?? ? ?error += currentError ** 2; ?? ? ?const change = currentError * learningRate; ?? ? ?for (const key in input) { ?? ? ? ?weights[key] += change; ?? ? ?} ?? ?} ??} ??return error; } // Build mock data structure const data = new Array(11514); for (let i = 0; i < data.length; i++) { ??const inputSet = new Set(); ??while (inputSet.size < 10) { ?? ?inputSet.add(Math.floor(Math.random() * 5146)); ??} ??const input = Array.from(inputSet); ??data[i] = { input: input, output: 0 }; } const perceptrons = Array.from({ length: 60 }, (_, i) => ({ ??id: i, ??weights: Array.from({ length: 5147 }, () => 0.0), })); // simulate 60 perceptrons // Simulate NLU for (let i = 0; i < 151; i++) { // 150 iterations ??const hrstart = performance.now(); ??for (const perceptron of perceptrons) { ?? ?trainPerceptron(perceptron, data); ??} ??const hrend = performance.now(); ??console.log(`Epoch ${i} - Time for training: ${Math.floor(hrend - hrstart)}ms`); } ``` When I run the JS code I get the following numbers: ``` Epoch 0 - Time for training: 30ms Epoch 1 - Time for training: 18ms Epoch 2 - Time for training: 17ms Epoch 3 - Time for training: 17ms Epoch 4 - Time for training: 17ms ... Epoch 147 - Time for training: 17ms Epoch 148 - Time for training: 17ms Epoch 149 - Time for training: 17ms Epoch 150 - Time for training: 17ms ``` These numbers confirm my theory. Python is being unreasonably slow. Any idea why or what exactly is making it perform so poorly? Runtime details: MacOS Ventura 13.2.1 (22D68) Macbook Pro M1 Pro 32GB Python 3.11.0 (native Apple Silicon) Regards! ??[1]: https://github.com/pyutils/line_profiler From jon+usenet at unequivocal.eu Tue Mar 14 08:31:02 2023 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 14 Mar 2023 12:31:02 -0000 (UTC) Subject: =- and -= snag References: Message-ID: On 2023-03-13, Morten W. Petersen wrote: > I was working in Python today, and sat there scratching my head as the > numbers for calculations didn't add up. It went into negative numbers, > when that shouldn't have been possible. > > Turns out I had a very small typo, I had =- instead of -=. > > Isn't it unpythonic to be able to make a mistake like that? Why would it be? How could it be? Mandating white-space between operators would be unpythonic. That's nothing anyway - yesterday I had an issue in TypeScript which confused me for a while which turned out to be because 1 + 1 = 11. (I thought the whole point of TypeScript was to prevent things like that...) From clint.olsen at gmail.com Tue Mar 14 02:32:12 2023 From: clint.olsen at gmail.com (Clint Olsen) Date: Mon, 13 Mar 2023 23:32:12 -0700 (PDT) Subject: Running asyncio.run() more than once Message-ID: <1d6965c8-81c4-4bcd-b632-4f7e12bf706dn@googlegroups.com> We have an application that involves submitting hundreds to thousands of jobs to a shared computing resource, and we're using asyncio to do so because it is far less overhead than threading or multiprocessing for the bookkeeping required to keep track of all these jobs. It makes extensive use of asyncio.create_subprocess_exec(). This was developed mostly in Python 3.9.7. Normally we know ahead of time all the jobs that need to be run and this can be accommodated by a single call to asyncio.run(). However, in this new case we need to submit a few hundred jobs, review these results, and compose many more. That means a separate call to asyncio.run() is necessary. I have tried to call our app twice, and during the second iteration things hang indefinitely. Processes get launched, but it eventually stops reporting job completions. I have added debug=True to the asyncio.run() keyword args, but I'm not sure what I'm looking for that might tell me what's wrong. It may be something I'm doing, but based on the docs being ambiguous about this it could also be a fundamental limitation of asyncio. Is what I'm trying going to be impossible to accomplish? I would hate to have to rig up some sort of crazy async/sync queue system to feed jobs dynamically all because of this problem with asyncio.run(). Thanks, -Clint From g.starck at gmail.com Tue Mar 14 02:55:11 2023 From: g.starck at gmail.com (gst) Date: Mon, 13 Mar 2023 23:55:11 -0700 (PDT) Subject: Running asyncio.run() more than once In-Reply-To: <1d6965c8-81c4-4bcd-b632-4f7e12bf706dn@googlegroups.com> References: <1d6965c8-81c4-4bcd-b632-4f7e12bf706dn@googlegroups.com> Message-ID: <2cae803a-4021-4846-a418-5f3de3cbab3bn@googlegroups.com> Le mardi 14 mars 2023 ? 02:32:23 UTC-4, Clint Olsen a ?crit?: > We have an application that involves submitting hundreds to thousands of jobs to a shared computing resource, and we're using asyncio to do so because it is far less overhead than threading or multiprocessing for the bookkeeping required to keep track of all these jobs. It makes extensive use of asyncio.create_subprocess_exec(). This was developed mostly in Python 3.9.7. > I'm not asyncio expert or even not advanced user, but using a simple list to hold the jobs to execute and fill it as necessary after results gathering is not good ? ``` @async def execute_jobs(jobs: List["Job"]): while len(jobs) > 0: # launch_job(s) # gather_job(s)_result(s) # append_jobs_if_desired ``` does not make the trick ? From clint.olsen at gmail.com Tue Mar 14 03:08:50 2023 From: clint.olsen at gmail.com (Clint Olsen) Date: Tue, 14 Mar 2023 00:08:50 -0700 (PDT) Subject: Running asyncio.run() more than once In-Reply-To: <2cae803a-4021-4846-a418-5f3de3cbab3bn@googlegroups.com> References: <1d6965c8-81c4-4bcd-b632-4f7e12bf706dn@googlegroups.com> <2cae803a-4021-4846-a418-5f3de3cbab3bn@googlegroups.com> Message-ID: On Monday, March 13, 2023 at 11:55:22?PM UTC-7, gst wrote: > Le mardi 14 mars 2023 ? 02:32:23 UTC-4, Clint Olsen a ?crit : > I'm not asyncio expert or even not advanced user, but using a simple list to hold the jobs to execute and fill it as necessary after results gathering is not good ? > > ``` > @async > def execute_jobs(jobs: List["Job"]): > while len(jobs) > 0: > # launch_job(s) > # gather_job(s)_result(s) > # append_jobs_if_desired > ``` The problem with this implementation is that most/all of the code calling this app is not async code. So, we'd need a method (and thread) to communicate between the sync and async worlds. A possible implementation is here: https://stackoverflow.com/questions/59650243/communication-between-async-tasks-and-synchronous-threads-in-python So, while this is certainly possible, it would be much more straightforward to just call asyncio.run() more than once. Thanks, -Clint From loris.bennett at fu-berlin.de Tue Mar 14 11:43:14 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Tue, 14 Mar 2023 16:43:14 +0100 Subject: Distributing program for Linux Message-ID: <87wn3jnxt9.fsf@debian-BULLSEYE-live-builder-AMD64> Hi, If I write a system program which has Python >= 3.y as a dependency, what are the options for someone whose Linux distribution provides Python 3.x, where x < y? I am aware that an individual user could use (mini)conda to install a more recent version of Python in his/her home directory, but I am interested in how root would install such a program. Cheers, Loris -- This signature is currently under constuction. From simon+python at bleah.co.uk Tue Mar 14 13:15:30 2023 From: simon+python at bleah.co.uk (Simon Ward) Date: Tue, 14 Mar 2023 17:15:30 +0000 Subject: Distributing program for Linux In-Reply-To: <87wn3jnxt9.fsf@debian-BULLSEYE-live-builder-AMD64> References: <87wn3jnxt9.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: <20230314171530.GA1025@bleah.co.uk> On Tue, Mar 14, 2023 at 04:43:14PM +0100, Loris Bennett wrote: >If I write a system program which has Python >= 3.y as a dependency, >what are the options for someone whose Linux distribution provides >Python 3.x, where x < y? The docs suggest creating your own package or building and installing from source: https://docs.python.org/3/using/unix.html To install from source, use ?make altinstall? (instead of ?make install?) to avoid shadowing your system Python version. The alternative interpreter should be qualified with . version, e.g. python3.11 Depending on the package manager used by the distribution, ?checkinstall? could be used to build from source and install as a package without rolling your own. https://wiki.debian.org/CheckInstall On Ubuntu check out the deadsnakes PPA: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa Or use python-build from pyenv to install to a custom location: https://github.com/pyenv/pyenv/wiki/Common-build-problems#installing-a-system-wide-python Simon From list1 at tompassin.net Tue Mar 14 15:27:35 2023 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 14 Mar 2023 15:27:35 -0400 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> Message-ID: <7ba3a39e-4080-3a6d-ef76-9d7b817cad9f@tompassin.net> On 3/14/2023 3:48 AM, Alexander Nestorov wrote: > I'm working on an NLP and I got bitten by an unreasonably slow behaviour in Python while operating with small amounts of numbers. > > I have the following code: > > ```python > import random, time > from functools import reduce > > def trainPerceptron(perceptron, data): > ??learningRate = 0.002 > ??weights = perceptron['weights'] > ??error = 0 > ??for chunk in data: > ?? ? ?input = chunk['input'] > ?? ? ?output = chunk['output'] > > ?? ? ?# 12x slower than equivalent JS > ?? ? ?sum_ = 0 > ?? ? ?for key in input: > ?? ? ? ? ?v = weights[key] > ?? ? ? ? ?sum_ += v > > ?? ? ?# 20x slower than equivalent JS > ?? ? ?#sum_ = reduce(lambda acc, key: acc + weights[key], input) > > ?? ? ?actualOutput = sum_ if sum_ > 0 else 0 > > ?? ? ?expectedOutput = 1 if output == perceptron['id'] else 0 > ?? ? ?currentError = expectedOutput - actualOutput > ?? ? ?if currentError: > ?? ? ? ? ?error += currentError ** 2 > ?? ? ? ? ?change = currentError * learningRate > ?? ? ? ? ?for key in input: > ?? ? ? ? ? ? ?weights[key] += change [snip] Just a speculation, but the difference with the javascript behavior might be because the JS JIT compiler kicked in for these loops. From morphex at gmail.com Tue Mar 14 16:30:53 2023 From: morphex at gmail.com (Morten W. Petersen) Date: Tue, 14 Mar 2023 21:30:53 +0100 Subject: =- and -= snag In-Reply-To: References: Message-ID: Hoi. After reading the replies, I think some script / linter etc. is the right thing to do. What's the best linter for Python out there that covers this as well? At first glance I thought =- was a new assignment operator, and this is what seemed unpythonic to me, to have two operators that were so similar. -Morten On Tue, Mar 14, 2023 at 5:31?PM Jon Ribbens via Python-list < python-list at python.org> wrote: > On 2023-03-13, Morten W. Petersen wrote: > > I was working in Python today, and sat there scratching my head as the > > numbers for calculations didn't add up. It went into negative numbers, > > when that shouldn't have been possible. > > > > Turns out I had a very small typo, I had =- instead of -=. > > > > Isn't it unpythonic to be able to make a mistake like that? > > Why would it be? How could it be? Mandating white-space between > operators would be unpythonic. > > That's nothing anyway - yesterday I had an issue in TypeScript which > confused me for a while which turned out to be because 1 + 1 = 11. > (I thought the whole point of TypeScript was to prevent things like > that...) > -- > https://mail.python.org/mailman/listinfo/python-list > -- I am https://leavingnorway.info Videos at https://www.youtube.com/user/TheBlogologue Twittering at http://twitter.com/blogologue Blogging at http://blogologue.com Playing music at https://soundcloud.com/morten-w-petersen Also playing music and podcasting here: http://www.mixcloud.com/morten-w-petersen/ On Google+ here https://plus.google.com/107781930037068750156 On Instagram at https://instagram.com/morphexx/ From avi.e.gross at gmail.com Tue Mar 14 17:28:10 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Tue, 14 Mar 2023 17:28:10 -0400 Subject: =- and -= snag In-Reply-To: References: Message-ID: <004801d956bb$e0f0c990$a2d25cb0$@gmail.com> There seem to be a fundamental disconnect here based on people not understanding what can happen when spaces are optional. Yes, I have had my share of times I found what I programmed was not quite right and been unhappy but the result was mostly learning how to not not not not do that next time and follow the rules. When I write: Var = -----1 The result of five minus signs in a row is not a new long operator called "-----". It is five instances of "-" and looks more like: Var=-(-(-(-(-1)))) You can even throw in some plus signs and they are effectively ignored. It is no different than some other operators like: Var = not not not not True So the "=-" case is not a single operator even as "-=" is a single operator. If I add another negative symbol to the above, I have two operators with a binary operator of "-=" that may be implemented more efficiently or use a dunder method that handles it and then a unary "-" operator. >>> Var = 1 >>> Var -=-1 >>> Var 2 Yes, I can sympathize with humans who think the computer should do what they meant. They may also not like scenarios where they mess up the indentation and assume the computer should guess what they meant. But life is generally not like that. Whenever you are in doubt as to how something will be parsed especially given how many precedence levels python has and so on, USE PARENTHESES and sometimes spaces. If you type "Var - = 5" you get a syntax error because it sees two different operators that do not mesh well. If you type "Var = - 5" you get a result that should make sense as the minus binds to the 5 and negates it and then the assignment is done. If you leave the space between symbols out, then "-=" evaluates to a new operator and "=-" evaluates to two operators as described. There are lots of trivial bugs people find including truly simple ones like subtracting instead of adding or using a floating point number like 5.0 when you meant to use an integer or forgetting that 5/3 and 5//3 do somewhat different things. People often substitute things like bitwise operators and the computer does what you tell it. Many languages have doubled operators like "&" versus "&&" that do different things. And if you want to make a list and instead of using square brackets use curly brackets, in python, you get a set! There are so many places you can mess up. ALL languages have such features where people can and do make mistakes and sometimes cannot easily find them. Add in mistakes where different parts of a program use the same variable name and one changes it out and the other gets a confusing result. Simply put, lots of stuff is not only legal but often useful and even when a linter or other program sees what might be a mistake, it will often be wrong and something you wanted done. Consider another such arena in the lowly spelling Checker that keeps telling me things are spelled wrong because it does not know Schwarzenegger is a name or that Grosz and Gro? are valid variations on the spelling of my name. Imagine what it does when I write in any language other than English. One solution has been to have it add such words to a dictionary but that backfires when it allows words as valid even though in the current context, it is NOT VALID. So some such programs allow you to designate what dictionary/language to use to check a region such as a paragraph. Some may transition to being closer to grammar checkers that try to parse your sentences and make sure not only that a word is a valid spelling but valid given what role it plays in the sentence! Computer languages are both far simpler and yet weirder. You need to use them in ways the documentation says. But when you consider various ideas about scope, you can end up with it needing to know which of perhaps many copies of the same variable name is being referenced. So if you wrote a program where you had a local variable inside a function that you changed and you ASS U ME d you could use that variable outside the scope later and another variable already exists there with the same name, how is it supposed to know you made a mistake? How does it know you wanted a deep copy rather than a reference or shallow copy? There are so many other examples that the short answer to many questions is something like THAT IS THE WAY IT IS. Don't do that! I doubt anyone would like it if computer programs were written with multiple layers of redundancy so that many errors could be detected when all the parts do not align along with a checksum. Human languages that do something similar are, frankly, a royal pain. I mean once you have a gender and a tense and a singular/plural, for example, everything else nearby, such as adjectives, must be adjusted to have the right form or endings to match it. That may have been great when it was hard to hear a speaker from the back of the theater so the redundancy helped offer possible corrections but these days just makes the language much harder to learn. I vastly prefer a designed language like Esperanto to any human ones that evolved into monstrosities. We have lots of computer languages to choose from and some are designed to protect you from yourself to the extent that I simply have no interest in programming in them. Some take quite a bit of work to even get it to compile so you can then look to see if there are any bugs not caught. Python is towards the other end of a spectrum where the idea is to let you write programs easier. There are people now trying to in some ways ruin the usability by putting in type hints that are ignored and although potentially helpful as in a linter evaluating it, instead often make it harder to read and write code if required to use it. Some programmers like freedom and others like dependability. Of course, freedom is relative and after you have been mugged a few times by your errors, you may decide it is worth getting some protection. So, consider having code reviews where fresh eyes may spot your errors. -----Original Message----- From: Python-list On Behalf Of Morten W. Petersen Sent: Tuesday, March 14, 2023 4:31 PM To: Jon Ribbens Cc: python-list at python.org Subject: Re: =- and -= snag Hoi. After reading the replies, I think some script / linter etc. is the right thing to do. What's the best linter for Python out there that covers this as well? At first glance I thought =- was a new assignment operator, and this is what seemed unpythonic to me, to have two operators that were so similar. -Morten On Tue, Mar 14, 2023 at 5:31?PM Jon Ribbens via Python-list < python-list at python.org> wrote: > On 2023-03-13, Morten W. Petersen wrote: > > I was working in Python today, and sat there scratching my head as the > > numbers for calculations didn't add up. It went into negative numbers, > > when that shouldn't have been possible. > > > > Turns out I had a very small typo, I had =- instead of -=. > > > > Isn't it unpythonic to be able to make a mistake like that? > > Why would it be? How could it be? Mandating white-space between > operators would be unpythonic. > > That's nothing anyway - yesterday I had an issue in TypeScript which > confused me for a while which turned out to be because 1 + 1 = 11. > (I thought the whole point of TypeScript was to prevent things like > that...) > -- > https://mail.python.org/mailman/listinfo/python-list > -- I am https://leavingnorway.info Videos at https://www.youtube.com/user/TheBlogologue Twittering at http://twitter.com/blogologue Blogging at http://blogologue.com Playing music at https://soundcloud.com/morten-w-petersen Also playing music and podcasting here: http://www.mixcloud.com/morten-w-petersen/ On Google+ here https://plus.google.com/107781930037068750156 On Instagram at https://instagram.com/morphexx/ -- https://mail.python.org/mailman/listinfo/python-list From hjp-python at hjp.at Tue Mar 14 17:52:11 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 14 Mar 2023 22:52:11 +0100 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> Message-ID: <20230314215211.kq4ohsrnz6vyigxw@hjp.at> On 2023-03-14 16:48:24 +0900, Alexander Nestorov wrote: > I'm working on an NLP and I got bitten by an unreasonably slow > behaviour in Python while operating with small amounts of numbers. > > I have the following code: [...] > ?? ? ?# 12x slower than equivalent JS > ?? ? ?sum_ = 0 > ?? ? ?for key in input: > ?? ? ? ? ?v = weights[key] > ?? ? ? ? ?sum_ += v > > ?? ? ?# 20x slower than equivalent JS > ?? ? ?#sum_ = reduce(lambda acc, key: acc + weights[key], input) Not surprising. Modern JavaScript implementations have a JIT compiler. CPython doesn't. You may want to try PyPy if your code uses tight loops like that. Or alternatively it may be possible to use numpy to do these operations. 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 rosuav at gmail.com Tue Mar 14 18:05:46 2023 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Mar 2023 09:05:46 +1100 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: <20230314215211.kq4ohsrnz6vyigxw@hjp.at> References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> Message-ID: On Wed, 15 Mar 2023 at 08:53, Peter J. Holzer wrote: > > On 2023-03-14 16:48:24 +0900, Alexander Nestorov wrote: > > I'm working on an NLP and I got bitten by an unreasonably slow > > behaviour in Python while operating with small amounts of numbers. > > > > I have the following code: > [...] > > # 12x slower than equivalent JS > > sum_ = 0 > > for key in input: > > v = weights[key] > > sum_ += v > > > > # 20x slower than equivalent JS > > #sum_ = reduce(lambda acc, key: acc + weights[key], input) > > Not surprising. Modern JavaScript implementations have a JIT compiler. > CPython doesn't. > > You may want to try PyPy if your code uses tight loops like that. > > Or alternatively it may be possible to use numpy to do these operations. > Or use the sum() builtin rather than reduce(), which was *deliberately* removed from the builtins. The fact that you can get sum() without importing, but have to go and reach for functools to get reduce(), is a hint that you probably shouldn't use reduce when sum will work. Naive code is almost always going to be slower than smart code, and comparing "equivalent" code across languages is almost always an unfair comparison to one of them. ChrisA From rob.cliffe at btinternet.com Tue Mar 14 18:50:08 2023 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Tue, 14 Mar 2023 22:50:08 +0000 Subject: =- and -= snag In-Reply-To: <004801d956bb$e0f0c990$a2d25cb0$@gmail.com> References: <004801d956bb$e0f0c990$a2d25cb0$@gmail.com> Message-ID: <293830a4-086d-0300-9283-6b4a77feedfd@btinternet.com> On 14/03/2023 21:28, avi.e.gross at gmail.com wrote: > TThere are people now trying to in some ways ruin the usability by putting in type hints that are ignored and although potentially helpful as in a linter evaluating it, instead often make it harder to read and write code if required to use it. +1 Whenever I see code with type hints, I have to edit them out, either mentally, or physically, to understand what the code is actually doing.? It's adding new syntax which I'm not used to and don't want to be forced to learn. Rob Cliffe From oscar.j.benjamin at gmail.com Tue Mar 14 18:55:33 2023 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 14 Mar 2023 22:55:33 +0000 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> Message-ID: On Tue, 14 Mar 2023 at 16:27, Alexander Nestorov wrote: > > I'm working on an NLP and I got bitten by an unreasonably slow behaviour in Python while operating with small amounts of numbers. > > I have the following code: > > ```python > import random, time > from functools import reduce > > def trainPerceptron(perceptron, data): > learningRate = 0.002 > weights = perceptron['weights'] > error = 0 > for chunk in data: > input = chunk['input'] > output = chunk['output'] > > # 12x slower than equivalent JS > sum_ = 0 > for key in input: > v = weights[key] > sum_ += v In Python something like your task here would usually use something along the lines of NumPy. Your two innermost loops involve adding up a subset of numbers from a list chosen using a list of indices. This is something that numpy can do much more efficiently with its fancy indexing e.g.: In [3]: a = np.array([1, 2, 3, 4, 5, 6, 7]) In [4]: b = np.array([0, 3, 5]) In [5]: a[b] Out[5]: array([1, 4, 6]) In [6]: a[b].sum() Out[6]: 11 This a[b].sum() operation in your code would be weights[input].sum() and would be much faster than the loop shown (the speed difference will be larger if you increase the size of the input array). -- Oscar From gweatherby at uchc.edu Tue Mar 14 19:28:18 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Tue, 14 Mar 2023 23:28:18 +0000 Subject: Distributing program for Linux In-Reply-To: <87wn3jnxt9.fsf@debian-BULLSEYE-live-builder-AMD64> References: <87wn3jnxt9.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: It?s really going to depend on the distribution and whether you have root access. If you have Ubuntu and root access, you can add the deadsnakes repo, https://launchpad.net/~deadsnakes, and install whatever Python you want. The default ?python3? remains but you can called a specific Python, (e.g. python3.10). A typical shebang line would be: #!/usr/bin/env python3.10 From: Python-list on behalf of Loris Bennett Date: Tuesday, March 14, 2023 at 12:27 PM To: python-list at python.org Subject: Distributing program for Linux *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Hi, If I write a system program which has Python >= 3.y as a dependency, what are the options for someone whose Linux distribution provides Python 3.x, where x < y? I am aware that an individual user could use (mini)conda to install a more recent version of Python in his/her home directory, but I am interested in how root would install such a program. Cheers, Loris -- This signature is currently under constuction. -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!l02A4qczH46l1ScA8yisiIwlDKh96sy16woPSOSABWqym4b6dBtHzExfFwZsnPDezDwDqaM0fdCMs3080WQQZ-b5OghOOpI$ From research at johnohagan.com Tue Mar 14 22:00:44 2023 From: research at johnohagan.com (John O'Hagan) Date: Wed, 15 Mar 2023 13:00:44 +1100 Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app In-Reply-To: <2ec2f29b-02f7-f85f-e3c8-4e43e2effde8@tompassin.net> References: <2ec2f29b-02f7-f85f-e3c8-4e43e2effde8@tompassin.net> Message-ID: On Tue, 2023-03-14 at 08:07 -0400, Thomas Passin wrote: > On 3/14/2023 6:54 AM, John O'Hagan wrote: > > Hi list > > > > I'm trying to use cv2 to display images created as numpy arrays, > > from > > within a tkinter app (which does other things with the arrays > > before > > they are displayed as images). The arrays are colour-coded > > visualisations of genomes and can be over a billion elements in > > size, > > and I've found the PIL methods to display images in tkinter are too > > slow and memory-heavy. > > > > Here is minimal code that demonstrates the problem in the subject > > line: > > > > import cv2 > > from tkinter import * > > > > images=['a.jpg', 'b.jpg', 'c.jpg'] #change to image paths > > > > cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN) > > cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN, > > cv2.WINDOW_FULLSCREEN) > > counter=[0] > > def show(): > > ??? cv2.imshow('W', cv2.imread(images[counter[0] % len(images)])) > > ??? cv2.waitKey(1) > > ??? counter[0] += 1 > > > > root=Tk() > > root.wm_attributes("-topmost", 1) > > Button(root, text=' Show ', command=show).pack() > > mainloop() > > > > It works up to a point - I can cycle through the images by clicking > > the > > button - but if I mouse-click on the displayed image (e.g. to use > > the > > zooming and panning features of cv2), nothing happens, and a few > > seconds later the image greys out and a popup appears saying > > "'Unknown' > > is not responding" and giving the option of waiting or forcing > > close > > (but sometimes these options are greyed out too). Clicking "wait", > > if > > available, closes the popup but it comes back a few seconds later. > > If I > > then click on the tkinter window titlebar, the popup changes > > to?"'Tk' > > is not responding". Clicking on the button still works and after a > > few > > clicks the popup closes. [...] > I don't know anything about the specifics here, but with billions of > elements you will not be able to show more than a small fraction on > the > screen.?? Hi Thomas Thanks for your reply. In the real app I use interpolating methods to fit the whole image on the screen. In cv2: cv2.imshow('W', cv2.resize(array, (width, height)) It's very quick, fractions of a second even for a billion+ sized array. The PIL/Tk equivalent: im = ImageTk.PhotoImage(Image.fromarray(array).resize((width, height))) canvas.create_image(width/2, height/2, image=im) did the same thing but was very, very slow for such large arrays (15 minutes or more per image, with memory heavily swapped out). Having said all that, the specific problem I'm having isn't related to the size of the arrays. The code I posted above triggers the problem even with small images. > So I think that a progressive disclosure approach would pay > off.? Sample the arrays down to a more workable size before creating > the > screen images.? If you want to zoom in, resample them and recreate > new > images that only cover the zoomed in region in more detail. > > It would also be useful to cache the generated images so they can be > re-displayed without needing to be regenerated each time. This is exactly the approach I took in the first draft (except the caching idea)! I wasn't using interpolating methods and was limited to a minimum of one pixel per array element, and therefore limited in how much of the array could be displayed. Even this got pretty slow in tkinter if fully zoomed out, although the caching would have helped with that. But the project brief requires the whole genome to be visible by default. Thanks From research at johnohagan.com Tue Mar 14 22:40:51 2023 From: research at johnohagan.com (John O'Hagan) Date: Wed, 15 Mar 2023 13:40:51 +1100 Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app In-Reply-To: References: Message-ID: On Tue, 2023-03-14 at 13:52 +0000, Weatherby,Gerard wrote: > Assuming you?re using opencv-python, I?d post query at > https://github.com/opencv/opencv-python/issues. Thanks Gerard I'm using the python3-opencv package from Debian testing. Is that github the appropriate place for this query? Thanks -- John > From aapost at idontexist.club Tue Mar 14 16:22:55 2023 From: aapost at idontexist.club (aapost) Date: Tue, 14 Mar 2023 16:22:55 -0400 Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app In-Reply-To: References: Message-ID: On 3/14/23 06:54, John O'Hagan wrote: > Hi list > > I'm trying to use cv2 to display images created as numpy arrays, from > within a tkinter app (which does other things with the arrays before > they are displayed as images). The arrays are colour-coded > visualisations of genomes and can be over a billion elements in size, > and I've found the PIL methods to display images in tkinter are too > slow and memory-heavy. > > Here is minimal code that demonstrates the problem in the subject line: > > import cv2 > from tkinter import * > > images=['a.jpg', 'b.jpg', 'c.jpg'] #change to image paths > > cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN) > cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN, > cv2.WINDOW_FULLSCREEN) > counter=[0] > def show(): > cv2.imshow('W', cv2.imread(images[counter[0] % len(images)])) > cv2.waitKey(1) > counter[0] += 1 > > root=Tk() > root.wm_attributes("-topmost", 1) > Button(root, text=' Show ', command=show).pack() > mainloop() > > It works up to a point - I can cycle through the images by clicking the > button - but if I mouse-click on the displayed image (e.g. to use the > zooming and panning features of cv2), nothing happens, and a few > seconds later the image greys out and a popup appears saying "'Unknown' > is not responding" and giving the option of waiting or forcing close > (but sometimes these options are greyed out too). Clicking "wait", if > available, closes the popup but it comes back a few seconds later. If I > then click on the tkinter window titlebar, the popup changes to?"'Tk' > is not responding". Clicking on the button still works and after a few > clicks the popup closes. > > This happens under both x11 and wayland, but under wayland, I ?also get > this error: > > "QSocketNotifier: Can only be used with threads started with QThread > qt.qpa.wayland: Wayland does not support QWindow::requestActivate()" > > and only every second button press displays a new image ,with only > every second image displayed. > > I think this particular popup is a Gnome thing, but AIUI most DEs have > something similar to detect stuck apps. But the app is not stuck. > > I suspect this is some kind of interaction between the call to > cv2.waitKey (which is necessary but I've never understood why!) and the > tkinter event loop, but it's beyond my knowledge. > > Any suggestions about causes or workarounds? > > Thanks > > -- > > John > > I don't get any of the zoom/panning behavior with waitKey(1). But a couple notes from the web: https://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html Note This function should be followed by waitKey function which displays the image for specified milliseconds. Otherwise, it won?t display the image. For example, waitKey(0) will display the window infinitely until any keypress (it is suitable for image display). waitKey(25) will display a frame for 25 ms, after which display will be automatically closed. (If you put it in a loop to read videos, it will display the video frame-by-frame) https://pythonexamples.org/python-opencv-imshow/ cv2.waitKey(0) is important for holding the execution of the python program at this statement, so that the image window stays visible. If you do not provide this statement, cv2.imshow() executes in fraction of a second and the program closes all the windows it opened, which makes it almost impossible to see the image on the window. if I change waitKey to 0, I get the ability to zoom/pan, but it places the tk window in a blocked state because it is waiting on cv2 to return. If I hit the ESC key, it releases the wait and gives control back to the tk window, allowing me to press show again to continue to the next image. I can try to change waitKey to a high ms like 10000000 and have zoom/pan for that amount of time before it gives control back to tk (not a sensical approach). The fact that you can still see the image after tk takes back control is I believe just a matter of design, some examples show cv2.destroyAllWindows() after waitKey(0) to clean that up, but of course if you are reusing the same window, that destroys the target. You can resolve that if you move cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN) cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) to inside the show, and destroy it after the wait, and make waitKey 0, this allows creation/cleanup of that window per image Hitting ESC when done zooming/panning on each image to get back to tk. From aapost at idontexist.club Tue Mar 14 19:12:54 2023 From: aapost at idontexist.club (aapost) Date: Tue, 14 Mar 2023 19:12:54 -0400 Subject: =- and -= snag In-Reply-To: References: <004801d956bb$e0f0c990$a2d25cb0$@gmail.com> <293830a4-086d-0300-9283-6b4a77feedfd@btinternet.com> Message-ID: > On 3/14/23 18:50, Rob Cliffe wrote: > On 14/03/2023 21:28, avi.e.gross at gmail.com wrote: Type hints are actually situationally quite useful (though yes, kind of hard to understand when you first come across their use, largely because of things like Union). And I wouldn't recommend their use in all situations because maintaining them is frustrating. xmlschema uses them extensively though and I appreciate them. The module does what I need where all the other offerings failed, and parsing the source because of the subject matter would have been harder to quickly grok without them. Alternatively, I spent quite a while on the subject of pep 232 (before finding the pep) trying to understand it because intuitively I felt like there was something I must be missing. Turns out there isn't. And what my thoughts were assuming was the intent, are discussed under "Future Directions", but when seeing it laid out like that, subjectively the dissenting conclusion of "It opens the way to mind abuse." is more correct. "What if I launch a virtual machine inside a virtual machine inside a virtual machine inside a virtual machine, what happens?"... If I want to have a grouping of minor functionality or attributes on a callable, I can get that with creating a class that defines __call__. I would say 232 is fine for what it is (I don't have to use it, and in many cases it probably is), but the only wide use I know of that I have come across is in the standard library ElementTree: # For tests and troubleshooting register_namespace._namespace_map = _namespace_map Which I hate that variable and it's design with a passion. lol. And exactly, the more a language starts policing my ability to be flexible in my trying to find a creative solution to a problem, the less I want to use it. Sometimes to have something useably beautiful to interact with requires something painfully complex under the surface. Hiding and avoiding all complexity away so you never have to see it or make mistakes prevents you from growing. Anyway, the 20th rule to The Zen of Python is: Don't believe your own bullshit *shrug* From Keith.S.Thompson+u at gmail.com Tue Mar 14 21:06:46 2023 From: Keith.S.Thompson+u at gmail.com (Keith Thompson) Date: Tue, 14 Mar 2023 18:06:46 -0700 Subject: =- and -= snag References: Message-ID: <87v8j2omah.fsf@nosuchdomain.example.com> "Morten W. Petersen" writes: > I was working in Python today, and sat there scratching my head as the > numbers for calculations didn't add up. It went into negative numbers, > when that shouldn't have been possible. > > Turns out I had a very small typo, I had =- instead of -=. > > Isn't it unpythonic to be able to make a mistake like that? Very early versions of C (around 1975 or so, before K&R1 was published) actually used "op=" for compound assignment operators, so `x =- 2` would subtract 2 from x. It was changed to "=op" (`x -= 2`) precisely to avoid this ambiguity that programmers kept running into (people were less generous with whitespace back then). As late as the late 1990s, I used a compiler (VAXC) that still recognized the old-style compound assignment operators, though I think it warned about them. I thought "Pythonic" was more about how you write code than about the design of the language. But designing a language syntax so typos are likely to be syntax errors rather than valid code with different semantics is an interesting challenge. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u at gmail.com Working, but not speaking, for XCOM Labs void Void(void) { Void(); } /* The recursive call of the void */ From bowman at montana.com Tue Mar 14 21:36:49 2023 From: bowman at montana.com (rbowman) Date: 15 Mar 2023 01:36:49 GMT Subject: =- and -= snag References: Message-ID: On Tue, 14 Mar 2023 22:15:34 GMT, Gilmeh Serda wrote: > On Mon, 13 Mar 2023 22:26:20 +0100, Morten W. Petersen wrote: > >> numbers for calculations didn't add up. It went into negative numbers, >> when that shouldn't have been possible. > > We have all written code that makes us wonder why the compiler even > bothered with it and didn't give up on the first line. gcc does have a flag so it will stop on the first error instead of wandering around aimlessly spitting out 100 errors because you missed a curly bracket. Sometimes it's useful. From scruelt at hotmail.com Wed Mar 15 05:57:39 2023 From: scruelt at hotmail.com (scruel tao) Date: Wed, 15 Mar 2023 09:57:39 +0000 Subject: We can call methods of parenet class without initliaze it? Message-ID: The following code won?t be allowed in Java, but in python, it works fine: ```python class A: A = 3 def __init__(self): print(self.A) def p(self): print(self.A) self.A += 1 class B(A): def __init__(self): print(2) self.p() super().__init__() B() ``` How can I understand this? Will it be a problem? From greg.ewing at canterbury.ac.nz Wed Mar 15 06:54:42 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 15 Mar 2023 23:54:42 +1300 Subject: We can call methods of parenet class without initliaze it? In-Reply-To: References: Message-ID: On 15/03/23 10:57 pm, scruel tao wrote: > How can I understand this? Will it be a problem? I can't remember any details offhand, but I know I've occasionally made use of the ability to do this. It's fine as long as the method you're calling doesn't rely on anything you haven't initialised yet. -- Greg From as at sci.fi Wed Mar 15 07:02:29 2023 From: as at sci.fi (Anssi Saari) Date: Wed, 15 Mar 2023 13:02:29 +0200 Subject: Distributing program for Linux In-Reply-To: <87wn3jnxt9.fsf@debian-BULLSEYE-live-builder-AMD64> (Loris Bennett's message of "Tue, 14 Mar 2023 16:43:14 +0100") References: <87wn3jnxt9.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: "Loris Bennett" writes: > I am aware that an individual user could use (mini)conda to install a > more recent version of Python in his/her home directory, but I am > interested in how root would install such a program. Root would install the script and required Python version somewhere depending any site specific practices and then use things like pyenv, stow, environment modules or whatever to give the users access to it. Root might even package your script with the interpreter required into one binary. See Tools/freeze in the source distribution. From research at johnohagan.com Wed Mar 15 07:37:30 2023 From: research at johnohagan.com (John O'Hagan) Date: Wed, 15 Mar 2023 22:37:30 +1100 Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app In-Reply-To: References: Message-ID: On Tue, 2023-03-14 at 16:22 -0400, aapost wrote: > On 3/14/23 06:54, John O'Hagan wrote: [...] > > > > Here is minimal code that demonstrates the problem in the subject > > line: > > > > import cv2 > > from tkinter import * > > > > images=['a.jpg', 'b.jpg', 'c.jpg'] #change to image paths > > > > cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN) > > cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN, > > cv2.WINDOW_FULLSCREEN) > > counter=[0] > > def show(): > > ??? cv2.imshow('W', cv2.imread(images[counter[0] % len(images)])) > > ??? cv2.waitKey(1) > > ??? counter[0] += 1 > > > > root=Tk() > > root.wm_attributes("-topmost", 1) > > Button(root, text=' Show ', command=show).pack() > > mainloop() > > > > It works up to a point - I can cycle through the images by clicking > > the > > button - but if I mouse-click on the displayed image (e.g. to use > > the > > zooming and panning features of cv2), nothing happens, and a few > > seconds later the image greys out and a popup appears saying > > "'Unknown' > > is not responding" and giving the option of waiting or forcing > > close > > (but sometimes these options are greyed out too). Clicking "wait", > > if > > available, closes the popup but it comes back a few seconds later. > > If I > > then click on the tkinter window titlebar, the popup changes > > to?"'Tk' > > is not responding". Clicking on the button still works and after a > > few > > clicks the popup closes. [...] > > I think this particular popup is a Gnome thing, but AIUI most DEs > > have > > something similar to detect stuck apps. But the app is not stuck. > > > > I suspect this is some kind of interaction between the call to > > cv2.waitKey (which is necessary but I've never understood why!) and > > the > > tkinter event loop, but it's beyond my knowledge. > > > > Any suggestions about causes or workarounds? > > > > Thanks > > > > -- > > > > John > > > > > > > I don't get any of the zoom/panning behavior with waitKey(1). But a > couple notes from the web: > > > https://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html > > Note > > This function should be followed by waitKey function which displays > the > image for specified milliseconds. Otherwise, it won?t display the > image. > For example, waitKey(0) will display the window infinitely until any > keypress (it is suitable for image display). waitKey(25) will display > a > frame for 25 ms, after which display will be automatically closed. > (If > you put it in a loop to read videos, it will display the video > frame-by-frame) > > https://pythonexamples.org/python-opencv-imshow/ > > cv2.waitKey(0) is important for holding the execution of the python > program at this statement, so that the image window stays visible. If > you do not provide this statement, cv2.imshow() executes in fraction > of > a second and the program closes all the windows it opened, which > makes > it almost impossible to see the image on the window. > > if I change waitKey to 0, I get the ability to zoom/pan, but it > places > the tk window in a blocked state because it is waiting on cv2 to > return. > If I hit the ESC key, it releases the wait and gives control back to > the > tk window, allowing me to press show again to continue to the next > image. > > I can try to change waitKey to a high ms like 10000000 and have > zoom/pan > for that amount of time before it gives control back to tk (not a > sensical approach). > > The fact that you can still see the image after tk takes back control > is > I believe just a matter of design, some examples show > cv2.destroyAllWindows() after waitKey(0) to clean that up, but of > course > if you are reusing the same window, that destroys the target. > > You can resolve that if you move > cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN) > cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN, > cv2.WINDOW_FULLSCREEN) > > to inside the show, and destroy it after the wait, and make waitKey > 0, > this allows creation/cleanup of that window per image > > Hitting ESC when done zooming/panning on each image to get back to > tk. Thanks for your reply. I'm afraid in the real app it won't be practical to have no gui control while viewing images. But your suggestions have made me realise that my issue has nothing to do with tkinter, it seems to be the way imshow is supposed to work. This code gives the same behaviour described above: cv2.imshow('W', array) cv2.waitKey(100) time.sleep(20) I've seen the docs you mention that say the window will close if no keypress happens within the waitKey time, but that doesn't seem to be what happens as you say. After waitKey returns, the image remains and everything works, but for some reason the desktop complains about an unresponsive app. You can use cv2 to display video with: while 1: frame = camera.read() #pseudocode cv2.imshow('W', frame) cv2.waitKey(1) (In fact this used to work without waitKey if you called cv2.startWindowThread() after creating the window, but that stopped working at some point.) The fact that this works, presumably because the image is being replaced often enough, suggested the following workaround to my problem, using a call to after() to re-display the current image before the desktop starts complaining: images=[cv2.imread(i) for i in ('a.jpg', 'b.jpg', 'c.jpg')] cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN) cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) counter=[0] image = [None] def show(): im = images[counter[0] % 3] cv2.imshow('W', im) cv2.waitKey(1) image[:] = [im] counter[0] += 1 root=Tk() root.wm_attributes("-topmost", 1) b=Button(root, text=' Show ', command=show) b.pack() def update(): if image[0] is not None: cv2.imshow('W', image[0]) cv2.waitKey(1) root.after(1000, update) update() mainloop() Not ideal, but I'm starting to think that despite the "highgui" label, cv2.imshow is not really suited for integration into a gui. Which is a shame because it's so damn fast!? Thanks John From roel at roelschroeven.net Wed Mar 15 08:01:49 2023 From: roel at roelschroeven.net (Roel Schroeven) Date: Wed, 15 Mar 2023 13:01:49 +0100 Subject: We can call methods of parenet class without initliaze it? In-Reply-To: References: Message-ID: <7c3318cc-5d6d-b298-f9ec-b7458da3893d@roelschroeven.net> Op 15/03/2023 om 10:57 schreef scruel tao: > The following code won?t be allowed in Java, but in python, it works fine: > ```python > class A: > A = 3 > > def __init__(self): > print(self.A) > > def p(self): > print(self.A) > self.A += 1 > > > class B(A): > def __init__(self): > print(2) > self.p() > super().__init__() > > > B() > ``` > > How can I understand this? Will it be a problem? Important: __init__ is not a constructor, like you have for example in C++. I don't know Java, but it seems plausible it works somewhat like C++ in this regard. Python does it differently: when you create an instance, the instance is fully created/constructed even before __init__ is called. __init__ is purely an initializer: you can use to initialize the things you want to initialize. Back to your example: it works because A is a class-level attribute, which is initialized independently from __init__. If you make it an instance attribute, like below, things stop working: ??? class A: ??????? def __init__(self): ??????????? self.A = 3 ??????????? print(self.A) ??????? def p(self): ??????????? print(self.A) ??????????? self.A += 1 ??? class B(A): ??????? def __init__(self): ??????????? print(2) ??????????? self.p() ??????????? super().__init__() ??? B() ??? print(A.A) That fails like this: ??? Traceback (most recent call last): ????? File ".code.tio", line 18, in ??????? B() ????? File ".code.tio", line 14, in __init__ ??????? self.p() ????? File ".code.tio", line 7, in p ??????? print(self.A) ??? AttributeError: 'B' object has no attribute 'A' That's because now A is indeed initialized in A.__init__, so it doesn't exist before A.__init__ is called. -- "Too often we hold fast to the cliches of our forebears. We subject all facts to a prefabricated set of interpretations. Too often we enjoy the comfort of opinion without the discomfort of thought." -- John F Kennedy From David.Raymond at tomtom.com Wed Mar 15 10:24:34 2023 From: David.Raymond at tomtom.com (David Raymond) Date: Wed, 15 Mar 2023 14:24:34 +0000 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> Message-ID: > Or use the sum() builtin rather than reduce(), which was > *deliberately* removed from the builtins. The fact that you can get > sum() without importing, but have to go and reach for functools to get > reduce(), is a hint that you probably shouldn't use reduce when sum > will work. Out of curiosity I tried a couple variations and am a little confused by the results. Maybe I'm having a brain fart and am missing something obvious? Each of these was run with the same "data" and "perceptrons" values to keep that fair. Times are averages over 150 iterations like the original. The only thing changed in the trainPerceptron function was how to calculate sum_ Original: sum_ = 0 for key in input: v = weights[key] sum_ += v 418ms The reduce version: sum_ = reduce(lambda acc, key: acc + weights[key], input) 758ms Getting rid of the assignment to v in the original version: sum_ = 0 for key in input: sum_ += weights[key] 380ms But then using sum seems to be slower sum with generator expression: sum_ = sum(weights[key] for key in input) 638ms sum with list comprehension: sum_ = sum([weights[key] for key in input]) 496ms math.fsum with generator expression: sum_ = math.fsum(weights[key] for key in input) 618ms math.fsum with list comprehension: sum_ = math.fsum([weights[key] for key in input]) 480ms I'm not quite sure why the built-in sum functions are slower than the for loop, or why they're slower with the generator expression than with the list comprehension. From rosuav at gmail.com Wed Mar 15 11:01:36 2023 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Mar 2023 02:01:36 +1100 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> Message-ID: On Thu, 16 Mar 2023 at 01:26, David Raymond wrote: > I'm not quite sure why the built-in sum functions are slower than the for loop, > or why they're slower with the generator expression than with the list comprehension. For small-to-medium data sizes, genexps are slower than list comps, but use less memory. (At some point, using less memory translates directly into faster runtime.) But even the sum-with-genexp version is notably faster than reduce. Is 'weights' a dictionary? You're iterating over it, then subscripting every time. If it is, try simply taking the sum of weights.values(), as this should be significantly faster. ChrisA From list1 at tompassin.net Wed Mar 15 10:58:13 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 15 Mar 2023 10:58:13 -0400 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> Message-ID: On 3/15/2023 10:24 AM, David Raymond wrote: >> Or use the sum() builtin rather than reduce(), which was >> *deliberately* removed from the builtins. The fact that you can get >> sum() without importing, but have to go and reach for functools to get >> reduce(), is a hint that you probably shouldn't use reduce when sum >> will work. > > Out of curiosity I tried a couple variations and am a little confused by the results. Maybe I'm having a brain fart and am missing something obvious? > > Each of these was run with the same "data" and "perceptrons" values to keep that fair. > Times are averages over 150 iterations like the original. > The only thing changed in the trainPerceptron function was how to calculate sum_ > > > Original: > sum_ = 0 > for key in input: > v = weights[key] > sum_ += v > 418ms > > The reduce version: > sum_ = reduce(lambda acc, key: acc + weights[key], input) > 758ms > > Getting rid of the assignment to v in the original version: > sum_ = 0 > for key in input: > sum_ += weights[key] > 380ms > > But then using sum seems to be slower > > sum with generator expression: > sum_ = sum(weights[key] for key in input) > 638ms > > sum with list comprehension: > sum_ = sum([weights[key] for key in input]) > 496ms > > math.fsum with generator expression: > sum_ = math.fsum(weights[key] for key in input) > 618ms > > math.fsum with list comprehension: > sum_ = math.fsum([weights[key] for key in input]) > 480ms > > > I'm not quite sure why the built-in sum functions are slower than the for loop, > or why they're slower with the generator expression than with the list comprehension. I tried similar variations yesterday and got similar results. All the sum() versions I tried were slower. Like you, I got the smallest times for > for key in input: > sum_ += weights[key] but I didn't get as much of a difference as you did. I surmise that in using the sum() variations, that the entire sequence was constructed first, and then iterated over. In the non-sum() versions, no new sequence had to be constructed first, so it would make sense for the latter to be slower. From list1 at tompassin.net Wed Mar 15 11:12:46 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 15 Mar 2023 11:12:46 -0400 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> Message-ID: On 3/15/2023 11:01 AM, Chris Angelico wrote: > On Thu, 16 Mar 2023 at 01:26, David Raymond wrote: >> I'm not quite sure why the built-in sum functions are slower than the for loop, >> or why they're slower with the generator expression than with the list comprehension. > > For small-to-medium data sizes, genexps are slower than list comps, > but use less memory. (At some point, using less memory translates > directly into faster runtime.) But even the sum-with-genexp version is > notably faster than reduce. > > Is 'weights' a dictionary? You're iterating over it, then subscripting > every time. If it is, try simply taking the sum of weights.values(), > as this should be significantly faster. It's a list. From rosuav at gmail.com Wed Mar 15 11:20:39 2023 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Mar 2023 02:20:39 +1100 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> Message-ID: On Thu, 16 Mar 2023 at 02:14, Thomas Passin wrote: > > On 3/15/2023 11:01 AM, Chris Angelico wrote: > > On Thu, 16 Mar 2023 at 01:26, David Raymond wrote: > >> I'm not quite sure why the built-in sum functions are slower than the for loop, > >> or why they're slower with the generator expression than with the list comprehension. > > > > For small-to-medium data sizes, genexps are slower than list comps, > > but use less memory. (At some point, using less memory translates > > directly into faster runtime.) But even the sum-with-genexp version is > > notably faster than reduce. > > > > Is 'weights' a dictionary? You're iterating over it, then subscripting > > every time. If it is, try simply taking the sum of weights.values(), > > as this should be significantly faster. > > It's a list. > Then I'm very confused as to how things are being done, so I will shut up. There's not enough information here to give performance advice without actually being a subject-matter expert already. ChrisA From morphex at gmail.com Wed Mar 15 11:22:53 2023 From: morphex at gmail.com (Morten W. Petersen) Date: Wed, 15 Mar 2023 16:22:53 +0100 Subject: =- and -= snag In-Reply-To: References: Message-ID: I don't remember making such a mistake ever before, but it might have happened. -= is a convenient operator so I've probably used it a lot. Anyway, I found that flake8 flagged this as E225 missing whitespace around operator and it's the only linter of pylint, flake8 and pyflake that detects this. Regards, Morten On Wed, Mar 15, 2023 at 5:32?AM Gilmeh Serda wrote: > On Mon, 13 Mar 2023 22:26:20 +0100, Morten W. Petersen wrote: > > > numbers for calculations didn't add up. It went into negative numbers, > > when that shouldn't have been possible. > > We have all written code that makes us wonder why the compiler even > bothered with it and didn't give up on the first line. > > -- > Gilmeh > > If this fortune didn't exist, somebody would have invented it. > -- > https://mail.python.org/mailman/listinfo/python-list > -- I am https://leavingnorway.info Videos at https://www.youtube.com/user/TheBlogologue Twittering at http://twitter.com/blogologue Blogging at http://blogologue.com Playing music at https://soundcloud.com/morten-w-petersen Also playing music and podcasting here: http://www.mixcloud.com/morten-w-petersen/ On Google+ here https://plus.google.com/107781930037068750156 On Instagram at https://instagram.com/morphexx/ From David.Raymond at tomtom.com Wed Mar 15 11:44:47 2023 From: David.Raymond at tomtom.com (David Raymond) Date: Wed, 15 Mar 2023 15:44:47 +0000 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> Message-ID: > Then I'm very confused as to how things are being done, so I will shut > up. There's not enough information here to give performance advice > without actually being a subject-matter expert already. Short version: In this specific case "weights" is a 5,147 element list of floats, and "input" is a 10 element list of integers which has the indexes of the 10 elements in weights that he wants to add up. sum_ = 0 for key in input: sum_ += weights[key] vs sum_ = sum(weights[key] for key in input) vs... other ways From loris.bennett at fu-berlin.de Wed Mar 15 03:37:18 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Wed, 15 Mar 2023 08:37:18 +0100 Subject: Distributing program for Linux References: <87wn3jnxt9.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: <87bkkuqxch.fsf@debian-BULLSEYE-live-builder-AMD64> "Weatherby,Gerard" writes: > It?s really going to depend on the distribution and whether you have root access. I am interested in providing a package for people with root access for a variety of distributions. > If you have Ubuntu and root access, you can add the deadsnakes repo, > https://launchpad.net/~deadsnakes, and install whatever Python you > want. I myself have this part covered via EasyBuild, https://easybuild.io/, which will work on any distro. How anybody else installs a given version Python will be left as an exercise for them (potential users of the software are however unlikely to be using Ubuntu). > The default ?python3? remains but you can called a specific Python, (e.g. python3.10). > > A typical shebang line would be: > > #!/usr/bin/env python3.10 I am currently using poetry to build the package and uses a 'scripts' section in the pyproject.toml file to produce stubs to call the main program. These have the shebang #!/usr/bin/python3 So if I can get poetry to use '/usr/bin/env' instead, then I can probably just rely on whatever mechanism other people use to switch between Python versions to do the right thing. Cheers, Loris > From: Python-list > on behalf of Loris Bennett > Date: Tuesday, March 14, 2023 at 12:27 PM > To: python-list at python.org > Subject: Distributing program for Linux > *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** > > Hi, > > If I write a system program which has Python >= 3.y as a dependency, > what are the options for someone whose Linux distribution provides > Python 3.x, where x < y? > > I am aware that an individual user could use (mini)conda to install a > more recent version of Python in his/her home directory, but I am > interested in how root would install such a program. > > Cheers, > > Loris > > -- > This signature is currently under constuction. > -- > https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!l02A4qczH46l1ScA8yisiIwlDKh96sy16woPSOSABWqym4b6dBtHzExfFwZsnPDezDwDqaM0fdCMs3080WQQZ-b5OghOOpI$ -- Dr. Loris Bennett (Herr/Mr) ZEDAT, Freie Universit?t Berlin From loris.bennett at fu-berlin.de Wed Mar 15 08:27:25 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Wed, 15 Mar 2023 13:27:25 +0100 Subject: Distributing program for Linux References: <87wn3jnxt9.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: <87y1nyqjwy.fsf@hornfels.zedat.fu-berlin.de> Anssi Saari writes: > "Loris Bennett" writes: > >> I am aware that an individual user could use (mini)conda to install a >> more recent version of Python in his/her home directory, but I am >> interested in how root would install such a program. > > Root would install the script and required Python version somewhere > depending any site specific practices and then use things like pyenv, > stow, environment modules or whatever to give the users access to it. The program is not for normal users, but is a system program. Many admins who might install the program will be using environment modules, so that, coupled with setting #!/usr/bin/env python3 for the scripts, looks like it might be a reasonable solution. > Root might even package your script with the interpreter required into > one binary. See Tools/freeze in the source distribution. Well, anyone who has the sources can do that, if so inclined. Personally, I already have enough versions of Python (currently 12 versions installed via EasyBuild plus the 2 from the OS itself) without creating fat binaries which contain a copy of one of those version. Cheers, Loris -- This signature is currently under constuction. From loris.bennett at fu-berlin.de Wed Mar 15 08:47:43 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Wed, 15 Mar 2023 13:47:43 +0100 Subject: Implementing a plug-in mechanism Message-ID: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de> Hi, I have written a program which, as part of the non-core functionality, contains a module to generate email. This is currently very specific to my organisation, so the main program contains import myorg.mailer This module is specific to my organisation in that it can ask an internal server to generate individualised salutations for a given UID which is known within the organisation. I want to share the code with other institutions, so I would like to 1. replace the organisation-specific mailer with a generic one 2. allow an organisation-specific mailer to be used instead of the generic one, if so desired Is importlib the way to go here or is there another approach? Cheers, Loris -- This signature is currently under constuction. From gweatherby at uchc.edu Wed Mar 15 13:09:52 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Wed, 15 Mar 2023 17:09:52 +0000 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> Message-ID: Sum is faster than iteration in the general case. Lifting a test program from Stack Overflow https://stackoverflow.com/questions/24578896/python-built-in-sum-function-vs-for-loop-performance, import timeit def sum1(): s = 0 for i in range(1000000): s += i return s def sum2(): return sum(range(1000000)) print('For Loop Sum:', timeit.timeit(sum1, number=100)) print( 'Built-in Sum:', timeit.timeit(sum2, number=100)) --- For Loop Sum: 7.726335353218019 Built-in Sum: 1.0398506000638008 --- From: Python-list on behalf of David Raymond Date: Wednesday, March 15, 2023 at 11:46 AM To: python-list at python.org Subject: RE: Debugging reason for python running unreasonably slow when adding numbers *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** > Then I'm very confused as to how things are being done, so I will shut > up. There's not enough information here to give performance advice > without actually being a subject-matter expert already. Short version: In this specific case "weights" is a 5,147 element list of floats, and "input" is a 10 element list of integers which has the indexes of the 10 elements in weights that he wants to add up. sum_ = 0 for key in input: sum_ += weights[key] vs sum_ = sum(weights[key] for key in input) vs... other ways -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!ikhJJxqJnllDHh6JKaMX8g2K-Ceq6ZiRDJxX7AbS-1AiBIrdAmA2qjBtYZbxel2mktyno1s9iJGo_zAl5alBIWxoVXE$ From gweatherby at uchc.edu Wed Mar 15 13:13:13 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Wed, 15 Mar 2023 17:13:13 +0000 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> Message-ID: Moving the generator out: import timeit thedata = [i for i in range(1_000_000)] def sum1(): s = 0 for i in thedata: s += i return s def sum2(): return sum(thedata) print('For Loop Sum:', timeit.timeit(sum1, number=100)) print( 'Built-in Sum:', timeit.timeit(sum2, number=100)) --- For Loop Sum: 6.984986504539847 Built-in Sum: 0.5175364706665277 From: Weatherby,Gerard Date: Wednesday, March 15, 2023 at 1:09 PM To: python-list at python.org Subject: Re: Debugging reason for python running unreasonably slow when adding numbers Sum is faster than iteration in the general case. Lifting a test program from Stack Overflow https://stackoverflow.com/questions/24578896/python-built-in-sum-function-vs-for-loop-performance, import timeit def sum1(): s = 0 for i in range(1000000): s += i return s def sum2(): return sum(range(1000000)) print('For Loop Sum:', timeit.timeit(sum1, number=100)) print( 'Built-in Sum:', timeit.timeit(sum2, number=100)) --- For Loop Sum: 7.726335353218019 Built-in Sum: 1.0398506000638008 --- From: Python-list on behalf of David Raymond Date: Wednesday, March 15, 2023 at 11:46 AM To: python-list at python.org Subject: RE: Debugging reason for python running unreasonably slow when adding numbers *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** > Then I'm very confused as to how things are being done, so I will shut > up. There's not enough information here to give performance advice > without actually being a subject-matter expert already. Short version: In this specific case "weights" is a 5,147 element list of floats, and "input" is a 10 element list of integers which has the indexes of the 10 elements in weights that he wants to add up. sum_ = 0 for key in input: sum_ += weights[key] vs sum_ = sum(weights[key] for key in input) vs... other ways -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!ikhJJxqJnllDHh6JKaMX8g2K-Ceq6ZiRDJxX7AbS-1AiBIrdAmA2qjBtYZbxel2mktyno1s9iJGo_zAl5alBIWxoVXE$ From gweatherby at uchc.edu Wed Mar 15 13:18:52 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Wed, 15 Mar 2023 17:18:52 +0000 Subject: Implementing a plug-in mechanism In-Reply-To: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de> References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de> Message-ID: Yes, that works, and I?ve used that on a couple of projects. Another alternative is defining an Abstract Base Class, https://docs.python.org/3/library/abc.html, and having an institution-specific implementation passed into your module. From: Python-list on behalf of Loris Bennett Date: Wednesday, March 15, 2023 at 1:03 PM To: python-list at python.org Subject: Implementing a plug-in mechanism *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Hi, I have written a program which, as part of the non-core functionality, contains a module to generate email. This is currently very specific to my organisation, so the main program contains import myorg.mailer This module is specific to my organisation in that it can ask an internal server to generate individualised salutations for a given UID which is known within the organisation. I want to share the code with other institutions, so I would like to 1. replace the organisation-specific mailer with a generic one 2. allow an organisation-specific mailer to be used instead of the generic one, if so desired Is importlib the way to go here or is there another approach? Cheers, Loris -- This signature is currently under constuction. -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!izCZs2X5PFeGpCF4TrtdDABzPqCFFT5i89Zsu-msRJAIpyWZYybdHDOFdxno9J3JvpNsRRQK9w72qgYj0MjlB2L-LsVXW1o$ From PythonList at DancesWithMice.info Wed Mar 15 14:45:18 2023 From: PythonList at DancesWithMice.info (dn) Date: Thu, 16 Mar 2023 07:45:18 +1300 Subject: Implementing a plug-in mechanism In-Reply-To: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de> References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de> Message-ID: On 16/03/2023 01.47, Loris Bennett wrote: > I have written a program which, as part of the non-core functionality, > contains a module to generate email. This is currently very specific > to my organisation, so the main program contains > > import myorg.mailer > > This module is specific to my organisation in that it can ask an > internal server to generate individualised salutations for a given UID > which is known within the organisation. > > I want to share the code with other institutions, so I would like to > > 1. replace the organisation-specific mailer with a generic one > 2. allow an organisation-specific mailer to be used instead of the > generic one, if so desired This may call for the plug-in pattern, ie the user will choose whether to plug-in the specific, or the generic, module. In Python, we would tend to use a Dependency Injection approach (one of Uncle Bob's SOLID principles). There's a rather abstract description of the plugin pattern at https://martinfowler.com/eaaCatalog/plugin.html OpenClassrooms has a more practical discussion at https://openclassrooms.com/en/courses/6397806-design-your-software-architecture-using-industry-standard-patterns/6896171-plug-in-architecture There is a PyPi library called pluggy (not used it). I've used informal approaches using an ABC as a framework/reminder (see @George's response). -- Regards, =dn From aapost at idontexist.club Wed Mar 15 15:19:46 2023 From: aapost at idontexist.club (aapost) Date: Wed, 15 Mar 2023 15:19:46 -0400 Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app In-Reply-To: References: Message-ID: On 3/15/23 07:37, John O'Hagan wrote: > On Tue, 2023-03-14 at 16:22 -0400, aapost wrote: >> On 3/14/23 06:54, John O'Hagan wrote: >>> It works up to a point - I can cycle through the images by clicking >>> the >>> button - but if I mouse-click on the displayed image (e.g. to use >>> the >>> zooming and panning features of cv2), nothing happens, and a few >>> seconds later the image greys out and a popup appears saying >>> "'Unknown' >>> is not responding" and giving the option of waiting or forcing >>> close >>> (but sometimes these options are greyed out too). Clicking "wait", >>> if >>> available, closes the popup but it comes back a few seconds later. >>> If I >>> then click on the tkinter window titlebar, the popup changes >>> to?"'Tk' >>> is not responding". Clicking on the button still works and after a >>> few >>> clicks the popup closes. > > [...] > >>> I think this particular popup is a Gnome thing, but AIUI most DEs >>> have >>> something similar to detect stuck apps. But the app is not stuck. >>> >>> I suspect this is some kind of interaction between the call to >>> cv2.waitKey (which is necessary but I've never understood why!) and >>> the >>> tkinter event loop, but it's beyond my knowledge. >>> >>> Any suggestions about causes or workarounds? >>> >>> Thanks >>> >>> -- >>> >>> John >>> >>> >> >> >> I don't get any of the zoom/panning behavior with waitKey(1). But a >> couple notes from the web: >> >> >> https://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html >> >> Note >> >> This function should be followed by waitKey function which displays >> the >> image for specified milliseconds. Otherwise, it won?t display the >> image. >> For example, waitKey(0) will display the window infinitely until any >> keypress (it is suitable for image display). waitKey(25) will display >> a >> frame for 25 ms, after which display will be automatically closed. >> (If >> you put it in a loop to read videos, it will display the video >> frame-by-frame) >> >> https://pythonexamples.org/python-opencv-imshow/ >> >> cv2.waitKey(0) is important for holding the execution of the python >> program at this statement, so that the image window stays visible. If >> you do not provide this statement, cv2.imshow() executes in fraction >> of >> a second and the program closes all the windows it opened, which >> makes >> it almost impossible to see the image on the window. >> >> if I change waitKey to 0, I get the ability to zoom/pan, but it >> places >> the tk window in a blocked state because it is waiting on cv2 to >> return. >> If I hit the ESC key, it releases the wait and gives control back to >> the >> tk window, allowing me to press show again to continue to the next >> image. >> >> I can try to change waitKey to a high ms like 10000000 and have >> zoom/pan >> for that amount of time before it gives control back to tk (not a >> sensical approach). >> >> The fact that you can still see the image after tk takes back control >> is >> I believe just a matter of design, some examples show >> cv2.destroyAllWindows() after waitKey(0) to clean that up, but of >> course >> if you are reusing the same window, that destroys the target. >> >> You can resolve that if you move >> cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN) >> cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN, >> cv2.WINDOW_FULLSCREEN) >> >> to inside the show, and destroy it after the wait, and make waitKey >> 0, >> this allows creation/cleanup of that window per image >> >> Hitting ESC when done zooming/panning on each image to get back to >> tk. > > Thanks for your reply. > > I'm afraid in the real app it won't be practical to have no gui control > while viewing images. > > But your suggestions have made me realise that my issue has nothing to > do with tkinter, it seems to be the way imshow is supposed to work. > This code gives the same behaviour described above: > > cv2.imshow('W', array) > cv2.waitKey(100) > time.sleep(20) > > I've seen the docs you mention that say the window will close if no > keypress happens within the waitKey time, but that doesn't seem to be > what happens as you say. After waitKey returns, the image remains and > everything works, but for some reason the desktop complains about an > unresponsive app. > > You can use cv2 to display video with: > > while 1: > frame = camera.read() #pseudocode > cv2.imshow('W', frame) > cv2.waitKey(1) > > (In fact this used to work without waitKey if you called > cv2.startWindowThread() after creating the window, but that stopped > working at some point.) > > The fact that this works, presumably because the image is being > replaced often enough, suggested the following workaround to my > problem, using a call to after() to re-display the current image before > the desktop starts complaining: > > images=[cv2.imread(i) for i in ('a.jpg', 'b.jpg', 'c.jpg')] > > cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN) > cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN, > cv2.WINDOW_FULLSCREEN) > > counter=[0] > > image = [None] > > def show(): > im = images[counter[0] % 3] > cv2.imshow('W', im) > cv2.waitKey(1) > image[:] = [im] > counter[0] += 1 > > root=Tk() > root.wm_attributes("-topmost", 1) > b=Button(root, text=' Show ', command=show) > b.pack() > > def update(): > if image[0] is not None: > cv2.imshow('W', image[0]) > cv2.waitKey(1) > root.after(1000, update) > > update() > > mainloop() > > > Not ideal, but I'm starting to think that despite the "highgui" label, > cv2.imshow is not really suited for integration into a gui. Which is a > shame because it's so damn fast! Yep, it was just a solution for the extent of the snippet. I don't have any easy fixes for the single thread blocking issue as I have not needed to investigate any UI blocking situations yet (if anyone has experience in that they can chime in, or you may need to ask about blocking/threading solutions/examples in regard to imshow on a cv2 specific forum, some sort of entirely different approach may be needed). To clarify the docs, it does not say "close if no key presses", it says 2 different things. 2nd part being, Setting the ms will close the window after the time regardless. The wording of the "displaying the window indefinitely until any keypress" - when 0, does not say anything about closing, so the until a keypress is unclear as to what that means, as any keypress when it is 0 definitely does not close it. They do activate the pan/zoom, and ability to ESC though.. Also to clarify (just in case), waitKey is in ms, and time.sleep is in seconds, so waitKey 100 is 0.1, the equivalent to time.sleep(20) would be waitKey(20000) The likely reason the desktop is complaining about an unresponsive app is that even though you still see that image, even at 100 ms (0.1s) the window you are clicking on by that time is technically already dead and closed, just not cleaned up. Additionally at least one of the error messages you were getting were in regard to qt (one of the graphical options under the hood), my understanding is that qt has some added controls for imshow that show up in a toolbar above the image (I don't have them so I don't see them). A sort of hypothetical guess, but it might be that those features are getting launched, but when they don't have the live imshow to operate on, they choke and the OS steps in (could be wrong). Does the update solve your problem in practice though? That is just a loop that makes the imshow live again for 1 ms, then pauses for 1 second, then runs recursively. Potentially indefinitely delaying anything from being flagged as stuck. I assume that doesn't give you the pan/zoom ability either (at least it doesn't on mine). From list1 at tompassin.net Wed Mar 15 15:42:10 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 15 Mar 2023 15:42:10 -0400 Subject: Implementing a plug-in mechanism In-Reply-To: References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <6dd3ac28-d877-d5bf-a2b3-7fc72f2292c1@tompassin.net> On 3/15/2023 2:45 PM, dn via Python-list wrote: > On 16/03/2023 01.47, Loris Bennett wrote: >> I have written a program which, as part of the non-core functionality, >> contains a module to generate email.? This is currently very specific >> to my organisation, so the main program contains >> >> ?? import myorg.mailer >> >> This module is specific to my organisation in that it can ask an >> internal server to generate individualised salutations for a given UID >> which is known within the organisation. >> >> I want to share the code with other institutions, so I would like to >> >> ?? 1. replace the organisation-specific mailer with a generic one >> ?? 2. allow an organisation-specific mailer to be used instead of the >> ????? generic one, if so desired > > This may call for the plug-in pattern, ie the user will choose whether > to plug-in the specific, or the generic, module. > > In Python, we would tend to use a Dependency Injection approach (one of > Uncle Bob's SOLID principles). [snip] Here is (slightly modified) plugin code I'm using in one project. You could use a naming convention to see if there is a plugin for a specific organizations, or each module could contain a UID variable which you could inspect to find the desired one. This code is under the MIT License, so feel free to adapt it if you like. def import_all_plugins(plugins_import_list, plugin_dir): """Import modules from the plugins directory and return a list of them. If plugins_import_list is not empty or None, only import the ones listed there. Otherwise import all ".py" files. RETURNS a list of successfully imported modules. """ modules = [] if not plugins_import_list: plugins_import_list = [] for root, dirs, files in os.walk(plugin_dir): if root == plugin_dir: break for f in files: f, ext = os.path.splitext(f) if ext == '.py': plugins_import_list.append(f) for f in plugins_import_list: try: mod = importlib.import_module(f'plugins.{f}') modules.append(mod) except ImportError as e: print(f'{__name__}: {f} plugin: {e}') continue return modules From gweatherby at uchc.edu Wed Mar 15 18:06:18 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Wed, 15 Mar 2023 22:06:18 +0000 Subject: Implementing a plug-in mechanism In-Reply-To: <6dd3ac28-d877-d5bf-a2b3-7fc72f2292c1@tompassin.net> References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de> <6dd3ac28-d877-d5bf-a2b3-7fc72f2292c1@tompassin.net> Message-ID: I do something similar to Thomas. (Also MIT licensed). I like objects. I like type hints. Each plugin needs to have check and purpose functions and accepts either PluginSpec (by default) or AddonSpec if it defines addon = True This requires a single-level plugin directory with no extra files in it (unless they start with _, like __init__.py) And I should use os.path.splitext but I forget what?s it called and find it easier just to split. # noinspection PyUnresolvedReferences @dataclass class NamedModule: """Datacheck module and its name""" mod: object name: str def __post_init__(self): """Validate attributes""" assert hasattr(self.mod, 'check') assert hasattr(self.mod, 'purpose') def check(self, inspec: Union[PluginSpec, AddonSpec]) -> PluginResult: return self.mod.check(inspec) @property def purpose(self) -> str: return self.mod.purpose() @property def addon(self) -> bool: """Return true if this module uses AddonSpec""" return getattr(self.mod, 'addon', False) class Integrity: @property def plugins(self) -> List[NamedModule]: """Get list of plugins by scanning plugin directory""" modules = [] us = os.path.abspath(__file__) plugin_dir = os.path.join(os.path.dirname(us), 'plugins') de: os.DirEntry for de in os.scandir(plugin_dir): if not de.name.startswith('_'): n = de.name.split('.')[0] mod = importlib.import_module(f'.plugins.{n}', 'dataintegrity') modules.append(NamedModule(mod, n)) return modules From list1 at tompassin.net Wed Mar 15 18:38:09 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 15 Mar 2023 18:38:09 -0400 Subject: Implementing a plug-in mechanism In-Reply-To: References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de> <6dd3ac28-d877-d5bf-a2b3-7fc72f2292c1@tompassin.net> Message-ID: On 3/15/2023 6:06 PM, Weatherby,Gerard wrote: > I do something similar to Thomas. (Also MIT licensed). I like objects. I like type hints. > > Each plugin needs to have check and purpose functions and accepts either PluginSpec (by default) or AddonSpec if it defines addon = True I omitted the checks because they specific to the use, so I thought they would just be a bit confusing. From clint.olsen at gmail.com Wed Mar 15 15:28:49 2023 From: clint.olsen at gmail.com (Clint Olsen) Date: Wed, 15 Mar 2023 12:28:49 -0700 (PDT) Subject: Running asyncio.run() more than once In-Reply-To: <1d6965c8-81c4-4bcd-b632-4f7e12bf706dn@googlegroups.com> References: <1d6965c8-81c4-4bcd-b632-4f7e12bf706dn@googlegroups.com> Message-ID: On Monday, March 13, 2023 at 11:32:23?PM UTC-7, Clint Olsen wrote: > We have an application that involves submitting hundreds to thousands of jobs to a shared computing resource, and we're using asyncio to do so because it is far less overhead than threading or multiprocessing for the bookkeeping required to keep track of all these jobs. It makes extensive use of asyncio.create_subprocess_exec(). This was developed mostly in Python 3.9.7. Good news! I did end up finding the source of the problem. I kept looking for the use of global data as a potential source of bugs and didn't really find anything there. I did fix some potential signal handler problems. However I had this particular piece of code that I needed to follow my processes. watcher = asyncio.FastChildWatcher() watcher.attach_loop(asyncio.get_event_loop()) asyncio.set_child_watcher(watcher) Since async reuses the same event loop on successive calls, doing this again is bad. I just needed to ensure I only set this once. Thanks, -Clint From aapost at idontexist.club Wed Mar 15 17:29:49 2023 From: aapost at idontexist.club (aapost) Date: Wed, 15 Mar 2023 17:29:49 -0400 Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app In-Reply-To: References: Message-ID: On 3/15/23 07:37, John O'Hagan wrote: > On Tue, 2023-03-14 at 16:22 -0400, aapost wrote: >> On 3/14/23 06:54, John O'Hagan wrote: > Doing a quick read, tkinter is not threadsafe, so diving in to a threading solution is probably not the best approach. But just to throw out another possible solution to see if you can find a "good enough" work around that fits your desired behavior. You could spawn the imshow as it's own program: file2: sp.py import sys import cv2 import tkinter as tk def show(img, root): cv2.namedWindow(str(root), cv2.WND_PROP_FULLSCREEN) cv2.setWindowProperty(str(root), cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) cv2.imshow(str(root), cv2.imread(img)) cv2.waitKey(0) cv2.destroyAllWindows() exit() root=tk.Tk() show(sys.argv[1], root) tk.mainloop() file1:main.py import cv2 import tkinter as tk import subprocess images=['c.jpg', 'b.jpg', 'c.jpg'] control = { "counter" : 0, "pid": None } def show(control): if control["pid"]: control["pid"].kill() control["pid"] = subprocess.Popen(["python", "sp.py", images[control["counter"] % len(images)]]) control["counter"] += 1 root=tk.Tk() root.wm_attributes("-topmost", 1) tk.Button(root, text=' Show ', command=lambda: show(control)).pack() tk.mainloop() refactor/design as needed, you track the pid, kill the existing on each subsequent show press. caveats would be that since it is an entirely separate program, if you close the main window, the other window will still linger until it is also closed. You could try to catch the close to run a .kill() on the subprocess if you want right before the exit, etc. But this gives control back to the main GUI since they are now independent of each other and not within the same thread. If they need to talk to each other in some way more than that, I am sure deeper design solutions could be thought up. From simon+python at bleah.co.uk Thu Mar 16 05:35:59 2023 From: simon+python at bleah.co.uk (Simon Ward) Date: Thu, 16 Mar 2023 09:35:59 +0000 Subject: Implementing a plug-in mechanism In-Reply-To: References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <20230316093559.GA5066@bleah.co.uk> On Thu, Mar 16, 2023 at 07:45:18AM +1300, dn via Python-list wrote: >There is a PyPi library called pluggy (not used it). I've used informal >approaches using an ABC as a framework/reminder (see @George's >response). typing.Protocol is also useful here as the plugin interface can be defined separately not requiring inheriting from an ABC. Simon -- A complex system that works is invariably found to have evolved from a simple system that works.?John Gall From roel at roelschroeven.net Thu Mar 16 06:08:12 2023 From: roel at roelschroeven.net (Roel Schroeven) Date: Thu, 16 Mar 2023 11:08:12 +0100 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> Message-ID: <0d8ed934-1016-9a83-fe4e-78a7171f7115@roelschroeven.net> Op 14/03/2023 om 8:48 schreef Alexander Nestorov: > I have the following code: > > ... > for i in range(151): # 150 iterations > ?? ... Nothing to do with your actual question and it's probably just a small oversight, but still I thought it was worth a mention: that comment does not accurately describe the code; the code is actually doing 151 iterations, numbered 0 up to and including 150. -- "I've come up with a set of rules that describe our reactions to technologies: 1. Anything that is in the world when you?re born is normal and ordinary and is just a natural part of the way the world works. 2. Anything that's invented between when you?re fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. 3. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams, The Salmon of Doubt From aapost at idontexist.club Thu Mar 16 04:21:30 2023 From: aapost at idontexist.club (aapost) Date: Thu, 16 Mar 2023 04:21:30 -0400 Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app In-Reply-To: References: Message-ID: On 3/15/23 07:37, John O'Hagan wrote: > On Tue, 2023-03-14 at 16:22 -0400, aapost wrote: >> On 3/14/23 06:54, John O'Hagan wrote: > > [...] >>> Read an alternative description of the waitKey behavior >For example, waitKey(0) will display the window infinitely until any keypress (it is suitable for image display). waitKey(25) will display a frame and wait approximately 25 ms for a key press (suitable for displaying a video frame-by-frame). To remove the window, use cv::destroyWindow. I went back to double check and I stand corrected on the "any keypress" part. Any keypress on the 'keyboard' does break the wait (as I incorrectly concluded and assumed only ESC did). It is still slightly ambiguous in explaining that when using 25ms, keypress or not, the wait breaks at 25ms (or before that if you press a keyboard key). For my setup the window is stale at that point, no controls, just a stale frame behind the tkinter window that needs to be destroyed or reused. Whether that is the exact behavior on all set-ups isn't clear, the note further uses the ambiguous phrasing "might". >Note: This function should be followed by a call to cv::waitKey or cv::pollKey to perform GUI housekeeping tasks that are necessary to actually show the given image and make the window respond to mouse and keyboard events. Otherwise, it won?t display the image and the window might lock up. It seems with the several variations, behavior varies between them, like one comment saying startWindowThread when using c++ and gtk allows you to not use waitKey (not the case here.. it seems -- changing my language to not misspeak, lol). I haven't come across any examples beyond imshow running stand-alone as in my solution suggestion 2. But waitKey does return a keyvalue for the keypess to allow extending the functionality, so you can grab it, do something, and go right back to waiting, I haven't seen any use of this though. You can also leave out reference to tkinter all together when using startWindowThread: import sys import cv2 cv2.startWindowThread() cv2.namedWindow("W", cv2.WND_PROP_FULLSCREEN) cv2.setWindowProperty("W", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) cv2.imshow("W", cv2.imread(sys.argv[1])) while(1): a = cv2.waitKey(0) if a == 27:#ESC break #elif a == something else, do something cv2.destroyAllWindows() exit() But it still blocks if integrated in to the main tkinter thread, and appears to use tkinter under the hood. And as tkinter is considered thread-unsafe, the startWindowThread would only be ok when spawned as a separate process like the subprocess example. Anyway, apologies for the mistake on the any key part. From info at egenix.com Thu Mar 16 10:35:18 2023 From: info at egenix.com (eGenix Team) Date: Thu, 16 Mar 2023 15:35:18 +0100 Subject: =?UTF-8?Q?ANN=3a_Python_Meeting_D=c3=bcsseldorf_-_22=2e03=2e2023?= Message-ID: <443e6d60-8aff-93d2-e77e-d80091fab561@egenix.com> /This announcement is in German since it targets a local user group//meeting in D?sseldorf, Germany/ Ank?ndigung Python Meeting D?sseldorf - M?rz 2023 Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. *22.03.2023, 18:00 Uhr* Raum 1, 2.OG im B?rgerhaus Stadtteilzentrum Bilk D?sseldorfer Arcaden , Bachstr. 145, 40217 D?sseldorf Programm Bereits angemeldete Vortr?ge: Charlie Clark: ??? ??? "Eine neue XML Bibliothek: Pugixml" Marc-Andre Lemburg: ??? ??? "Data Analysis with OpenSearch ? Waiting times at the DUS airport" Arkadius Schuchhardt: ??? ??? "Concurrent data loading by using the thread producer-consumer pattern" Weitere Vortr?ge k?nnen gerne noch angemeldet werden. Bei Interesse, bitte unter info at pyddf.de melden. Startzeit und Ort Wir treffen uns um 18:00 Uhr im B?rgerhaus in den D?sseldorfer Arcaden. Das B?rgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet sich an der Seite der Tiefgarageneinfahrt der D?sseldorfer Arcaden. ?ber dem Eingang steht ein gro?es "Schwimm? in Bilk" Logo. Hinter der T?r direkt links zu den zwei Aufz?gen, dann in den 2. Stock hochfahren. Der Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt. >>> Eingang in Google Street View Corona Die Corona Einschr?nkungen sind mittlerweile aufgehoben worden. Vorsicht ist zwar immer noch geboten, aber jetzt jedem selbst ?berlassen. *?? Wichtig*: Bitte nur dann anmelden, wenn ihr absolut sicher seid, dass ihr auch kommt. Angesichts der begrenzten Anzahl Pl?tze, haben wir kein Verst?ndnis f?r kurzfristige Absagen oder No-Shows. Einleitung Das Python Meeting D?sseldorf ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet. Einen guten ?berblick ?ber die Vortr?ge bietet unser PyDDF YouTube-Kanal , auf dem wir Videos der Vortr?ge nach den Meetings ver?ffentlichen. Veranstaltet wird das Meeting von der eGenix.com GmbH , Langenfeld, in Zusammenarbeit mit Clark Consulting & Research , D?sseldorf: Format Das Python Meeting D?sseldorf nutzt eine Mischung aus (Lightning) Talks und offener Diskussion. Vortr?ge k?nnen vorher angemeldet werden, oder auch spontan w?hrend des Treffens eingebracht werden. Ein Beamer mit XGA Aufl?sung steht zur Verf?gung. (Lightning) Talk Anmeldung bitte formlos per EMail an info at pyddf.de Kostenbeteiligung Das Python Meeting D?sseldorf wird von Python Nutzern f?r Python Nutzer veranstaltet. Da Tagungsraum, Beamer, Internet und Getr?nke Kosten produzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,00 inkl. 19% Mwst. Sch?ler und Studenten zahlen EUR 5,00 inkl. 19% Mwst. Wir m?chten alle Teilnehmer bitten, den Betrag in bar mitzubringen. Anmeldung Da wir nur 25 Personen in dem angemieteten Raum empfangen k?nnen, m?chten wir bitten, sich vorher anzumelden. *Meeting Anmeldung* bitte per Meetup Weitere Informationen Weitere Informationen finden Sie auf der Webseite des Meetings: https://pyddf.de/ Viel Spa? ! -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Mar 16 2023) >>> Python Projects, Coaching and Support ... https://www.egenix.com/ >>> Python Product Development ... https://consulting.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 https://www.egenix.com/company/contact/ https://www.malemburg.com/ From loris.bennett at fu-berlin.de Thu Mar 16 12:02:37 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Thu, 16 Mar 2023 17:02:37 +0100 Subject: Implementing a plug-in mechanism References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de> <20230316093559.GA5066@bleah.co.uk> Message-ID: <878rfw4rc2.fsf@debian-BULLSEYE-live-builder-AMD64> Simon Ward writes: > On Thu, Mar 16, 2023 at 07:45:18AM +1300, dn via Python-list wrote: >> There is a PyPi library called pluggy (not used it). I've used >> informal approaches using an ABC as a framework/reminder (see >> @George's response). > > typing.Protocol is also useful here as the plugin interface can be > defined separately not requiring inheriting from an ABC. Thanks to all for the helpful suggestions. I realise that I don't actually need to be able to load a bunch of arbitrary plugins, but merely to be able to override one (or, perhaps later, more) piece of default behaviour. Therefore I think the following very simple scheme will work for me: $ tree -L 3 . ??? myproj ??? __init__.py ??? mailer.py ??? main.py ??? plugins ??? normanmailer.py Where main.py is #!/usr/bin/env python3 # -*- coding: utf-8 -*- if __name__ == "__main__": try: import plugin.mailer as mailer print("Found plugin.mailer") except ModuleNotFoundError: import mailer print("Found mailer") m = mailer.Mailer('abc') m.run() mailer.py is class Mailer(): def run(self): print("This is a generic Mailer object!") and plugins/normanmailer.py is class Mailer(): def run(self): print("This is a customized Mailer object!") This then gives me $ poetry run myproj\/main.py Found mailer This is a generic Mailer object! $ mv myproj/plugins/{norman,}mailer.py $ poetry run myproj\/main.py Found plugins.mailer This is a customized Mailer object! I suspect I was using slightly incorrect/misleading terminology. I don't want to be able to load arbitrary functionality via plugins, e.g. sending an email, dumping to a database, uploading to a cloud. That would, I far as I can tell, necessitate having some mechanism to select the functionality. Instead I just want to modify the behaviour of a piece of fixed functionality. e.g. sending a mail. So am I really talking about customisation here. Cheers, Loris -- This signature is currently under constuction. From PythonList at DancesWithMice.info Thu Mar 16 18:55:38 2023 From: PythonList at DancesWithMice.info (dn) Date: Fri, 17 Mar 2023 11:55:38 +1300 Subject: Friday finking: IDE 'macro expansions' Message-ID: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> It is a long, long, time since I've thrown one of these into the maelstrom of our musings. (have the nightmares receded?) Do you make use of your IDE's expansionist tendencies, and if-so, which ones? NB this is where vi/emacs enthusiasts start chuckling (polite term for 'insane cackling'). Hence the question's limitation to IDEs, cf 'editors'! Also: I'm talking 'PyCharm' because of the story, but others use Codium, Sublime Text, etc - which presumably offer equivalent features. Was helping a friend install PyCharm. Jumped into the Settings. Isn't it incredible how many there are? Idly noted that there are two short-cut or macro-expansion types of facilities: - Postfix Completion, (nothing to do with email or polish notation) and - Live Templates (again, we're not talking about jinja2) With both, one types an abbreviated-name and the IDE will expand it into appropriate code. For (LiveTemplate) example, typing compli and pressing Tab induces PyCharm to add the following to the program[me]: [ ! for ! in !drop-down menu! if ! ] It offers further typo-saving through the drop-down menu which lists a bunch of likely (iterable) candidates from amongst previously-written code. The action continues after selecting from the menu, by inviting completion of the other ("!") placeholders, in-turn. I haven't made use of such a tool, to-date - OK, yes, I have practised a high typing-speed (and accuracy). Puff, puff... Also, at the time, I'm thinking in 'code', rather than about what tool might implement said ideas. Do you make use of such expansionist-tendencies? Do you make use of other powerful features within the IDE, or are its editor functionalities employed at pretty-much the NotePad level? Web.Refs: https://www.jetbrains.com/help/pycharm/settings-postfix-completion.html https://www.jetbrains.com/help/pycharm/using-live-templates.html#live_templates_types -- Regards, =dn From mats at wichmann.us Thu Mar 16 19:29:44 2023 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 16 Mar 2023 17:29:44 -0600 Subject: Friday finking: IDE 'macro expansions' In-Reply-To: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> References: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> Message-ID: <7e166dcc-1e88-1e7c-77c5-4b2c2f5efe54@wichmann.us> On 3/16/23 16:55, dn via Python-list wrote: > It is a long, long, time since I've thrown one of these into the > maelstrom of our musings. > (have the nightmares receded?) > > > Do you make use of your IDE's expansionist tendencies, and if-so, which > ones? > > > NB this is where vi/emacs enthusiasts start chuckling (polite term for > 'insane cackling'). Hence the question's limitation to IDEs, cf 'editors'! > Also: I'm talking 'PyCharm' because of the story, but others use Codium, > Sublime Text, etc - which presumably offer equivalent features. > > > Was helping a friend install PyCharm. Jumped into the Settings. Isn't it > incredible how many there are? > > Idly noted that there are two short-cut or macro-expansion types of > facilities: > - Postfix Completion, (nothing to do with email or polish notation) and > - Live Templates (again, we're not talking about jinja2) > > > With both, one types an abbreviated-name and the IDE will expand it into > appropriate code. For (LiveTemplate) example, typing compli and pressing > Tab induces PyCharm to add the following to the program[me]: > > ??? [ ! for ! in !drop-down menu! if ! ] > > It offers further typo-saving through the drop-down menu which lists a > bunch of likely (iterable) candidates from amongst previously-written > code. The action continues after selecting from the menu, by inviting > completion of the other ("!") placeholders, in-turn. > > > I haven't made use of such a tool, to-date - OK, yes, I have practised a > high typing-speed (and accuracy). Puff, puff... > > Also, at the time, I'm thinking in 'code', rather than about what tool > might implement said ideas. > > > Do you make use of such expansionist-tendencies? > > Do you make use of other powerful features within the IDE, or are its > editor functionalities employed at pretty-much the NotePad level? Not sure the purpose of the "survey" but - no, I don't use these. IDEs are incredible things, but you need to invest yourself completely in them, basically live in them, or there's not that much payback. There's just too much to remember, and honestly, too much mouse movement needed, especially if you have a big screen. In the PyCharm case, the startup time is incredibly slow, so, since I don't "live in it", I don't use it much any more - there are some things it does superbly, but it's such a cost to fire it up just for those I pretty much don't bother any more. From list1 at tompassin.net Thu Mar 16 19:54:21 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 16 Mar 2023 19:54:21 -0400 Subject: Friday finking: IDE 'macro expansions' In-Reply-To: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> References: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> Message-ID: On 3/16/2023 6:55 PM, dn via Python-list wrote: > It is a long, long, time since I've thrown one of these into the > maelstrom of our musings. > (have the nightmares receded?) > > > Do you make use of your IDE's expansionist tendencies, and if-so, which > ones? > > > NB this is where vi/emacs enthusiasts start chuckling (polite term for > 'insane cackling'). Hence the question's limitation to IDEs, cf 'editors'! > Also: I'm talking 'PyCharm' because of the story, but others use Codium, > Sublime Text, etc - which presumably offer equivalent features. > > > Was helping a friend install PyCharm. Jumped into the Settings. Isn't it > incredible how many there are? > > Idly noted that there are two short-cut or macro-expansion types of > facilities: > - Postfix Completion, (nothing to do with email or polish notation) and > - Live Templates (again, we're not talking about jinja2) > > > With both, one types an abbreviated-name and the IDE will expand it into > appropriate code. For (LiveTemplate) example, typing compli and pressing > Tab induces PyCharm to add the following to the program[me]: > > ??? [ ! for ! in !drop-down menu! if ! ] > > It offers further typo-saving through the drop-down menu which lists a > bunch of likely (iterable) candidates from amongst previously-written > code. The action continues after selecting from the menu, by inviting > completion of the other ("!") placeholders, in-turn. > > > I haven't made use of such a tool, to-date - OK, yes, I have practised a > high typing-speed (and accuracy). Puff, puff... > > Also, at the time, I'm thinking in 'code', rather than about what tool > might implement said ideas. > > > Do you make use of such expansionist-tendencies? > > Do you make use of other powerful features within the IDE, or are its > editor functionalities employed at pretty-much the NotePad level? In general, I don't like a lot of popups and code completions, so I tend to avoid them. I don't even like automatic parens or brace insertion. They distract me, and often put the cursor somewhere I don't want it. Of course, for Python code I do like automatic indentation after a colon: if the cursor ends up in the right place, then I'm happy. If I'm using a plain editor, then I usually like EditPlus. It's not free but the cost is low and it's well worth it (but Windows only). It knows about file types, and can do various insertions and completions if you want (as I said, I mostly don't). I also use Notepad++, but I more often go with EditPlus. What I find more useful is matching brackets/parens/braces. Not inserting them but highlighting or (better) jumping to the matching one when asked. Otherwise I'm usually working in the Leo Editor, which is hard to explain in a few words but is a real gift, especially for Python programmers. It does have an abbreviation capability that I use a little, but so far mostly for inserting symbols like math and Greek letters. Leo is written in Python (with a Qt GUI) and you can easily get access to all its internals, so once you learn something about how it works, you can create scripts to do almost anything you want. The Leo Editor is an MIT-licensed project on GitHub (I know I sound very positive but despite that, it's not my project; it really can grow on you - if you are willing to climb the learning curve). From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Mar 16 20:06:01 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 16 Mar 2023 20:06:01 -0400 Subject: Friday finking: IDE 'macro expansions' In-Reply-To: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> References: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> Message-ID: On 2023-03-17 at 11:55:38 +1300, dn via Python-list wrote: > Do you make use of your IDE's expansionist tendencies, and if-so, which > ones? Expansionist tendencies. Nice phrase. :-) > NB this is where vi/emacs enthusiasts start chuckling (polite term for > 'insane cackling') ... Long time (since the 1980s, when you had to edit config.h and compile it yourself) insane emacs enthusiast and "Unix is my IDE" claimant here. I used one language that required a special editor because the "source code" was a semi-compiled byte stream instead of ASCII. A coworker once awarded me a black belt in vi for knowing how to indent and unindent code. They made me write in Java at my last job; that language encourages IDEs beause they deny that the underlying OS and tools exist at all. I used to say that some of my coworkers weren't writing Java, they were writing IntelliJ. Anyway, the short answer to your question is no. I think the main reason is that there are/were too many editors in too many contexts to start depending on such features. What happens if I'm editing on a target box instead of my desktop? What if I'm helping a coworker, and they use a different editor (different tools for different programmers)? > I haven't made use of such a tool, to-date - OK, yes, I have practised a > high typing-speed (and accuracy). Puff, puff... I, too, type relatively quickly, which definitely relieves some of the appeal. Saving a few keystrokes isn't worth the extra congnitive load to remember how to use those features. And by the time I edit the template, it's more keystrokes (and usually cursor motion and placeholder deletion keystrokes not related to the programming task at hand) than if I had typed the full code in the first place. > Also, at the time, I'm thinking in 'code', rather than about what tool might > implement said ideas. Exactly. Any excursion away from the programming language and the programming task at hand is disruptive. I did finally train myself to use Emacs' dabbrev-expand function, which completes the current "word" according to the previous occurrance of that word, which lets me use longer identifiers without having to type them out or copy/paste them. That said, I often find myself typing stuff out anyway, again because any deviation from writing code is a deviation from writing code. From grant.b.edwards at gmail.com Thu Mar 16 22:31:04 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 16 Mar 2023 19:31:04 -0700 (PDT) Subject: Friday finking: IDE 'macro expansions' References: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> Message-ID: <6413d0e8.920a0220.f0b83.09b4@mx.google.com> On 2023-03-16, Thomas Passin wrote: > In general, I don't like a lot of popups and code completions, so I > tend to avoid them. I don't even like automatic parens or brace > insertion. I _hate_ it when the "editor" decides to insert stuff I didn't type. There's an html editor I use occasionally that auto-inserts the closing tag when you type an opening tag. It's, always, 100% of the time, wrong. Either the tag ends up in the wrong place, or it's a duplicate because there was already a closing tag. > They distract me, and often put the cursor somewhere I don't want it. Maybe it matters how good a typist you are, but I don't really concentrate that hard on watching the letters show up on the screen, so any sort of "IDE know better than you do" stuff tends to trip me up. > Of course, for Python code I do like automatic indentation after a > colon: if the cursor ends up in the right place, then I'm happy. Yep, I do allow emacs to do auto indent. > If I'm using a plain editor, then I usually like EditPlus. It's not > free but the cost is low and it's well worth it (but Windows only). > It knows about file types, and can do various insertions and > completions if you want (as I said, I mostly don't). I also use > Notepad++, but I more often go with EditPlus. > > What I find more useful is matching brackets/parens/braces. Not > inserting them but highlighting or (better) jumping to the matching one > when asked. Same here. From simon+python at bleah.co.uk Fri Mar 17 05:32:33 2023 From: simon+python at bleah.co.uk (Simon Ward) Date: Fri, 17 Mar 2023 09:32:33 +0000 Subject: Friday finking: IDE 'macro expansions' In-Reply-To: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> References: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> Message-ID: <20230317093233.GA28476@bleah.co.uk> On Fri, Mar 17, 2023 at 11:55:38AM +1300, dn via Python-list wrote: >Do you make use of your IDE's expansionist tendencies, and if-so, which >ones? Unix (well, GNU/Linux) is my IDE ;) Simon From roel at roelschroeven.net Fri Mar 17 09:05:50 2023 From: roel at roelschroeven.net (Roel Schroeven) Date: Fri, 17 Mar 2023 14:05:50 +0100 Subject: Friday finking: IDE 'macro expansions' In-Reply-To: References: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> Message-ID: <02f48c79-ff5c-7953-0abb-fd99b14264b3@roelschroeven.net> Op 17/03/2023 om 0:54 schreef Thomas Passin: > What I find more useful is matching brackets/parens/braces.? Not > inserting them but highlighting or (better) jumping to the matching > one when asked. That is very helpful indeed. Even better than simply highlighting is (IMO) a thing called "Rainbow Braces" or "Bracket Pair Colorization" I recently learned about: both braces of a matching pair get the same color, while other pairs get other colors. I have to say I like it quite a lot. It's in VS Code these days; possible there are implementations or extensions for other editors and IDEs as well. -- "Most of us, when all is said and done, like what we like and make up reasons for it afterwards." -- Soren F. Petersen From simon+python at bleah.co.uk Fri Mar 17 09:38:34 2023 From: simon+python at bleah.co.uk (Simon Ward) Date: Fri, 17 Mar 2023 13:38:34 +0000 Subject: Friday finking: IDE 'macro expansions' In-Reply-To: <02f48c79-ff5c-7953-0abb-fd99b14264b3@roelschroeven.net> References: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> <02f48c79-ff5c-7953-0abb-fd99b14264b3@roelschroeven.net> Message-ID: <20230317133834.GB28476@bleah.co.uk> On Fri, Mar 17, 2023 at 02:05:50PM +0100, Roel Schroeven wrote: >Even better than simply highlighting is (IMO) a thing called "Rainbow >Braces" or "Bracket Pair Colorization" I recently learned about: both >braces of a matching pair get the same color, while other pairs get >other colors. I have to say I like it quite a lot. It's in VS Code >these days; possible there are implementations or extensions for other >editors and IDEs as well. VS Code also supports ?semantic highlighting?: Instead of simply highlighting syntax, highlight the same identifiers in the same colours, with the aim of helping you see them through the flow of the code. Simon -- A complex system that works is invariably found to have evolved from a simple system that works.?John Gall From list1 at tompassin.net Fri Mar 17 09:44:44 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 17 Mar 2023 09:44:44 -0400 Subject: Friday finking: IDE 'macro expansions' In-Reply-To: <20230317133834.GB28476@bleah.co.uk> References: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> <02f48c79-ff5c-7953-0abb-fd99b14264b3@roelschroeven.net> <20230317133834.GB28476@bleah.co.uk> Message-ID: On 3/17/2023 9:38 AM, Simon Ward wrote: > On Fri, Mar 17, 2023 at 02:05:50PM +0100, Roel Schroeven wrote: >> Even better than simply highlighting is (IMO) a thing called "Rainbow >> Braces" or "Bracket Pair Colorization" I recently learned about: both >> braces of a matching pair get the same color, while other pairs get >> other colors. I have to say I like it quite a lot. It's in VS Code >> these days; possible there are implementations or extensions for other >> editors and IDEs as well. > > VS Code also supports ?semantic highlighting?: Instead of simply > highlighting syntax, highlight the same identifiers in the same colours, > with the aim of helping you see them through the flow of the code. Even with a simple "Find" command I don't like that behavior, let alone for programming. I find that all those other marked instances make it harder for me to read the surrounding material. They are good for moving from one instance to another, but otherwise they get in the way for me. From manta103g at gmail.com Thu Mar 16 20:07:33 2023 From: manta103g at gmail.com (a a) Date: Thu, 16 Mar 2023 17:07:33 -0700 (PDT) Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? Message-ID: <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> Crash report: Problem Caption: Problem Event Name: APPCRASH Application name: python.exe Application version: 3.8.7150.1013 Application time signature: 5fe0df5a Error module name: _multiarray_umath.cp38-win32.pyd Version of the module with the error: 0.0.0.0 Time signature of the module with the error: 63dfe4cf Exception code: c000001d Exception offset: 000269c9 Operating system version: 6.1.7601.2.1.0.256.48 Regional Settings ID: 1045 Additional information 1: 0a9e Additional information 2: 0a9e372d3b4ad19135b953a78882e789 Additional information 3: 0a9e Additional information 4: 0a9e372d3b4ad19135b953a78882e789 From list1 at tompassin.net Fri Mar 17 11:02:36 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 17 Mar 2023 11:02:36 -0400 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> References: <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> Message-ID: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> On 3/16/2023 8:07 PM, a a wrote: > Crash report: > > Problem Caption: > Problem Event Name: APPCRASH > Application name: python.exe > Application version: 3.8.7150.1013 > Application time signature: 5fe0df5a > Error module name: _multiarray_umath.cp38-win32.pyd > Version of the module with the error: 0.0.0.0 > Time signature of the module with the error: 63dfe4cf > Exception code: c000001d > Exception offset: 000269c9 > Operating system version: 6.1.7601.2.1.0.256.48 > Regional Settings ID: 1045 > Additional information 1: 0a9e > Additional information 2: 0a9e372d3b4ad19135b953a78882e789 > Additional information 3: 0a9e > Additional information 4: 0a9e372d3b4ad19135b953a78882e789 This exception has been reported to have many causes, but one possibility seems to be that your computer may not support an advanced instruction set that the .pyd was compiled for. I found this one specifically mentioned on the Internet: Advanced Vector Extensions. If that were the case, you would either need to find a different version of the module, or upgrade the computer/OS. It would be worth trying to downgrade the multiarray version to an earlier one and see if that fixes the problem. From learn2program at gmail.com Fri Mar 17 13:13:10 2023 From: learn2program at gmail.com (Alan Gauld) Date: Fri, 17 Mar 2023 17:13:10 +0000 Subject: Fwd: Friday finking: IDE 'macro expansions' In-Reply-To: References: Message-ID: <663495e3-ca12-0370-3b2b-63bcc5d65bc8@gmail.com> Oops! I meant to send this to the group not just Dave. -------- Forwarded Message -------- On 16/03/2023 22:55, dn via Python-list wrote: > Do you make use of your IDE's expansionist tendencies, and if-so, which > ones? When I'm writing Java/C++/C# yes, I need all the IDE help I can get. Netbeans or Eclipse being my tools of choice. And in my Windows days I used Delphi and Smalltalk/V which both pretty much only exist within their own IDEs and I used their features extensively. When writing Python I use IDLE, or vim for bigger jobs. IDLE does have some suggestions and auto tricks but I don't always use them. In vim I use auto-indent and that's about it. -- 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 Fri Mar 17 13:55:37 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 17 Mar 2023 13:55:37 -0400 Subject: Fwd: Friday finking: IDE 'macro expansions' In-Reply-To: <663495e3-ca12-0370-3b2b-63bcc5d65bc8@gmail.com> References: <663495e3-ca12-0370-3b2b-63bcc5d65bc8@gmail.com> Message-ID: <4ef507c9-0ca3-2968-e468-cb51d621ff3f@tompassin.net> On 3/17/2023 1:13 PM, Alan Gauld wrote: > Oops! I meant to send this to the group not just Dave. > > > -------- Forwarded Message -------- > > On 16/03/2023 22:55, dn via Python-list wrote: > >> Do you make use of your IDE's expansionist tendencies, and if-so, which >> ones? > > When I'm writing Java/C++/C# yes, I need all the IDE help I can get. > Netbeans or Eclipse being my tools of choice. And in my Windows days > I used Delphi and Smalltalk/V which both pretty much only exist within > their own IDEs and I used their features extensively. Back when Delphi first came out, when I first used it, I don't remember any IDE; one just used a text editor. > When writing Python I use IDLE, or vim for bigger jobs. > IDLE does have some suggestions and auto tricks but I don't > always use them. In vim I use auto-indent and that's about it. > From python at mrabarnett.plus.com Fri Mar 17 14:14:22 2023 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Mar 2023 18:14:22 +0000 Subject: Fwd: Friday finking: IDE 'macro expansions' In-Reply-To: <4ef507c9-0ca3-2968-e468-cb51d621ff3f@tompassin.net> References: <663495e3-ca12-0370-3b2b-63bcc5d65bc8@gmail.com> <4ef507c9-0ca3-2968-e468-cb51d621ff3f@tompassin.net> Message-ID: On 2023-03-17 17:55, Thomas Passin wrote: > On 3/17/2023 1:13 PM, Alan Gauld wrote: >> Oops! I meant to send this to the group not just Dave. >> >> >> -------- Forwarded Message -------- >> >> On 16/03/2023 22:55, dn via Python-list wrote: >> >>> Do you make use of your IDE's expansionist tendencies, and if-so, which >>> ones? >> >> When I'm writing Java/C++/C# yes, I need all the IDE help I can get. >> Netbeans or Eclipse being my tools of choice. And in my Windows days >> I used Delphi and Smalltalk/V which both pretty much only exist within >> their own IDEs and I used their features extensively. > > Back when Delphi first came out, when I first used it, I don't remember > any IDE; one just used a text editor. > I used Turbo Pascal and then Delphi 3 or 4, back when it was still Borland. >> When writing Python I use IDLE, or vim for bigger jobs. >> IDLE does have some suggestions and auto tricks but I don't >> always use them. In vim I use auto-indent and that's about it. >> From PythonList at DancesWithMice.info Fri Mar 17 17:00:11 2023 From: PythonList at DancesWithMice.info (dn) Date: Sat, 18 Mar 2023 10:00:11 +1300 Subject: Friday finking: IDE 'macro expansions' In-Reply-To: References: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> <02f48c79-ff5c-7953-0abb-fd99b14264b3@roelschroeven.net> <20230317133834.GB28476@bleah.co.uk> Message-ID: On 18/03/2023 02.44, Thomas Passin wrote: > On 3/17/2023 9:38 AM, Simon Ward wrote: >> On Fri, Mar 17, 2023 at 02:05:50PM +0100, Roel Schroeven wrote: >>> Even better than simply highlighting is (IMO) a thing called "Rainbow >>> Braces" or "Bracket Pair Colorization" I recently learned about: both >>> braces of a matching pair get the same color, while other pairs get >>> other colors. I have to say I like it quite a lot. It's in VS Code >>> these days; possible there are implementations or extensions for >>> other editors and IDEs as well. >> >> VS Code also supports ?semantic highlighting?: Instead of simply >> highlighting syntax, highlight the same identifiers in the same >> colours, with the aim of helping you see them through the flow of the >> code. > > Even with a simple "Find" command I don't like that behavior, let alone > for programming.? I find that all those other marked instances make it > harder for me to read the surrounding material.? They are good for > moving from one instance to another, but otherwise they get in the way > for me. Haven't seen the coloring feature as-described. As the number of identifiers increased, suspect it would become gaudy or the color shading too subtle for my eyes. +1 'Busy pictures' can be distracting. That said, the syntax-highlighting can provide the occasional cue that something has gone-wrong. However, will I recognise it from the mis-coloring, or from other evidence first? The semantic point might be easily under-estimated. A 'simple find' may not be helpful - a web-search for Python turns-up irrelevant information about snakes! Regarding the tracing of an identifier: PyCharm has two features: - with cursor/caret on/at a single use of an identifier, it will highlight other usage, elsewhere in that module's code - (context menu) FindUsages will bring-up a two-pane window. The left-pane shows a tree-structure of the project, modules, etc, down to a listing of each code-line where the identifier is used. Highlighting one of those (at a time), will show the context around that particular line/usage. The right-pane is editable! The great thing about these features is that they are semantically-aware (is that a real term?). For example, if I were (foolish enough) to name an identifier "the", such searches will not 'hit' the same word inside a comment or docstring. Better still, the above motivation continues into a (context menu) Refactor facility. This, one might consider to be a semantic Find-Replace. Often employ when helping others to clarify their code/Code Review - or when I'm 'just coding' and have quickly defined an identifier without a lot of thought, but later (ie when come to make use of it) realise a better alternative and more descriptive name. -- Regards, =dn From research at johnohagan.com Fri Mar 17 22:56:04 2023 From: research at johnohagan.com (John O'Hagan) Date: Sat, 18 Mar 2023 13:56:04 +1100 Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app In-Reply-To: References: Message-ID: <8dd9e654d6d5a8285adb3e98fdce6f8841f50026.camel@johnohagan.com> On Thu, 2023-03-16 at 04:21 -0400, aapost wrote: > On 3/15/23 07:37, John O'Hagan wrote: > > On Tue, 2023-03-14 at 16:22 -0400, aapost wrote: > > > On 3/14/23 06:54, John O'Hagan wrote: > > > > [...] > > > > > > > Read an alternative description of the waitKey behavior > > ?>For example, waitKey(0) will display the window infinitely until > any > keypress (it is suitable for image display). waitKey(25) will display > a > frame and wait approximately 25 ms for a key press (suitable for > displaying a video frame-by-frame). To remove the window, use > cv::destroyWindow. > > I went back to double check and I stand corrected on the "any > keypress" > part. Any keypress on the 'keyboard' does break the wait (as I > incorrectly concluded and assumed only ESC did). > > It is still slightly ambiguous in explaining that when using 25ms, > keypress or not, the wait breaks at 25ms (or before that if you press > a > keyboard key). For my setup the window is stale at that point, no > controls, just a stale frame behind the tkinter window that needs to > be > destroyed or reused. > > Whether that is the exact behavior on all set-ups isn't clear, the > note > further uses the ambiguous phrasing "might". > > ?>Note: This function should be followed by a call to cv::waitKey or > cv::pollKey to perform GUI housekeeping tasks that are necessary to > actually show the given image and make the window respond to mouse > and > keyboard events. Otherwise, it won?t display the image and the window > might lock up. > > It seems with the several variations, behavior varies between them, > like > one comment saying startWindowThread when using c++ and gtk allows > you > to not use waitKey (not the case here.. it seems -- changing my > language > to not misspeak, lol). > > I haven't come across any examples beyond imshow running stand-alone > as > in my solution suggestion 2. But waitKey does return a keyvalue for > the > keypess to allow extending the functionality, so you can grab it, do > something, and go right back to waiting, I haven't seen any use of > this > though. > > You can also leave out reference to tkinter all together when using > startWindowThread: > > import sys > import cv2 > > cv2.startWindowThread() > cv2.namedWindow("W", cv2.WND_PROP_FULLSCREEN) > cv2.setWindowProperty("W", cv2.WND_PROP_FULLSCREEN, > cv2.WINDOW_FULLSCREEN) > cv2.imshow("W", cv2.imread(sys.argv[1])) > while(1): > ???? a = cv2.waitKey(0) > ???? if a == 27:#ESC > ???????? break > ???? #elif a == something else, do something > cv2.destroyAllWindows() > exit() > > But it still blocks if integrated in to the main tkinter thread, and > appears to use tkinter under the hood. And as tkinter is considered > thread-unsafe, the startWindowThread would only be ok when spawned as > a > separate process like the subprocess example. > Thanks for this and your other detailed replies, which I won't go into because your comment above led me to a simple workaround using threading, with a caveat.? This may be controversial, but AIUI it's fine to use threads in tkinter as long as you don't touch the same widget from different threads. I do it all the time! ?So I tried opening and waiting for the window in a thread like this: def window_thread(): cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN) cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) cv2.waitKey(0) threading.Thread(target=window_thread, daemon=True).start() This works - the images can be displayed by calling imshow() via tkinter buttons in the main thread, and all the cv2 panning and zooming works too.? But the fly in the ointment is that any keypress while the focus is on the cv2 window exits the thread. I think this would apply to your subprocess example too. I tried: - putting the waitKey call in a while loop as in your example above, hoping it would just keep waiting, but the second call to waitKey doesn't respond to keypresses - putting the whole window_thread code in a while loop with a call to destroyAllWindows, hoping that this would re-create the window, but it doesn't - restarting the window thread after waitKey, which has the same results as above and - using a new name for the namedWindow each time In all cases, any subsequent calls to imshow block. I have no idea why.? For now it looks like I'll have to tell my users not to touch the keyboard while the image is in focus! Not ideal. If there is another nice fast pythonic way to display an image from a very large array _programatically_, I'd love to know about it. -- John From learn2program at gmail.com Sat Mar 18 04:46:42 2023 From: learn2program at gmail.com (Alan Gauld) Date: Sat, 18 Mar 2023 08:46:42 +0000 Subject: Fwd: Friday finking: IDE 'macro expansions' In-Reply-To: <4ef507c9-0ca3-2968-e468-cb51d621ff3f@tompassin.net> References: <663495e3-ca12-0370-3b2b-63bcc5d65bc8@gmail.com> <4ef507c9-0ca3-2968-e468-cb51d621ff3f@tompassin.net> Message-ID: <77a6acc6-a2a3-b9f5-e1fa-965d0f874553@yahoo.co.uk> On 17/03/2023 17:55, Thomas Passin wrote: >> I used Delphi and Smalltalk/V which both pretty much only exist within >> their own IDEs and I used their features extensively. > > Back when Delphi first came out, when I first used it, I don't remember > any IDE; one just used a text editor. I think you might be meaning TurboPascal, Delphi's forerunner. It just had a compiler and text editor. But Delphi from day 1 was an IDE designed to compete with Visual Basic. Everything was geared around the GUI builder. You could write code outside the IDE but it was orders of magnitude more difficult. The Lazarus open source project is based on Delphi's IDE. -- 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 gweatherby at uchc.edu Sat Mar 18 07:49:24 2023 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Sat, 18 Mar 2023 11:49:24 +0000 Subject: Friday finking: IDE 'macro expansions' In-Reply-To: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> References: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> Message-ID: I send ~99% of Python coding time in PyCharm. Likewise, IntelliJ and Clion for Java and C++, respectively. Mostly use: Tab completion for variable names Letting PyCharm figure out imports for me, and cleaning up old, unused imports. Jumping to definitions of symbols. Tellling me I?ve made a type error before unit testing the code by highlighting it in yellow. Occasionally I?ll jump through the hoops to connect it to our Postgresql database to help verify SQL, but it?s not usually worth the trouble. For templating, I have two Python programs for starting new work. One generates a standalone Python program with the Python shebang, a __main__ which calls def main(), and logging and argparser intialization. The other generates a pyproject.toml /setup.cfg directory structure with a main.py referenced as a console script. from setup.cfg From: Python-list on behalf of dn via Python-list Date: Thursday, March 16, 2023 at 6:59 PM To: 'Python' Subject: Friday finking: IDE 'macro expansions' *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** It is a long, long, time since I've thrown one of these into the maelstrom of our musings. (have the nightmares receded?) Do you make use of your IDE's expansionist tendencies, and if-so, which ones? NB this is where vi/emacs enthusiasts start chuckling (polite term for 'insane cackling'). Hence the question's limitation to IDEs, cf 'editors'! Also: I'm talking 'PyCharm' because of the story, but others use Codium, Sublime Text, etc - which presumably offer equivalent features. Was helping a friend install PyCharm. Jumped into the Settings. Isn't it incredible how many there are? Idly noted that there are two short-cut or macro-expansion types of facilities: - Postfix Completion, (nothing to do with email or polish notation) and - Live Templates (again, we're not talking about jinja2) With both, one types an abbreviated-name and the IDE will expand it into appropriate code. For (LiveTemplate) example, typing compli and pressing Tab induces PyCharm to add the following to the program[me]: [ ! for ! in !drop-down menu! if ! ] It offers further typo-saving through the drop-down menu which lists a bunch of likely (iterable) candidates from amongst previously-written code. The action continues after selecting from the menu, by inviting completion of the other ("!") placeholders, in-turn. I haven't made use of such a tool, to-date - OK, yes, I have practised a high typing-speed (and accuracy). Puff, puff... Also, at the time, I'm thinking in 'code', rather than about what tool might implement said ideas. Do you make use of such expansionist-tendencies? Do you make use of other powerful features within the IDE, or are its editor functionalities employed at pretty-much the NotePad level? Web.Refs: https://urldefense.com/v3/__https://www.jetbrains.com/help/pycharm/settings-postfix-completion.html__;!!Cn_UX_p3!l5XlkM7xExYMxpwFOxIvLPLSWPm_iu_aRv0WpnvCW2353FzsFjuJKfOYr-rCsnE915Rk59u6F4CgKPuF7fWLqicNTA$ https://urldefense.com/v3/__https://www.jetbrains.com/help/pycharm/using-live-templates.html*live_templates_types__;Iw!!Cn_UX_p3!l5XlkM7xExYMxpwFOxIvLPLSWPm_iu_aRv0WpnvCW2353FzsFjuJKfOYr-rCsnE915Rk59u6F4CgKPuF7fUOn2vrzA$ -- Regards, =dn -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!l5XlkM7xExYMxpwFOxIvLPLSWPm_iu_aRv0WpnvCW2353FzsFjuJKfOYr-rCsnE915Rk59u6F4CgKPuF7fUQeq7a_w$ From hjp-python at hjp.at Sat Mar 18 08:15:05 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 18 Mar 2023 13:15:05 +0100 Subject: Fwd: Friday finking: IDE 'macro expansions' In-Reply-To: <77a6acc6-a2a3-b9f5-e1fa-965d0f874553@yahoo.co.uk> References: <663495e3-ca12-0370-3b2b-63bcc5d65bc8@gmail.com> <4ef507c9-0ca3-2968-e468-cb51d621ff3f@tompassin.net> <77a6acc6-a2a3-b9f5-e1fa-965d0f874553@yahoo.co.uk> Message-ID: <20230318121505.msqfhopyiz73lj55@hjp.at> On 2023-03-18 08:46:42 +0000, Alan Gauld wrote: > On 17/03/2023 17:55, Thomas Passin wrote: > >> I used Delphi and Smalltalk/V which both pretty much only exist within > >> their own IDEs and I used their features extensively. > > > > Back when Delphi first came out, when I first used it, I don't remember > > any IDE; one just used a text editor. > > I think you might be meaning TurboPascal, Delphi's forerunner. It just > had a compiler and text editor. I'd still classify Turbo Pascal as an IDE. It wasn't a standalone compiler you would invoke on source files you wrote with some other tool. It was a single program where you would write your code, compile it, see the errors directly in the source code. I think it even had a debugger which would also use the same editor window (Turbo C did). > But Delphi from day 1 was an IDE designed to compete with Visual > Basic. Everything was geared around the GUI builder. Turbo Pascal predated GUIs, so it wouldn't have a GUI builder. Also not everything you develop needs a GUI (in fact I haven't written a real application (i.e. not a learning project) with a traditional desktop GUI for 20 years) so the presence or absence of a GUI builder isn't an essential criterion on whether something is or is not an IDE. 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 hjp-python at hjp.at Sat Mar 18 08:20:42 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 18 Mar 2023 13:20:42 +0100 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> Message-ID: <20230318122042.aktojdmubrxsy4kl@hjp.at> On 2023-03-15 17:09:52 +0000, Weatherby,Gerard wrote: > Sum is faster than iteration in the general case. I'd say this is the special case, not the general case. > def sum1(): > s = 0 > for i in range(1000000): > s += i > return s > > def sum2(): > return sum(range(1000000)) Here you already have the numbers you want to add. The OP needed to compute those numbers first. 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 2QdxY4RzWzUUiLuE at potatochowder.com Sat Mar 18 08:27:53 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Sat, 18 Mar 2023 08:27:53 -0400 Subject: Friday finking: IDE 'macro expansions' In-Reply-To: References: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> Message-ID: On 2023-03-18 at 11:49:24 +0000, "Weatherby,Gerard" wrote: > For templating, I have two Python programs for starting new work. One > generates a standalone Python program with the Python shebang, a > __main__ which calls def main(), and logging and argparser > intialization. The other generates a pyproject.toml /setup.cfg > directory structure with a main.py referenced as a console > script. from setup.cfg You don't describe the process for using those programs, but if you "have two Python programs," then it sounds like you're *not* using the IDE/editor for that. (I'm not judging, I'm trying to relate your answer to dn's original question.) For an opposing view, I'm much more likely to copy an old project (at the command line, often with sed) and then use my editor to morph it into a new project. IME, unless there's an imposed process, those templates and programs tend to experience bitrot, whereas going back to an old program gives me the chance to keep it up to date w.r.t. what I've learned more recently, which helps reinforce said learning. > From: Python-list on behalf of dn via Python-list > Date: Thursday, March 16, 2023 at 6:59 PM > To: 'Python' > Subject: Friday finking: IDE 'macro expansions' > *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** > > It is a long, long, time since I've thrown one of these into the > maelstrom of our musings. > (have the nightmares receded?) > > > Do you make use of your IDE's expansionist tendencies, and if-so, which > ones? [...] -- I can eat glass, it does not hurt me. Dan Sommers, http://www.tombstonezero.net/dan From list1 at tompassin.net Sat Mar 18 09:29:47 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 18 Mar 2023 09:29:47 -0400 Subject: Fwd: Friday finking: IDE 'macro expansions' In-Reply-To: <77a6acc6-a2a3-b9f5-e1fa-965d0f874553@yahoo.co.uk> References: <663495e3-ca12-0370-3b2b-63bcc5d65bc8@gmail.com> <4ef507c9-0ca3-2968-e468-cb51d621ff3f@tompassin.net> <77a6acc6-a2a3-b9f5-e1fa-965d0f874553@yahoo.co.uk> Message-ID: <916fe299-3813-3f44-a484-8c21d78b949c@tompassin.net> On 3/18/2023 4:46 AM, Alan Gauld wrote: > On 17/03/2023 17:55, Thomas Passin wrote: > >>> I used Delphi and Smalltalk/V which both pretty much only exist within >>> their own IDEs and I used their features extensively. >> >> Back when Delphi first came out, when I first used it, I don't remember >> any IDE; one just used a text editor. > > I think you might be meaning TurboPascal, Delphi's forerunner. It just > had a compiler and text editor. But Delphi from day 1 was an IDE > designed to compete with Visual Basic. Everything was geared around the > GUI builder. You could write code outside the IDE but it was orders of > magnitude more difficult. Maybe my memory has faded too much! I remember porting some of my TurboPascal code to Delphi and wrapping it with the Delphi-Windows GUI instead of my own, pre-Delphi one. The details are hazy, though ... > The Lazarus open source project is based on Delphi's IDE. > From list1 at tompassin.net Sat Mar 18 09:33:24 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 18 Mar 2023 09:33:24 -0400 Subject: Fwd: Friday finking: IDE 'macro expansions' In-Reply-To: <20230318121505.msqfhopyiz73lj55@hjp.at> References: <663495e3-ca12-0370-3b2b-63bcc5d65bc8@gmail.com> <4ef507c9-0ca3-2968-e468-cb51d621ff3f@tompassin.net> <77a6acc6-a2a3-b9f5-e1fa-965d0f874553@yahoo.co.uk> <20230318121505.msqfhopyiz73lj55@hjp.at> Message-ID: On 3/18/2023 8:15 AM, Peter J. Holzer wrote: > On 2023-03-18 08:46:42 +0000, Alan Gauld wrote: >> On 17/03/2023 17:55, Thomas Passin wrote: >>>> I used Delphi and Smalltalk/V which both pretty much only exist within >>>> their own IDEs and I used their features extensively. >>> >>> Back when Delphi first came out, when I first used it, I don't remember >>> any IDE; one just used a text editor. >> >> I think you might be meaning TurboPascal, Delphi's forerunner. It just >> had a compiler and text editor. > > I'd still classify Turbo Pascal as an IDE. It wasn't a standalone > compiler you would invoke on source files you wrote with some other > tool. It was a single program where you would write your code, compile > it, see the errors directly in the source code. I think it even had a > debugger which would also use the same editor window (Turbo C did). Yes, TurboPascal was a brilliant product for its time. And it was much cheaper than getting, say, a complete C compiler package, and way easier and faster to use. > >> But Delphi from day 1 was an IDE designed to compete with Visual >> Basic. Everything was geared around the GUI builder. > > Turbo Pascal predated GUIs, so it wouldn't have a GUI builder. Also not > everything you develop needs a GUI (in fact I haven't written a real > application (i.e. not a learning project) with a traditional desktop GUI > for 20 years) so the presence or absence of a GUI builder isn't an > essential criterion on whether something is or is not an IDE. > > hp > > From roel at roelschroeven.net Sat Mar 18 10:39:34 2023 From: roel at roelschroeven.net (Roel Schroeven) Date: Sat, 18 Mar 2023 15:39:34 +0100 Subject: Fwd: Friday finking: IDE 'macro expansions' In-Reply-To: <20230318121505.msqfhopyiz73lj55@hjp.at> References: <663495e3-ca12-0370-3b2b-63bcc5d65bc8@gmail.com> <4ef507c9-0ca3-2968-e468-cb51d621ff3f@tompassin.net> <77a6acc6-a2a3-b9f5-e1fa-965d0f874553@yahoo.co.uk> <20230318121505.msqfhopyiz73lj55@hjp.at> Message-ID: Peter J. Holzer schreef op 18/03/2023 om 13:15: > On 2023-03-18 08:46:42 +0000, Alan Gauld wrote: > > On 17/03/2023 17:55, Thomas Passin wrote: > > >> I used Delphi and Smalltalk/V which both pretty much only exist within > > >> their own IDEs and I used their features extensively. > > > > > > Back when Delphi first came out, when I first used it, I don't remember > > > any IDE; one just used a text editor. > > > > I think you might be meaning TurboPascal, Delphi's forerunner. It just > > had a compiler and text editor. > > I'd still classify Turbo Pascal as an IDE. It wasn't a standalone > compiler you would invoke on source files you wrote with some other > tool. It was a single program where you would write your code, compile > it, see the errors directly in the source code. I think it even had a > debugger which would also use the same editor window (Turbo C did). Oh yes, Turbo Pascal was definitely an IDE. It was actually pretty similar to the GUI applications we have today, even though it was all text based. It had a menu bar with pull-down menus, it had popup windows. The look and feel is pretty similar to that of Midnight Commander (mc) nowadays, for those who know that. Like you say it had an editor (obviously) and an integrated compiler, and indeed an integrated debugger, with watches and all, much like you would see in an IDE today. See this screenshot for example: https://daynhauhoc.s3.dualstack.ap-southeast-1.amazonaws.com/original/3X/7/8/782423b53bb6531d43c3c2075cb4a00f4ac7a5c0.png For people too young to have used such semi-graphical applications in the past, you can find plenty of screenshots when you do an image search for turbo pascal. Turbo Pascal was obviously not as advanced as the IDEs we have today, but it was definitely an IDE, and it had all the basic functions that one would expect from an IDE. -- "Most of us, when all is said and done, like what we like and make up reasons for it afterwards." -- Soren F. Petersen From learn2program at gmail.com Sat Mar 18 12:06:49 2023 From: learn2program at gmail.com (Alan Gauld) Date: Sat, 18 Mar 2023 16:06:49 +0000 Subject: Fwd: Friday finking: IDE 'macro expansions' In-Reply-To: <20230318121505.msqfhopyiz73lj55@hjp.at> References: <663495e3-ca12-0370-3b2b-63bcc5d65bc8@gmail.com> <4ef507c9-0ca3-2968-e468-cb51d621ff3f@tompassin.net> <77a6acc6-a2a3-b9f5-e1fa-965d0f874553@yahoo.co.uk> <20230318121505.msqfhopyiz73lj55@hjp.at> Message-ID: <6fb2be36-48c8-b65d-c852-04d84a9e5139@yahoo.co.uk> On 18/03/2023 12:15, Peter J. Holzer wrote: >> I think you might be meaning TurboPascal, Delphi's forerunner. It just >> had a compiler and text editor. > > I'd still classify Turbo Pascal as an IDE. It wasn't a standalone > compiler you would invoke on source files you wrote with some other It had both (although I'm not sure when that was introduced, the original didn't). Mostly you used the IDE/editor but there was a command line compiler that you could run (and a make-like project tool too in the later versions). I started with TurboPascal on DOS at Uni generating COM files then later used TP versions 4, 5.5(with added OOP!) and 6 professionally, creating EXE file DOS programs. Up until I switched to a Mac, a year ago, I still had TP6 and used it to maintain some old TurboVision DOS programs. But I used Delphi from version 1 through to 7(?) for all my Windows programming and still have version 3 installed (via VirtualBox on Linux) to keep some old shareware apps of mine running. I often think there are a lot of similarities between Delphi/Object Pascal and Python in the OOP area. > it, see the errors directly in the source code. I think it even had a > debugger which would also use the same editor window (Turbo C did). I think the debugger came in v3, but i could be wrong. I don't recall there being one at uni... > Turbo Pascal predated GUIs, so it wouldn't have a GUI builder. No, it did have a windowing toolkit(TurboVision) but no visual UI builder. That was the big new feature of Delphi. > application (i.e. not a learning project) with a traditional desktop GUI > for 20 years) so the presence or absence of a GUI builder isn't an > essential criterion on whether something is or is not an IDE. Indeed, but it was intrinsic to Delphi (even though you could write non GUI apps too, but they required extra effort.) Eclipse et al have GUI builders available as extras, in Delphi (and Lazurus) it is hard to avoid. BTW Delphi (v11) and the other Borland tools are still going strong, albeit at extortionately high prices: $1000~3000 for the pro versions! (But there is still a free community version with just the basics.) See http://www.embarcadero.com And it's targeted at multi-platforms now: Windows, MacOS, Android, iOS although it only runs on Windows. -- 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 gvanem at yahoo.no Sat Mar 18 14:02:55 2023 From: gvanem at yahoo.no (Gisle Vanem) Date: Sat, 18 Mar 2023 19:02:55 +0100 Subject: Q: argparse.add_argument() References: <1bc9f382-73fb-b43b-7ca0-036544a18544.ref@yahoo.no> Message-ID: <1bc9f382-73fb-b43b-7ca0-036544a18544@yahoo.no> I accidentally used 'argparse' like this in my Python 3.9 program: parser.add_argument ("-c, --clean", dest="clean", action="store_true") parser.add_argument ("-n, --dryrun", dest="dryrun", action="store_true") instead of: parser.add_argument ("-c", "--clean", dest="clean", action="store_true") parser.add_argument ("-n", "--dryrun", dest="dryrun", action="store_true") So any use of 'my-prog.py -cn' threw an error: error: unrecognized arguments: -cn So is there something that throws an error on this wrong use of "-c, --clean" instead? Could be useful. Or is "-c, --clean" legit somehow? -- --gv From manta103g at gmail.com Fri Mar 17 11:32:41 2023 From: manta103g at gmail.com (a a) Date: Fri, 17 Mar 2023 08:32:41 -0700 (PDT) Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> Message-ID: <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> On Friday, 17 March 2023 at 16:03:14 UTC+1, Thomas Passin wrote: > On 3/16/2023 8:07 PM, a a wrote: > > Crash report: > > > > Problem Caption: > > Problem Event Name: APPCRASH > > Application name: python.exe > > Application version: 3.8.7150.1013 > > Application time signature: 5fe0df5a > > Error module name: _multiarray_umath.cp38-win32.pyd > > Version of the module with the error: 0.0.0.0 > > Time signature of the module with the error: 63dfe4cf > > Exception code: c000001d > > Exception offset: 000269c9 > > Operating system version: 6.1.7601.2.1.0.256.48 > > Regional Settings ID: 1045 > > Additional information 1: 0a9e > > Additional information 2: 0a9e372d3b4ad19135b953a78882e789 > > Additional information 3: 0a9e > > Additional information 4: 0a9e372d3b4ad19135b953a78882e789 > This exception has been reported to have many causes, but one > possibility seems to be that your computer may not support an advanced > instruction set that the .pyd was compiled for. I found this one > specifically mentioned on the Internet: Advanced Vector Extensions. If > that were the case, you would either need to find a different version of > the module, or upgrade the computer/OS. > > It would be worth trying to downgrade the multiarray version to an > earlier one and see if that fixes the problem. Thank you Thomas for your kind reply. I am fully aware to be living on an old machine, old OS, Windows 7, 32-bit system but I have visited every social chat support forum on the Internet: from Python to Matplotlib, Numpy, Twitter, Github. As a newbie I am not aware how to downgrade "the multiarray version to an earlier one I simply tried to test Python code from https://www.section.io/engineering-education/reading-and-processing-android-sensor-data-using-python-with-csv-read/ ==== # Python program to read .csv file import numpy as np import matplotlib.pyplot as plt import csv ---- "After importing the libraries, we now read the .csv file: with open('accl1.csv', 'r') as f: data = list(csv.reader(f, delimiter=',')) #reading csv file ==== Just read about AVE from Wikipedia https://en.wikipedia.org/wiki/Advanced_Vector_Extensions From manta103g at gmail.com Fri Mar 17 11:36:48 2023 From: manta103g at gmail.com (a a) Date: Fri, 17 Mar 2023 08:36:48 -0700 (PDT) Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> Message-ID: <542a36a8-d4d1-42b6-b234-5e918548bf5dn@googlegroups.com> On Friday, 17 March 2023 at 16:03:14 UTC+1, Thomas Passin wrote: > On 3/16/2023 8:07 PM, a a wrote: > > Crash report: > > > > Problem Caption: > > Problem Event Name: APPCRASH > > Application name: python.exe > > Application version: 3.8.7150.1013 > > Application time signature: 5fe0df5a > > Error module name: _multiarray_umath.cp38-win32.pyd > > Version of the module with the error: 0.0.0.0 > > Time signature of the module with the error: 63dfe4cf > > Exception code: c000001d > > Exception offset: 000269c9 > > Operating system version: 6.1.7601.2.1.0.256.48 > > Regional Settings ID: 1045 > > Additional information 1: 0a9e > > Additional information 2: 0a9e372d3b4ad19135b953a78882e789 > > Additional information 3: 0a9e > > Additional information 4: 0a9e372d3b4ad19135b953a78882e789 > This exception has been reported to have many causes, but one > possibility seems to be that your computer may not support an advanced > instruction set that the .pyd was compiled for. I found this one > specifically mentioned on the Internet: Advanced Vector Extensions. If > that were the case, you would either need to find a different version of > the module, or upgrade the computer/OS. > > It would be worth trying to downgrade the multiarray version to an > earlier one and see if that fixes the problem. Just reading from search engine: https://www.bing.com/search?q=how+to+downgrade+_multiarray_umath.cp38-win32.pyd+&form=QBLH&sp=-1&lq=0&pq=how+to+downgrade+_multiarray_umath.cp38-win32.pyd+&sc=1-50&qs=n&sk= From manta103g at gmail.com Fri Mar 17 11:52:15 2023 From: manta103g at gmail.com (a a) Date: Fri, 17 Mar 2023 08:52:15 -0700 (PDT) Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> Message-ID: On Friday, 17 March 2023 at 16:32:53 UTC+1, a a wrote: > On Friday, 17 March 2023 at 16:03:14 UTC+1, Thomas Passin wrote: > > On 3/16/2023 8:07 PM, a a wrote: > > > Crash report: > > > > > > Problem Caption: > > > Problem Event Name: APPCRASH > > > Application name: python.exe > > > Application version: 3.8.7150.1013 > > > Application time signature: 5fe0df5a > > > Error module name: _multiarray_umath.cp38-win32.pyd > > > Version of the module with the error: 0.0.0.0 > > > Time signature of the module with the error: 63dfe4cf > > > Exception code: c000001d > > > Exception offset: 000269c9 > > > Operating system version: 6.1.7601.2.1.0.256.48 > > > Regional Settings ID: 1045 > > > Additional information 1: 0a9e > > > Additional information 2: 0a9e372d3b4ad19135b953a78882e789 > > > Additional information 3: 0a9e > > > Additional information 4: 0a9e372d3b4ad19135b953a78882e789 > > This exception has been reported to have many causes, but one > > possibility seems to be that your computer may not support an advanced > > instruction set that the .pyd was compiled for. I found this one > > specifically mentioned on the Internet: Advanced Vector Extensions. If > > that were the case, you would either need to find a different version of > > the module, or upgrade the computer/OS. > > > > It would be worth trying to downgrade the multiarray version to an > > earlier one and see if that fixes the problem. > Thank you Thomas > for your kind reply. > > I am fully aware to be living on an old machine, old OS, Windows 7, 32-bit system > but I have visited every social chat support forum on the Internet: from Python to Matplotlib, Numpy, Twitter, Github. > > As a newbie I am not aware how to downgrade "the multiarray version to an > earlier one > > I simply tried to test Python code from > > > https://www.section.io/engineering-education/reading-and-processing-android-sensor-data-using-python-with-csv-read/ > > ==== > # Python program to read .csv file > > import numpy as np > import matplotlib.pyplot as plt > import csv > ---- > > "After importing the libraries, we now read the .csv file: > > with open('accl1.csv', 'r') as f: > data = list(csv.reader(f, delimiter=',')) #reading csv file > > ==== > Just read about AVE from Wikipedia > > https://en.wikipedia.org/wiki/Advanced_Vector_Extensions downloaded and run HWiNFO and AVE not supported, not greened out From hjp-python at hjp.at Sat Mar 18 14:37:17 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 18 Mar 2023 19:37:17 +0100 Subject: Fwd: Friday finking: IDE 'macro expansions' In-Reply-To: <6fb2be36-48c8-b65d-c852-04d84a9e5139@yahoo.co.uk> References: <663495e3-ca12-0370-3b2b-63bcc5d65bc8@gmail.com> <4ef507c9-0ca3-2968-e468-cb51d621ff3f@tompassin.net> <77a6acc6-a2a3-b9f5-e1fa-965d0f874553@yahoo.co.uk> <20230318121505.msqfhopyiz73lj55@hjp.at> <6fb2be36-48c8-b65d-c852-04d84a9e5139@yahoo.co.uk> Message-ID: <20230318183717.h4333akxm7awqtml@hjp.at> On 2023-03-18 16:06:49 +0000, Alan Gauld wrote: > On 18/03/2023 12:15, Peter J. Holzer wrote: > >> I think you might be meaning TurboPascal, Delphi's forerunner. It just > >> had a compiler and text editor. > > > > I'd still classify Turbo Pascal as an IDE. It wasn't a standalone > > compiler you would invoke on source files you wrote with some other > > It had both I didn't mention that because I think it is irrelevant to the question whether Turbo Pascal as an IDE or not. What is relevant IMNSHO is that it did indeed provide an "integraded environment" for "developing", combining all those tools which were traditionally separate in one user interface. > Indeed, but it was intrinsic to Delphi (even though you could > write non GUI apps too, but they required extra effort.) > Eclipse et al have GUI builders available as extras, in Delphi > (and Lazurus) it is hard to avoid. This is starting to sound like "Delphi is the only True? IDE". hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From list1 at tompassin.net Sat Mar 18 15:01:03 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 18 Mar 2023 15:01:03 -0400 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> Message-ID: On 3/17/2023 11:32 AM, a a wrote: > On Friday, 17 March 2023 at 16:03:14 UTC+1, Thomas Passin wrote: >> It would be worth trying to downgrade the multiarray version to an >> earlier one and see if that fixes the problem. > > Thank you Thomas for your kind reply. > > I am fully aware to be living on an old machine, old OS, Windows 7, > 32-bit system but I have visited every social chat support forum on > the Internet: from Python to Matplotlib, Numpy, Twitter, Github. I mentioned the "multiarray" just because of its name in the error message: "Error module name: _multiarray_umath.cp38-win32.pyd " I assumed that the code you tried to run required an import from a module or package whose name included "multiarray". But I didn't try to actually look for one. Now I've checked, and I see it's included with NumPy. > I simply tried to test Python code from > > > https://www.section.io/engineering-education/reading-and-processing-android-sensor-data-using-python-with-csv-read/ > > ==== # Python program to read .csv file > > import numpy as np import matplotlib.pyplot as plt import csv ---- > > "After importing the libraries, we now read the .csv file: > > with open('accl1.csv', 'r') as f: data = list(csv.reader(f, > delimiter=',')) #reading csv file You don't need numpy just to do this import, so you could remove the numpy import just to test reading the csv file. But I imagine you do need numpy for later steps. > > As a newbie I am not aware how to downgrade "the multiarray version > to an earlier one. I just had to do this myself to work around a change in an import that broke one of my programs (not a numpy import). If you can identify an earlier version that work - we will use proglib v 3.72 as an example - with pip you would use python3 -m pip install --upgrade proglib<=3.72 To get exactly version 3.72, you would use "==3.72". NOTE - no space allowed before the first "=" character!. NOTE - you may need to type "python" or "py" instead of "python3". Just use the one that runs the version of Python that you want to run. To find which versions are available: python3 -m pip install --upgrade proglib== To find out which version you have installed on your computer: python3 -m pip show numpy After you downgrade to an earlier version, you can test it just by trying to import numpy. In an interpreter session, just try to import it: >>> import numpy If that succeeds, chances are you will be all set. > ==== Just read about AVE from Wikipedia > > https://en.wikipedia.org/wiki/Advanced_Vector_Extensions I have read that there are other instruction set extensions that could be missing besides AVE, that could cause that exception code. The fact that you have a relatively old computer suggests that could be the problem. From list1 at tompassin.net Sat Mar 18 15:08:26 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 18 Mar 2023 15:08:26 -0400 Subject: Q: argparse.add_argument() In-Reply-To: <1bc9f382-73fb-b43b-7ca0-036544a18544@yahoo.no> References: <1bc9f382-73fb-b43b-7ca0-036544a18544.ref@yahoo.no> <1bc9f382-73fb-b43b-7ca0-036544a18544@yahoo.no> Message-ID: On 3/18/2023 2:02 PM, Gisle Vanem via Python-list wrote: > I accidentally used 'argparse' like this in my Python 3.9 program: > ? parser.add_argument ("-c, --clean",? dest="clean", action="store_true") > ? parser.add_argument ("-n, --dryrun", dest="dryrun", action="store_true") > > instead of: > ? parser.add_argument ("-c", "--clean",? dest="clean", > action="store_true") > ? parser.add_argument ("-n", "--dryrun", dest="dryrun", > action="store_true") > > So any use of 'my-prog.py -cn' threw an error: > ? error: unrecognized arguments: -cn > > So is there something that throws an error on this wrong use of > "-c, --clean" instead? Could be useful. Or is "-c, --clean" legit somehow? Are you trying to troll here? You just showed how you got an error with this construction, so why are you asking how to get an error with this construction? From list1 at tompassin.net Sat Mar 18 15:05:41 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 18 Mar 2023 15:05:41 -0400 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> Message-ID: <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> On 3/17/2023 11:52 AM, a a wrote: > On Friday, 17 March 2023 at 16:32:53 UTC+1, a a wrote: >> On Friday, 17 March 2023 at 16:03:14 UTC+1, Thomas Passin wrote: >>> On 3/16/2023 8:07 PM, a a wrote: >>>> Crash report: >>>> >>>> Problem Caption: >>>> Problem Event Name: APPCRASH >>>> Application name: python.exe >>>> Application version: 3.8.7150.1013 >>>> Application time signature: 5fe0df5a >>>> Error module name: _multiarray_umath.cp38-win32.pyd >>>> Version of the module with the error: 0.0.0.0 >>>> Time signature of the module with the error: 63dfe4cf >>>> Exception code: c000001d >>>> Exception offset: 000269c9 >>>> Operating system version: 6.1.7601.2.1.0.256.48 >>>> Regional Settings ID: 1045 >>>> Additional information 1: 0a9e >>>> Additional information 2: 0a9e372d3b4ad19135b953a78882e789 >>>> Additional information 3: 0a9e >>>> Additional information 4: 0a9e372d3b4ad19135b953a78882e789 >>> This exception has been reported to have many causes, but one >>> possibility seems to be that your computer may not support an advanced >>> instruction set that the .pyd was compiled for. I found this one >>> specifically mentioned on the Internet: Advanced Vector Extensions. If >>> that were the case, you would either need to find a different version of >>> the module, or upgrade the computer/OS. >>> >>> It would be worth trying to downgrade the multiarray version to an >>> earlier one and see if that fixes the problem. >> Thank you Thomas >> for your kind reply. >> >> I am fully aware to be living on an old machine, old OS, Windows 7, 32-bit system >> but I have visited every social chat support forum on the Internet: from Python to Matplotlib, Numpy, Twitter, Github. >> >> As a newbie I am not aware how to downgrade "the multiarray version to an >> earlier one >> >> I simply tried to test Python code from >> >> >> https://www.section.io/engineering-education/reading-and-processing-android-sensor-data-using-python-with-csv-read/ >> >> ==== >> # Python program to read .csv file >> >> import numpy as np >> import matplotlib.pyplot as plt >> import csv >> ---- >> >> "After importing the libraries, we now read the .csv file: >> >> with open('accl1.csv', 'r') as f: >> data = list(csv.reader(f, delimiter=',')) #reading csv file >> >> ==== >> Just read about AVE from Wikipedia >> >> https://en.wikipedia.org/wiki/Advanced_Vector_Extensions > > > downloaded and run > HWiNFO > and AVE not supported, not greened out That's too bad; you may be out of luck. It's possible that someone has compiled the .pyd library in such a way that it does not need the instruction set extensions. I'm sorry but I don't know how to find out except by trying internet searches - or by downgrading to earlier versions of Numpy hoping to find one that works and also can be used by the other libraries/programs that need to use it. From rosuav at gmail.com Sat Mar 18 15:22:33 2023 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Mar 2023 06:22:33 +1100 Subject: Q: argparse.add_argument() In-Reply-To: References: <1bc9f382-73fb-b43b-7ca0-036544a18544.ref@yahoo.no> <1bc9f382-73fb-b43b-7ca0-036544a18544@yahoo.no> Message-ID: On Sun, 19 Mar 2023 at 06:09, Thomas Passin wrote: > > On 3/18/2023 2:02 PM, Gisle Vanem via Python-list wrote: > > I accidentally used 'argparse' like this in my Python 3.9 program: > > parser.add_argument ("-c, --clean", dest="clean", action="store_true") > > parser.add_argument ("-n, --dryrun", dest="dryrun", action="store_true") > > > > instead of: > > parser.add_argument ("-c", "--clean", dest="clean", > > action="store_true") > > parser.add_argument ("-n", "--dryrun", dest="dryrun", > > action="store_true") > > > > So any use of 'my-prog.py -cn' threw an error: > > error: unrecognized arguments: -cn > > > > So is there something that throws an error on this wrong use of > > "-c, --clean" instead? Could be useful. Or is "-c, --clean" legit somehow? > > > Are you trying to troll here? You just showed how you got an error with > this construction, so why are you asking how to get an error with this > construction? > There's a small difference in the way that the arguments are passed. In the accidental example, "-c, --clean" is passed as a single argument, which is a bug. The truth is, though, that no program can ever tell you about all of your bugs. The "-c, --clean" form is technically valid, and will match an argument that looks exactly like it; I suppose argparse might be coded to give a warning if there's a space inside an argument, but that would be extremely annoying to anyone who actually wants it. Ultimately, the only way to find bugs is to test, and to get good at noticing expected patterns (for instance, if your editor highlights strings or quote characters, your brain should expect to see them in certain places). It's a nice courtesy when a library will help you to find your own bugs, but there's a limit to what it can do. ChrisA From gvanem at yahoo.no Sat Mar 18 15:33:48 2023 From: gvanem at yahoo.no (Gisle Vanem) Date: Sat, 18 Mar 2023 20:33:48 +0100 Subject: Q: argparse.add_argument() In-Reply-To: References: <1bc9f382-73fb-b43b-7ca0-036544a18544.ref@yahoo.no> <1bc9f382-73fb-b43b-7ca0-036544a18544@yahoo.no> Message-ID: Thomas Passin wrote: > Are you trying to troll here? > You just showed how you got an error with this construction, so why are you asking how to > get an error with this construction? I meant (obviously), another error-message besides: error: unrecognized arguments: -cn Perhaps from 'parser.add_argument ("-c, --clean", dest="clean", action="store_true")' error: "-c, --clean", 2 options are unsupported. BTW, accusing someone of 'trolling' is rather rude IMHO. And thanks to ChrisA for a nice and normal answer. -- --gv From rosuav at gmail.com Sat Mar 18 16:05:51 2023 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Mar 2023 07:05:51 +1100 Subject: Q: argparse.add_argument() In-Reply-To: References: <1bc9f382-73fb-b43b-7ca0-036544a18544.ref@yahoo.no> <1bc9f382-73fb-b43b-7ca0-036544a18544@yahoo.no> Message-ID: On Sun, 19 Mar 2023 at 06:35, Gisle Vanem via Python-list wrote: > > Thomas Passin wrote: > > > Are you trying to troll here? > > > You just showed how you got an error with this construction, so why are you asking how to > > get an error with this construction? > > I meant (obviously), another error-message besides: > error: unrecognized arguments: -cn > > Perhaps from 'parser.add_argument ("-c, --clean", dest="clean", action="store_true")' > error: "-c, --clean", 2 options are unsupported. > > BTW, accusing someone of 'trolling' is rather rude IMHO. > And thanks to ChrisA for a nice and normal answer. I suspect the reason you were accused of trolling was that it was quite unobvious what the difference was. When you ask for help with something where the distinction is subtle (and you generally know it was subtle by how long it took you to spot it!), it's often valuable to pinpoint the exact issue, so people don't gloss over it and think you posted the same code twice. For example: """ I accidentally used 'argparse' like this in my Python 3.9 program: parser.add_argument ("-c, --clean", dest="clean", action="store_true") parser.add_argument ("-n, --dryrun", dest="dryrun", action="store_true") instead of: parser.add_argument ("-c", "--clean", dest="clean", action="store_true") parser.add_argument ("-n", "--dryrun", dest="dryrun", action="store_true") Instead of having the short and long forms as separate parameters to add_argument, I mistakenly put them in a single string. """ Now everyone can see immediately what your bug was, how easy it is to make (and how hard to spot if not pointed out), and how likely it is for this to be actually desired behaviour (in this case: highly unlikely). As to the reason you didn't get any other error message - that's because, technically, what you did was perfectly valid. >>> import argparse >>> parser = argparse.ArgumentParser() >>> parser.add_argument ("-c, --clean", dest="clean", action="store_true") _StoreTrueAction(option_strings=['-c, --clean'], dest='clean', nargs=0, const=True, default=False, type=None, choices=None, required=False, help=None, metavar=None) >>> parser.add_argument ("-n, --dryrun", dest="dryrun", action="store_true") _StoreTrueAction(option_strings=['-n, --dryrun'], dest='dryrun', nargs=0, const=True, default=False, type=None, choices=None, required=False, help=None, metavar=None) >>> parser.parse_args(["-c, --clean"]) Namespace(clean=True, dryrun=False) It's just that the argument needed to make this happen is... a tad unlikely in the real world. So I do see that there's a problem here, but I'm not sure what the true solution is. Is it reasonable to mandate that arguments do not contain spaces? (Dubious.) What if they're not allowed to contain commas? (Also dubious.) Maybe something really complicated like ", -" as an entire construct? (Could easily be confusing.) It's definitely worth opening the conversation on this, and I'd be curious to know how many other people have made this same bug. ChrisA From list1 at tompassin.net Sat Mar 18 17:59:39 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 18 Mar 2023 17:59:39 -0400 Subject: Q: argparse.add_argument() In-Reply-To: References: <1bc9f382-73fb-b43b-7ca0-036544a18544.ref@yahoo.no> <1bc9f382-73fb-b43b-7ca0-036544a18544@yahoo.no> Message-ID: <1de7b18b-9e4d-2433-ae2e-001a8f3cb4a4@tompassin.net> On 3/18/2023 4:05 PM, Chris Angelico wrote: > On Sun, 19 Mar 2023 at 06:35, Gisle Vanem via Python-list > wrote: >> >> Thomas Passin wrote: >> >>> Are you trying to troll here? >>> >> You just showed how you got an error with this construction, so why are you asking how to >>> get an error with this construction? >> >> I meant (obviously), another error-message besides: >> error: unrecognized arguments: -cn >> >> Perhaps from 'parser.add_argument ("-c, --clean", dest="clean", action="store_true")' >> error: "-c, --clean", 2 options are unsupported. >> >> BTW, accusing someone of 'trolling' is rather rude IMHO. >> And thanks to ChrisA for a nice and normal answer. I apologize for putting it that way. I did have a reason for wondering about the post, but another time I wouldn't express it like that. Really, this is more general - about how to be more effective when asking for help. > I suspect the reason you were accused of trolling was that it was > quite unobvious what the difference was. When you ask for help with > something where the distinction is subtle (and you generally know it > was subtle by how long it took you to spot it!), it's often valuable > to pinpoint the exact issue, so people don't gloss over it and think > you posted the same code twice. I did notice the difference, although I had to read it carefully a few times. What I picked up on was that the OP wrote "So is there something that throws an error on this wrong use..." immediately after writing "So any use of 'my-prog.py -cn' threw an error..." To me that reads "using 'cn' as a parameter gave an error. Is there something that will give this error?". The question doesn't make sense that way - the OP *already* has "something" that gives the error. So either the OP meant something else - and why should I need to guess what it was? - or ... [troll, maybe? :)]. So please, try to think out how your questions will seem to the reader, and be clear about what you are asking. You may not know the terminology that some other people use, but don't let that stop you from being clear about what you really need to find out. Including more context is likely to be helpful, too. Don't leave it to the readers to infer what you were thinking of. Perhaps some people who ask for help do not realize it, but to understand clearly what a situation and question are, and to work out and write (and edit) a helpful reply, perhaps with some code that needed to be checked first - that takes time and care. From PythonList at DancesWithMice.info Sat Mar 18 19:11:07 2023 From: PythonList at DancesWithMice.info (dn) Date: Sun, 19 Mar 2023 12:11:07 +1300 Subject: Friday finking: IDE 'macro expansions' In-Reply-To: References: <238f9c45-35c9-e6e7-8263-a7b704269f5a@DancesWithMice.info> Message-ID: <82a1f7f3-b5a8-d409-ba13-d01c4168e46b@DancesWithMice.info> On 19/03/2023 01.27, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > On 2023-03-18 at 11:49:24 +0000, > "Weatherby,Gerard" wrote: > >> For templating, I have two Python programs for starting new work. One >> generates a standalone Python program with the Python shebang, a >> __main__ which calls def main(), and logging and argparser >> intialization. The other generates a pyproject.toml /setup.cfg >> directory structure with a main.py referenced as a console >> script. from setup.cfg > > You don't describe the process for using those programs, but if you > "have two Python programs," then it sounds like you're *not* using the > IDE/editor for that. > > (I'm not judging, I'm trying to relate your answer to dn's original > question.) It is a good example of a facility or 'power' of an IDE - even if there's room for more information... The team I'm currently assisting has decided to use Poetry. PyCharm will create a new project, populating basic files, more-or-less as @George described. In the same way, if one prefers a venv (etc) instead of a Poetry structure, PyCharm will set things up similarly. Accordingly, it saves a lot of time, fiddling-about creating a bunch of (basically) empty files and sub-dirs. (that said, there a plenty of operations which have a blank-project template which can be copied-in and renamed...) Continuing the story, let's say the project calls for a PyPi-based* library, eg more_itertools, or there's a team 'standard', eg pytest; then these can be selected from a PyCharm-provided list (no need to go to PyPi to download) AND that operation will also be reflected in the pyproject.toml file. * cf one from the PSL In other words, the build file has been created and continually-maintained, by the IDE, ready for when the project is to be uploaded to a library or exported to target-machines; cf the 'tradition' of an extra, last, and not looked-forward-to, step in the process! > For an opposing view, I'm much more likely to copy an old project (at > the command line, often with sed) and then use my editor to morph it > into a new project. IME, unless there's an imposed process, those > templates and programs tend to experience bitrot, whereas going back to > an old program gives me the chance to keep it up to date w.r.t. what > I've learned more recently, which helps reinforce said learning. Yes... (guilty as charged!) Equally, may promulgate old habits and a lower-quality (related to the depth of learning, back-then cf 'now'). -- Regards, =dn From research at johnohagan.com Sat Mar 18 20:08:54 2023 From: research at johnohagan.com (John O'Hagan) Date: Sun, 19 Mar 2023 11:08:54 +1100 Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app In-Reply-To: References: Message-ID: <43b2e1bcf9100e9456b0d27710bfb766dffcd9cc.camel@johnohagan.com> On Tue, 2023-03-14 at 21:54 +1100, John O'Hagan wrote: [...] > Here is minimal code that demonstrates the problem in the subject > line: > > import cv2 > from tkinter import * > > images=['a.jpg', 'b.jpg', 'c.jpg'] #change to image paths > > cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN) > cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN,? > cv2.WINDOW_FULLSCREEN) > counter=[0] > def show(): > cv2.imshow('W', cv2.imread(images[counter[0] % len(images)])) > cv2.waitKey(1) > counter[0] += 1 > > root=Tk() > root.wm_attributes("-topmost", 1) > Button(root, text=' Show ', command=show).pack() > mainloop() > > It works up to a point - I can cycle through the images by clicking > the button - but if I mouse-click on the displayed image (e.g. to use > the zooming and panning features of cv2), nothing happens, and a few > seconds later the image greys out and a popup appears saying > "'Unknown' is not responding" and giving the option of waiting or > forcing close (but sometimes these options are greyed out too). > Clicking "wait", if available, closes the popup but it comes back a > few seconds later. If I then click on the tkinter window titlebar, > the popup changes to?"'Tk' is not responding". Clicking on the button > still works and after a few clicks the popup closes. > [...] For anyone interested (and there are a lot of questions about this type of issue out there), here's the nearest I came to a satisfactory solution. In the real code I put a method like: def window_thread(): cv2.namedWindow('W') #window properties omited while 1: # really a flag for clean exit cv2.imshow('W', self.image) cv2.waitKey(40) and call this as a thread from __init__. This updates the image every 40 ms regardless of whether it has been changed or not, in the manner of a video feed. Seems unnecessary, but surprisingly it doesn't seem to use any significant resources and seems to be the only way to keep both the tkinter GUI and the cv2 window responsive. What I'd really like is cv2.wait(until_i_say_so()) - i.e. to wait for a flag that can be set programatically, but it doesn't seem to be available in cv2. Thanks to those who replied. > -- > > John > > From rob.cliffe at btinternet.com Sat Mar 18 20:54:48 2023 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Sun, 19 Mar 2023 00:54:48 +0000 Subject: Packing Problem In-Reply-To: References: <6e36f542-e4b6-35f8-5530-1115360de252@btinternet.com> Message-ID: <2f9b32af-dc25-a310-c0d1-f8c2fcd5b2ce@btinternet.com> On 02/03/2023 19:40, Weatherby,Gerard wrote: > Haven?t look at it all in detail, but I?d replace the list comprehensions with a loop: > CopyOfWords = list(Words) > Words = [(w[1:] if w[0] == ch else w) for w in Words] > Words = [w for w in Words if w != ''] > nextWords = [] > for w in CopyOfWords: > if w[0] != ch: > nextWords.append(w) > elif len(w) > 1: > nextWords.append(w[1:]) > assert Words == nextWords Why? Rob Cliffe > > From: Python-list on behalf of Rob Cliffe via Python-list > Date: Thursday, March 2, 2023 at 2:12 PM > To: python-list at python.org > Subject: Re: Packing Problem > *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** > > Slightly improved version (deals with multiple characters together > instead of one at a time): > > # Pack.py > def Pack(Words): > if not Words: > return '' > # The method is to build up the result by adding letters at the > beginning > # and working forward, and by adding letters at the end, working > backwards, > # meanwhile shrinking the words in the list. > Words = list(Words) # Don't mutate the original > Initial = '' > Final = '' > while True: > # It is safe to add an initial letter (of one or more of the > words) if > # EITHER There is no word that contains it as > # a non-initial letter but not as an initial letter. > # OR All words start with it. > while True: > FirstLetters = set(w[0] for w in Words) > FirstLettersSafe = sorted(ch for ch in FirstLetters if > all(w[0]==ch for w in Words) > or not any(ch in w[1:] and w[0]!=ch for w in Words)) > # sorted() to make the answer deterministic > # (not dependent on set ordering) > if not FirstLettersSafe: > break > AnyProgress = True > Initial += ''.join(FirstLettersSafe) # Build up the > answer from the beginning > Words = [ (w[1:] if w[0] in FirstLettersSafe else w) for w > in Words ] > Words = [ w for w in Words if w != ''] > if not Words: > return Initial + Final > # It is safe to add a final letter (of one or more of the words) of > # EITHER There is no word that contains it as > # a non-final letter but not as a final letter. > # OR All words end with it. > while True: > LastLetters = set(w[-1] for w in Words) > LastLettersSafe = sorted(ch for ch in LastLetters if > all(w[-1]==ch for w in Words) > or not any(ch in w[:-1] and w[-1]!=ch for w in Words)) > # sorted() to make the answer deterministic > # (not dependent on set ordering) > if not LastLettersSafe: > break > Final = ''.join(LastLettersSafe) + Final # Build up the > answer from the end > Words = [ (w[:-1] if w[-1] in LastLettersSafe else w) for w > in Words ] > Words = [ w for w in Words if w != ''] > if not Words: > return Initial + Final > if not (FirstLettersSafe or LastLettersSafe): > break # stuck > # Try all the possibilities for the next letter to add at the > beginning, > # with recursive calls, and pick one that gives a shortest answer: > BestResult = None > for ch in FirstLetters: > Words2 = list( (w[1:] if w[0] == ch else w) for w in Words ) > Words2 = [ w for w in Words2 if w != '' ] > res = ch + Pack(Words2) > if BestResult is None or len(res) < len(BestResult): > BestResult = res > return Initial + BestResult + Final > > print(Pack(['APPLE', 'PIE', 'APRICOT', 'BANANA', 'CANDY'])) > > Rob Cliffe > -- > https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!l3ysx0BUPZBdKdwb9F8mw4BAE2UIflvNqWeZLfALY2kjEo9e4KTy6fEYoGCTileOUtYe0yp6nL18ymdOguC3TGagEA$ From gvanem at yahoo.no Sat Mar 18 22:52:12 2023 From: gvanem at yahoo.no (Gisle Vanem) Date: Sun, 19 Mar 2023 03:52:12 +0100 Subject: Q: argparse.add_argument() In-Reply-To: <1de7b18b-9e4d-2433-ae2e-001a8f3cb4a4@tompassin.net> References: <1bc9f382-73fb-b43b-7ca0-036544a18544.ref@yahoo.no> <1bc9f382-73fb-b43b-7ca0-036544a18544@yahoo.no> <1de7b18b-9e4d-2433-ae2e-001a8f3cb4a4@tompassin.net> Message-ID: Thomas Passin wrote: > So please, try to think out how your questions will seem to the reader, and be clear about what you are asking.? You may > not know the terminology that some other people use, but don't let that stop you from being clear about what you really > need to find out.? Including more context is likely to be helpful, too.? Don't leave it to the readers to infer what you > were thinking of. I'll do that. My post was written in a bit of a hurry and frustration after struggling with my 'typo' for 30 minutes. -- --gv From list1 at tompassin.net Sat Mar 18 23:04:48 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 18 Mar 2023 23:04:48 -0400 Subject: Q: argparse.add_argument() In-Reply-To: References: <1bc9f382-73fb-b43b-7ca0-036544a18544.ref@yahoo.no> <1bc9f382-73fb-b43b-7ca0-036544a18544@yahoo.no> <1de7b18b-9e4d-2433-ae2e-001a8f3cb4a4@tompassin.net> Message-ID: <0747fd7f-9a5a-881f-b595-baa5217e584e@tompassin.net> On 3/18/2023 10:52 PM, Gisle Vanem via Python-list wrote: > Thomas Passin wrote: > >> So please, try to think out how your questions will seem to the >> reader, and be clear about what you are asking.? You may not know the >> terminology that some other people use, but don't let that stop you >> from being clear about what you really need to find out.? Including >> more context is likely to be helpful, too.? Don't leave it to the >> readers to infer what you were thinking of. > > I'll do that. My post was written in a bit of a hurry > and frustration after struggling with my 'typo' for > 30 minutes. Been there too :) From pengyu.ut at gmail.com Sat Mar 18 22:49:45 2023 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 18 Mar 2023 21:49:45 -0500 Subject: How to get get_body() to work? (about email) Message-ID: Hi, https://docs.python.org/3/library/email.parser.html It says "For MIME messages, the root object will return True from its is_multipart() method, and the subparts can be accessed via the payload manipulation methods, such as get_body(), iter_parts(), and walk()." But when I try the following code, get_body() is not found. How to get get_body() to work? $ python3 -c 'import email, sys; msg = email.message_from_string(sys.stdin.read()); print(msg.get_body())' <<< some_text Traceback (most recent call last): File "", line 1, in AttributeError: 'Message' object has no attribute 'get_body' -- Regards, Peng From list1 at tompassin.net Sun Mar 19 13:34:00 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 19 Mar 2023 13:34:00 -0400 Subject: How to get get_body() to work? (about email) In-Reply-To: References: Message-ID: On 3/18/2023 10:49 PM, Peng Yu wrote: > Hi, > > https://docs.python.org/3/library/email.parser.html > > It says "For MIME messages, the root object will return True from its > is_multipart() method, and the subparts can be accessed via the > payload manipulation methods, such as get_body(), iter_parts(), and > walk()." > > But when I try the following code, get_body() is not found. How to get > get_body() to work? > > $ python3 -c 'import email, sys; msg = > email.message_from_string(sys.stdin.read()); print(msg.get_body())' > <<< some_text > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'Message' object has no attribute 'get_body' > A Message object does not have a get_body method, but an EmailMessage object does. In the Python 3.10 docs, Just before the part you quoted, there is this sentence: "You can pass the parser a bytes, string or file object, and the parser will return to you the root EmailMessage instance of the object structure". So if you want to use get_body(), you should be feeding the parser your message string, rather than using email.message_from_string(), which returns a Message, not an EmailMessage. With a Message object, you could use get_payload(), which will give you a list of Messages for each MIME part of the document. When a part is not a multipart, it will give you a string, which sounds like what you want to end up with. (see https://docs.python.org/3.10/library/email.compat32-message.html) From greg.ewing at canterbury.ac.nz Sun Mar 19 17:59:03 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 20 Mar 2023 10:59:03 +1300 Subject: How to get get_body() to work? (about email) In-Reply-To: References: Message-ID: On 20/03/23 7:07 am, Jon Ribbens wrote: > Ah, apparently it got removed in Python 3, which is a bit odd as the > last I heard it was added in Python 2.2 in order to achieve consistency > with other types. As far as I remember, the file type came into existence with type/class unification, and "open" became an alias for the file type, so you could use open() and file() interchangeably. With the Unicode revolution in Python 3, file handling got a lot more complicated. Rather than a single file type, there are now a bunch of classes that handle low-level I/O, encoding/decoding, etc, and open() is a function again that builds the appropriate combination of underlying objects. -- Greg From jon+usenet at unequivocal.eu Sun Mar 19 13:20:24 2023 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 19 Mar 2023 17:20:24 -0000 (UTC) Subject: How to get get_body() to work? (about email) References: Message-ID: On 2023-03-19, Stefan Ram wrote: > Peng Yu writes: >>But when I try the following code, get_body() is not found. How to get >>get_body() to work? > > Did you know that this post of mine here was posted to > Usenet with a Python script I wrote? > > That Python script has a function to show the body of > a post before posting. The post is contained in a file, > so it reads the post from that file. > > I copy it here, maybe it can help some people to see > how I do this. > > # Python 3.5 > > import email > > ... > > def showbody( file ): # lightly edited for posting on 2023-03-19 > output = '' > msg = email.message_from_binary_file\ > ( file, policy=email.policy.default ) I wouldn't generally be pedantic about code style, but that's giving me painful convulsions. Backslashes for line continuations are generally considered a bad idea (as they mean that any whitespace after the backslash, which is often invisible, becomes significant). And not indenting the continuation line(s) is pretty shocking. Writing it as below is objectively better: msg = email.message_from_binary_file( file, policy=email.policy.default ) (Also, I too find it annoying to have to avoid, but calling a local variable 'file' is somewhat suspect since it shadows the builtin.) From jon+usenet at unequivocal.eu Sun Mar 19 14:07:53 2023 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 19 Mar 2023 18:07:53 -0000 (UTC) Subject: How to get get_body() to work? (about email) References: Message-ID: On 2023-03-19, Stefan Ram wrote: > Jon Ribbens writes: >>(Also, I too find it annoying to have to avoid, but calling a local >>variable 'file' is somewhat suspect since it shadows the builtin.) > > Thanks for your remarks, but I'm not aware > of such a predefined name "file"! Ah, apparently it got removed in Python 3, which is a bit odd as the last I heard it was added in Python 2.2 in order to achieve consistency with other types. From jon+usenet at unequivocal.eu Mon Mar 20 08:41:57 2023 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 20 Mar 2023 12:41:57 -0000 (UTC) Subject: How to get get_body() to work? (about email) References: Message-ID: On 2023-03-19, Greg Ewing wrote: > On 20/03/23 7:07 am, Jon Ribbens wrote: >> Ah, apparently it got removed in Python 3, which is a bit odd as the >> last I heard it was added in Python 2.2 in order to achieve consistency >> with other types. > > As far as I remember, the file type came into existence > with type/class unification, and "open" became an alias > for the file type, so you could use open() and file() > interchangeably. > > With the Unicode revolution in Python 3, file handling got > a lot more complicated. Rather than a single file type, > there are now a bunch of classes that handle low-level I/O, > encoding/decoding, etc, and open() is a function again > that builds the appropriate combination of underlying > objects. This is true, however there does exist a base class which, according to the documentation, underlies all of the different IO classes - IOBase - so it might have been neater to make 'file' be an alias for that. From edmondo.giovannozzi at gmail.com Mon Mar 20 11:21:12 2023 From: edmondo.giovannozzi at gmail.com (Edmondo Giovannozzi) Date: Mon, 20 Mar 2023 08:21:12 -0700 (PDT) Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> <20230318122042.aktojdmubrxsy4kl@hjp.at> Message-ID: > > def sum1(): > > s = 0 > > for i in range(1000000): > > s += i > > return s > > > > def sum2(): > > return sum(range(1000000)) > Here you already have the numbers you want to add. Actually using numpy you'll be much faster in this case: ? import numpy as np ? def sum3(): ? return np.arange(1_000_000, dtype=np.int64).sum() On my computer sum1 takes 44 ms, while the numpy version just 2.6 ms One problem is that sum2 gives the wrong result. This is why I used np.arange with dtype=np.int64. sum2 evidently doesn't uses the python "big integers" e restrict the result to 32 bits. From python at mrabarnett.plus.com Mon Mar 20 13:42:44 2023 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 20 Mar 2023 17:42:44 +0000 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> <20230318122042.aktojdmubrxsy4kl@hjp.at> Message-ID: On 2023-03-20 15:21, Edmondo Giovannozzi wrote: > >> > def sum1(): >> > s = 0 >> > for i in range(1000000): >> > s += i >> > return s >> > >> > def sum2(): >> > return sum(range(1000000)) >> Here you already have the numbers you want to add. > > Actually using numpy you'll be much faster in this case: > > ? import numpy as np > ? def sum3(): > ? return np.arange(1_000_000, dtype=np.int64).sum() > > On my computer sum1 takes 44 ms, while the numpy version just 2.6 ms > One problem is that sum2 gives the wrong result. This is why I used np.arange with dtype=np.int64. > > sum2 evidently doesn't uses the python "big integers" e restrict the result to 32 bits. > On my computer they all give the same result, as I'd expect. From list1 at tompassin.net Mon Mar 20 13:45:01 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 20 Mar 2023 13:45:01 -0400 Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> <20230318122042.aktojdmubrxsy4kl@hjp.at> Message-ID: <5eafc0f0-bd40-7025-40fb-d2d520891d1d@tompassin.net> On 3/20/2023 11:21 AM, Edmondo Giovannozzi wrote: > >>> def sum1(): >>> s = 0 >>> for i in range(1000000): >>> s += i >>> return s >>> >>> def sum2(): >>> return sum(range(1000000)) >> Here you already have the numbers you want to add. > > Actually using numpy you'll be much faster in this case: > > ? import numpy as np > ? def sum3(): > ? return np.arange(1_000_000, dtype=np.int64).sum() > > On my computer sum1 takes 44 ms, while the numpy version just 2.6 ms > One problem is that sum2 gives the wrong result. This is why I used np.arange with dtype=np.int64. On my computer they all give the same result. Python 3.10.9, PyQt version 6.4.1 Windows 10 AMD64 (build 10.0.19044) SP0 Processor: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz, 1690 Mhz, 4 Core(s), 8 Logical Processor(s) > sum2 evidently doesn't uses the python "big integers" e restrict the result to 32 bits. What about your system? Let's see if we can figure the reason for the difference. From edmondo.giovannozzi at gmail.com Tue Mar 21 08:22:43 2023 From: edmondo.giovannozzi at gmail.com (Edmondo Giovannozzi) Date: Tue, 21 Mar 2023 05:22:43 -0700 (PDT) Subject: Debugging reason for python running unreasonably slow when adding numbers In-Reply-To: References: <41f44497-bf2d-44e3-a99d-e7dddc1fa2c4@Spark> <20230314215211.kq4ohsrnz6vyigxw@hjp.at> <20230318122042.aktojdmubrxsy4kl@hjp.at> <5eafc0f0-bd40-7025-40fb-d2d520891d1d@tompassin.net> Message-ID: <8d6d4f5f-cb19-4d17-8d17-18b1ed59cf0an@googlegroups.com> Il giorno luned? 20 marzo 2023 alle 19:10:26 UTC+1 Thomas Passin ha scritto: > On 3/20/2023 11:21 AM, Edmondo Giovannozzi wrote: > > > >>> def sum1(): > >>> s = 0 > >>> for i in range(1000000): > >>> s += i > >>> return s > >>> > >>> def sum2(): > >>> return sum(range(1000000)) > >> Here you already have the numbers you want to add. > > > > Actually using numpy you'll be much faster in this case: > > > > ? import numpy as np > > ? def sum3(): > > ? return np.arange(1_000_000, dtype=np.int64).sum() > > > > On my computer sum1 takes 44 ms, while the numpy version just 2.6 ms > > One problem is that sum2 gives the wrong result. This is why I used np.arange with dtype=np.int64. > On my computer they all give the same result. > > Python 3.10.9, PyQt version 6.4.1 > Windows 10 AMD64 (build 10.0.19044) SP0 > Processor: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz, 1690 Mhz, 4 > Core(s), 8 Logical Processor(s) > > sum2 evidently doesn't uses the python "big integers" e restrict the result to 32 bits. > What about your system? Let's see if we can figure the reason for the > difference. I'm using winpython on Windows 11 and the python version is, well, 3.11: But it is my fault, sorry, I realised now that ipython is importing numpy namespace and the numpy sum function is overwriting the intrinsic sum. The intrinsic sum is behaving correctly and is faster when used in sum(range(1_000_000)) then the numpy version. From mohammednourkoujan2 at gmail.com Wed Mar 22 02:14:13 2023 From: mohammednourkoujan2 at gmail.com (Mohammed nour Koujan) Date: Wed, 22 Mar 2023 09:14:13 +0300 Subject: Hello I want help get rid of that message and help install Python properly and thank you Message-ID: From manta103g at gmail.com Wed Mar 22 08:09:21 2023 From: manta103g at gmail.com (a a) Date: Wed, 22 Mar 2023 05:09:21 -0700 (PDT) Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> Message-ID: <999f76d8-c88b-40bc-a209-8e6535dbd470n@googlegroups.com> On Saturday, 18 March 2023 at 20:12:22 UTC+1, Thomas Passin wrote: > On 3/17/2023 11:52 AM, a a wrote: > > On Friday, 17 March 2023 at 16:32:53 UTC+1, a a wrote: > >> On Friday, 17 March 2023 at 16:03:14 UTC+1, Thomas Passin wrote: > >>> On 3/16/2023 8:07 PM, a a wrote: > >>>> Crash report: > >>>> > >>>> Problem Caption: > >>>> Problem Event Name: APPCRASH > >>>> Application name: python.exe > >>>> Application version: 3.8.7150.1013 > >>>> Application time signature: 5fe0df5a > >>>> Error module name: _multiarray_umath.cp38-win32.pyd > >>>> Version of the module with the error: 0.0.0.0 > >>>> Time signature of the module with the error: 63dfe4cf > >>>> Exception code: c000001d > >>>> Exception offset: 000269c9 > >>>> Operating system version: 6.1.7601.2.1.0.256.48 > >>>> Regional Settings ID: 1045 > >>>> Additional information 1: 0a9e > >>>> Additional information 2: 0a9e372d3b4ad19135b953a78882e789 > >>>> Additional information 3: 0a9e > >>>> Additional information 4: 0a9e372d3b4ad19135b953a78882e789 > >>> This exception has been reported to have many causes, but one > >>> possibility seems to be that your computer may not support an advanced > >>> instruction set that the .pyd was compiled for. I found this one > >>> specifically mentioned on the Internet: Advanced Vector Extensions. If > >>> that were the case, you would either need to find a different version of > >>> the module, or upgrade the computer/OS. > >>> > >>> It would be worth trying to downgrade the multiarray version to an > >>> earlier one and see if that fixes the problem. > >> Thank you Thomas > >> for your kind reply. > >> > >> I am fully aware to be living on an old machine, old OS, Windows 7, 32-bit system > >> but I have visited every social chat support forum on the Internet: from Python to Matplotlib, Numpy, Twitter, Github. > >> > >> As a newbie I am not aware how to downgrade "the multiarray version to an > >> earlier one > >> > >> I simply tried to test Python code from > >> > >> > >> https://www.section.io/engineering-education/reading-and-processing-android-sensor-data-using-python-with-csv-read/ > >> > >> ==== > >> # Python program to read .csv file > >> > >> import numpy as np > >> import matplotlib.pyplot as plt > >> import csv > >> ---- > >> > >> "After importing the libraries, we now read the .csv file: > >> > >> with open('accl1.csv', 'r') as f: > >> data = list(csv.reader(f, delimiter=',')) #reading csv file > >> > >> ==== > >> Just read about AVE from Wikipedia > >> > >> https://en.wikipedia.org/wiki/Advanced_Vector_Extensions > > > > > > downloaded and run > > HWiNFO > > and AVE not supported, not greened out > That's too bad; you may be out of luck. It's possible that someone has > compiled the .pyd library in such a way that it does not need the > instruction set extensions. I'm sorry but I don't know how to find out > except by trying internet searches - or by downgrading to earlier > versions of Numpy hoping to find one that works and also can be used by > the other libraries/programs that need to use it. Thank you Thomas for youre kind help. You are the real Python PRO, you deserve Nobel Prize in Python. I operated an old Dell computer with Windows XP preinstalled and upgraded XP to Windows 7 to get some web services to work. Unfortunately I failed to find and install driver for video controller since none supported by Dell. Visited many driver sites (Intel Driver Assistant included and more) without any success. So life with an old PC is not easy From ikorot01 at gmail.com Wed Mar 22 12:41:22 2023 From: ikorot01 at gmail.com (Igor Korot) Date: Wed, 22 Mar 2023 11:41:22 -0500 Subject: Hello I want help get rid of that message and help install Python properly and thank you In-Reply-To: References: Message-ID: Hi, On Wed, Mar 22, 2023 at 11:37?AM Mohammed nour Koujan wrote: > > > -- What message? Please don't post screenshots - copy and paste the errors from your machine... Thank you. > https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Wed Mar 22 15:48:56 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 22 Mar 2023 15:48:56 -0400 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: <999f76d8-c88b-40bc-a209-8e6535dbd470n@googlegroups.com> References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <999f76d8-c88b-40bc-a209-8e6535dbd470n@googlegroups.com> Message-ID: <67d59124-760b-b908-7b83-b2befdb4e899@tompassin.net> On 3/22/2023 8:09 AM, a a wrote: > On Saturday, 18 March 2023 at 20:12:22 UTC+1, Thomas Passin wrote: >> On 3/17/2023 11:52 AM, a a wrote: >>> On Friday, 17 March 2023 at 16:32:53 UTC+1, a a wrote: >>>> On Friday, 17 March 2023 at 16:03:14 UTC+1, Thomas Passin wrote: >>>>> On 3/16/2023 8:07 PM, a a wrote: >>>>>> Crash report: >>>>>> >>>>>> Problem Caption: >>>>>> Problem Event Name: APPCRASH >>>>>> Application name: python.exe >>>>>> Application version: 3.8.7150.1013 >>>>>> Application time signature: 5fe0df5a >>>>>> Error module name: _multiarray_umath.cp38-win32.pyd >>>>>> Version of the module with the error: 0.0.0.0 >>>>>> Time signature of the module with the error: 63dfe4cf >>>>>> Exception code: c000001d >>>>>> Exception offset: 000269c9 >>>>>> Operating system version: 6.1.7601.2.1.0.256.48 >>>>>> Regional Settings ID: 1045 >>>>>> Additional information 1: 0a9e >>>>>> Additional information 2: 0a9e372d3b4ad19135b953a78882e789 >>>>>> Additional information 3: 0a9e >>>>>> Additional information 4: 0a9e372d3b4ad19135b953a78882e789 >>>>> This exception has been reported to have many causes, but one >>>>> possibility seems to be that your computer may not support an advanced >>>>> instruction set that the .pyd was compiled for. I found this one >>>>> specifically mentioned on the Internet: Advanced Vector Extensions. If >>>>> that were the case, you would either need to find a different version of >>>>> the module, or upgrade the computer/OS. >>>>> >>>>> It would be worth trying to downgrade the multiarray version to an >>>>> earlier one and see if that fixes the problem. >>>> Thank you Thomas >>>> for your kind reply. >>>> >>>> I am fully aware to be living on an old machine, old OS, Windows 7, 32-bit system >>>> but I have visited every social chat support forum on the Internet: from Python to Matplotlib, Numpy, Twitter, Github. >>>> >>>> As a newbie I am not aware how to downgrade "the multiarray version to an >>>> earlier one >>>> >>>> I simply tried to test Python code from >>>> >>>> >>>> https://www.section.io/engineering-education/reading-and-processing-android-sensor-data-using-python-with-csv-read/ >>>> >>>> ==== >>>> # Python program to read .csv file >>>> >>>> import numpy as np >>>> import matplotlib.pyplot as plt >>>> import csv >>>> ---- >>>> >>>> "After importing the libraries, we now read the .csv file: >>>> >>>> with open('accl1.csv', 'r') as f: >>>> data = list(csv.reader(f, delimiter=',')) #reading csv file >>>> >>>> ==== >>>> Just read about AVE from Wikipedia >>>> >>>> https://en.wikipedia.org/wiki/Advanced_Vector_Extensions >>> >>> >>> downloaded and run >>> HWiNFO >>> and AVE not supported, not greened out >> That's too bad; you may be out of luck. It's possible that someone has >> compiled the .pyd library in such a way that it does not need the >> instruction set extensions. I'm sorry but I don't know how to find out >> except by trying internet searches - or by downgrading to earlier >> versions of Numpy hoping to find one that works and also can be used by >> the other libraries/programs that need to use it. > > > Thank you Thomas for youre kind help. > > You are the real Python PRO, you deserve Nobel Prize in Python. :) > I operated an old Dell computer with Windows XP preinstalled > and upgraded XP to Windows 7 to get some web services to work. > > Unfortunately I failed to find and install driver for video controller since none supported by Dell. > > Visited many driver sites (Intel Driver Assistant included and more) > without any success. > > So life with an old PC is not easy I reused my 10-year-old Sony VAIO laptop (it had Windows 8, IIRC) to be a Linux machine - I got a 1T external solid state drive, set up the BIOS to boot from it, and installed Linux Mint. If you are willing to tackle Linux, this might be a good way to go. I recommend Mint for newcomers to Linux. The computer is much snappier and pleasant to use than it was under Windows. I mostly use it as a backup computer. I had to to without my main computer for a week or so, and the old machine made a fine substitute. I even copied all my Thunderbird emails over and used email all the week without losing any messages. Actually, the keyboard on that old computer is much better than I've got on my new one, although a few keys are getting a little flaky. I was able to compile some version of Python on it, though I forget why I needed to do that. With this setup, you could install a newer version of Python, and Numpy would work - it might get compiled during installation, but that's not a problem. It happens automatically. If fact, I know that it works because I have Numpy working on the computer. Of course, my computer has the instruction set extensions and your does not, so who knows if can be compiled for you. But it would probably be your best bet. Anyway, if you decide to try it out, let us know. And if you hit any problems, I might be able to help you. I'm not a Linux expert but I've installed various distributions maybe 20 times or more as virtual machines, and twice using an external drive, including running Tomcat and MySQL as services. Once you get it installed and working, and learned some of its quirks (not too bad, mostly about installing programs and configuring the desktop to be more to your liking), it's not much different from using Windows. Well, batch files are really different... From arnaud at sphaero.org Thu Mar 23 04:46:50 2023 From: arnaud at sphaero.org (Arnaud Loonstra) Date: Thu, 23 Mar 2023 09:46:50 +0100 Subject: PyGILState_Release called twice in embedded application Message-ID: Hi all, I'm running in a crash due to a ResourceWarning (some socket is not closed in a used module) after calling PyGILState_Release. I'm running Python in a native thread (so a thread created by C not Python). I'm acquiring the GIL through PyGILState_Ensure before doing any CPYthon calls and releasing when finished using PyGILState_Release. This has worked fine. But now I'm using a python module (openai) which doesn't close its socket correctly which results in a ResourceWarning which triggers an assert. In the backtrace (below) I can see PyGILState_Release is called again. (7) while I've already called it (126). I can make the crash go away by adding import warnings warnings.simplefilter("ignore", ResourceWarning) to my python code. But I'd rather prevent this from happening in the first place. Any suggestion very welcomed cause I'm puzzled. Rg, Arnaud 1 __pthread_kill_implementation pthread_kill.c 44 0x7ffff6fcaccc 2 __pthread_kill_internal pthread_kill.c 78 0x7ffff6fcad2f 3 __GI_raise raise.c 26 0x7ffff6f7bef2 4 __GI_abort abort.c 79 0x7ffff6f66472 5 __assert_fail_base assert.c 92 0x7ffff6f66395 6 __GI___assert_fail assert.c 101 0x7ffff6f74df2 7 PyGILState_Release pystate.c 1742 0x7ffff7abcf9f 8 tracemalloc_raw_alloc _tracemalloc.c 779 0x7ffff7afa803 9 tracemalloc_raw_malloc _tracemalloc.c 789 0x7ffff7afa844 10 PyMem_RawMalloc obmalloc.c 586 0x7ffff79dab8d 11 decode_current_locale fileutils.c 472 0x7ffff7ada4ab 12 _Py_DecodeLocaleEx fileutils.c 598 0x7ffff7adafce 13 unicode_decode_locale unicodeobject.c 3970 0x7ffff7a13b65 14 PyUnicode_DecodeLocale unicodeobject.c 4012 0x7ffff7a18c79 15 PyErr_SetFromErrnoWithFilenameObjects errors.c 772 0x7ffff7a94178 16 PyErr_SetFromErrnoWithFilenameObject errors.c 750 0x7ffff7a942ce 17 posix_path_object_error posixmodule.c 1709 0x7ffff7ae4201 18 path_object_error posixmodule.c 1719 0x7ffff7ae420f 19 path_error posixmodule.c 1737 0x7ffff7ae4221 20 posix_do_stat posixmodule.c 2565 0x7ffff7af42f7 21 os_stat_impl posixmodule.c 2897 0x7ffff7af4491 22 os_stat posixmodule.c.h 71 0x7ffff7af45e5 23 cfunction_vectorcall_FASTCALL_KEYWORDS methodobject.c 443 0x7ffff79d2ece 24 _PyObject_VectorcallTstate pycore_call.h 92 0x7ffff798b579 25 PyObject_Vectorcall call.c 299 0x7ffff798b65e 26 _PyEval_EvalFrameDefault ceval.c 4772 0x7ffff7a75453 27 _PyEval_EvalFrame pycore_ceval.h 73 0x7ffff7a79887 28 _PyEval_Vector ceval.c 6435 0x7ffff7a799b1 29 _PyFunction_Vectorcall call.c 393 0x7ffff798b215 30 _PyObject_VectorcallTstate pycore_call.h 92 0x7ffff798b579 31 PyObject_CallOneArg call.c 376 0x7ffff798b6cd 32 call_show_warning _warnings.c 609 0x7ffff7a31d24 33 warn_explicit _warnings.c 746 0x7ffff7a3223b 34 do_warn _warnings.c 947 0x7ffff7a3236f 35 warn_unicode _warnings.c 1106 0x7ffff7a32414 36 _PyErr_WarnFormatV _warnings.c 1126 0x7ffff7a32481 37 PyErr_ResourceWarning _warnings.c 1177 0x7ffff7a32d38 38 sock_finalize socketmodule.c 5073 0x7ffff6840cf3 39 PyObject_CallFinalizer object.c 208 0x7ffff79d6449 40 PyObject_CallFinalizerFromDealloc object.c 226 0x7ffff79d75ac 41 subtype_dealloc typeobject.c 1382 0x7ffff79ecf81 42 _Py_Dealloc object.c 2390 0x7ffff79d6c38 43 Py_DECREF object.h 527 0x7ffff79c116e 44 Py_XDECREF object.h 602 0x7ffff79c118d 45 free_keys_object dictobject.c 664 0x7ffff79c120a 46 dictkeys_decref dictobject.c 324 0x7ffff79c130f 47 dict_dealloc dictobject.c 2378 0x7ffff79c2eeb 48 _Py_Dealloc object.c 2390 0x7ffff79d6c38 49 Py_DECREF object.h 527 0x7ffff79eb06b 50 subtype_dealloc typeobject.c 1438 0x7ffff79ed138 51 _Py_Dealloc object.c 2390 0x7ffff79d6c38 52 Py_DECREF object.h 527 0x7ffff7affa77 53 deque_clear _collectionsmodule.c 625 0x7ffff7b01e10 54 deque_dealloc _collectionsmodule.c 1311 0x7ffff7b030d9 55 _Py_Dealloc object.c 2390 0x7ffff79d6c38 56 Py_DECREF object.h 527 0x7ffff79c116e 57 Py_XDECREF object.h 602 0x7ffff79c118d 58 _PyObject_FreeInstanceAttributes dictobject.c 5583 0x7ffff79ca68a 59 subtype_dealloc typeobject.c 1442 0x7ffff79ed18d 60 _Py_Dealloc object.c 2390 0x7ffff79d6c38 61 Py_DECREF object.h 527 0x7ffff79c116e 62 Py_XDECREF object.h 602 0x7ffff79c118d 63 _PyObject_FreeInstanceAttributes dictobject.c 5583 0x7ffff79ca68a 64 subtype_dealloc typeobject.c 1442 0x7ffff79ed18d 65 _Py_Dealloc object.c 2390 0x7ffff79d6c38 66 Py_DECREF object.h 527 0x7ffff79c116e 67 Py_XDECREF object.h 602 0x7ffff79c118d 68 free_keys_object dictobject.c 672 0x7ffff79c127f 69 dictkeys_decref dictobject.c 324 0x7ffff79c130f 70 dict_dealloc dictobject.c 2378 0x7ffff79c2eeb 71 odict_dealloc odictobject.c 1364 0x7ffff79ccc8c 72 _Py_Dealloc object.c 2390 0x7ffff79d6c38 73 Py_DECREF object.h 527 0x7ffff79c116e 74 Py_XDECREF object.h 602 0x7ffff79c118d 75 _PyObject_FreeInstanceAttributes dictobject.c 5583 0x7ffff79ca68a 76 subtype_dealloc typeobject.c 1442 0x7ffff79ed18d 77 _Py_Dealloc object.c 2390 0x7ffff79d6c38 78 Py_DECREF object.h 527 0x7ffff79c116e 79 Py_XDECREF object.h 602 0x7ffff79c118d 80 _PyObject_FreeInstanceAttributes dictobject.c 5583 0x7ffff79ca68a 81 subtype_dealloc typeobject.c 1442 0x7ffff79ed18d 82 _Py_Dealloc object.c 2390 0x7ffff79d6c38 83 Py_DECREF object.h 527 0x7ffff79c116e 84 Py_XDECREF object.h 602 0x7ffff79c118d 85 _PyObject_FreeInstanceAttributes dictobject.c 5583 0x7ffff79ca68a 86 subtype_dealloc typeobject.c 1442 0x7ffff79ed18d 87 _Py_Dealloc object.c 2390 0x7ffff79d6c38 88 Py_DECREF object.h 527 0x7ffff79c116e 89 Py_XDECREF object.h 602 0x7ffff79c118d 90 free_keys_object dictobject.c 664 0x7ffff79c120a 91 dictkeys_decref dictobject.c 324 0x7ffff79c130f 92 dict_dealloc dictobject.c 2378 0x7ffff79c2eeb 93 odict_dealloc odictobject.c 1364 0x7ffff79ccc8c 94 _Py_Dealloc object.c 2390 0x7ffff79d6c38 95 Py_DECREF object.h 527 0x7ffff79c116e 96 Py_XDECREF object.h 602 0x7ffff79c118d 97 _PyObject_FreeInstanceAttributes dictobject.c 5583 0x7ffff79ca68a 98 subtype_dealloc typeobject.c 1442 0x7ffff79ed18d 99 _Py_Dealloc object.c 2390 0x7ffff79d6c38 100 Py_DECREF object.h 527 0x7ffff79c116e 101 Py_XDECREF object.h 602 0x7ffff79c118d 102 free_keys_object dictobject.c 664 0x7ffff79c120a 103 dictkeys_decref dictobject.c 324 0x7ffff79c130f 104 dict_dealloc dictobject.c 2378 0x7ffff79c2eeb 105 _Py_Dealloc object.c 2390 0x7ffff79d6c38 106 Py_DECREF object.h 527 0x7ffff79c116e 107 delitem_common dictobject.c 1986 0x7ffff79c4deb 108 _PyDict_DelItem_KnownHash dictobject.c 2028 0x7ffff79c6c8b 109 PyDict_DelItem dictobject.c 2003 0x7ffff79c6d3a 110 _localdummy_destroyed _threadmodule.c 1044 0x7ffff7b31a85 111 cfunction_vectorcall_O methodobject.c 514 0x7ffff79d30f5 112 _PyObject_VectorcallTstate pycore_call.h 92 0x7ffff798b579 113 PyObject_CallOneArg call.c 376 0x7ffff798b6cd 114 handle_callback weakrefobject.c 931 0x7ffff7a300ab 115 PyObject_ClearWeakRefs weakrefobject.c 977 0x7ffff7a305cd 116 localdummy_dealloc _threadmodule.c 673 0x7ffff7b31f18 117 _Py_Dealloc object.c 2390 0x7ffff79d6c38 118 Py_DECREF object.h 527 0x7ffff79c116e 119 Py_XDECREF object.h 602 0x7ffff79c118d 120 free_keys_object dictobject.c 664 0x7ffff79c120a 121 dictkeys_decref dictobject.c 324 0x7ffff79c130f 122 dict_dealloc dictobject.c 2378 0x7ffff79c2eeb 123 _Py_Dealloc object.c 2390 0x7ffff79d6c38 124 Py_DECREF object.h 527 0x7ffff7aba1c9 125 PyThreadState_Clear pystate.c 1029 0x7ffff7abc790 126 PyGILState_Release pystate.c 1743 0x7ffff7abcef3 127 pythonactor_socket pythonactor.c 1021 0x555555709488 128 pythonactor_handle_msg pythonactor.c 1113 0x5555557098a5 129 pythonactor_handler pythonactor.c 1077 0x555555709716 130 sphactor_actor_run_once sphactor_actor.c 965 0x55555599bdfa 131 sphactor_actor_run sphactor_actor.c 1052 0x55555599c1c0 132 s_thread_shim zactor.c 68 0x5555559a97de 133 start_thread pthread_create.c 442 0x7ffff6fc8fd4 134 clone3 clone3.S 81 0x7ffff704966c From barry at barrys-emacs.org Thu Mar 23 08:33:09 2023 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 23 Mar 2023 12:33:09 +0000 Subject: PyGILState_Release called twice in embedded application In-Reply-To: References: Message-ID: <0709E328-8035-4B81-ADE1-8170834DBB8F@barrys-emacs.org> > On 23 Mar 2023, at 08:46, Arnaud Loonstra wrote: > > Hi all, > > I'm running in a crash due to a ResourceWarning (some socket is not closed in a used module) after calling PyGILState_Release. > > I'm running Python in a native thread (so a thread created by C not Python). I'm acquiring the GIL through PyGILState_Ensure before doing any CPYthon calls and releasing when finished using PyGILState_Release. > > This has worked fine. But now I'm using a python module (openai) which doesn't close its socket correctly which results in a ResourceWarning which triggers an assert. > > In the backtrace (below) I can see PyGILState_Release is called again. (7) while I've already called it (126). > > I can make the crash go away by adding > > import warnings > warnings.simplefilter("ignore", ResourceWarning) > > to my python code. But I'd rather prevent this from happening in the first place. > > Any suggestion very welcomed cause I'm puzzled. What 3rd party C extension are you running with? I'd be surprised if the cpython code was the issue. Barry > > Rg, > > Arnaud > > 1 __pthread_kill_implementation pthread_kill.c 44 0x7ffff6fcaccc > 2 __pthread_kill_internal pthread_kill.c 78 0x7ffff6fcad2f > 3 __GI_raise raise.c 26 0x7ffff6f7bef2 > 4 __GI_abort abort.c 79 0x7ffff6f66472 > 5 __assert_fail_base assert.c 92 0x7ffff6f66395 > 6 __GI___assert_fail assert.c 101 0x7ffff6f74df2 > 7 PyGILState_Release pystate.c 1742 0x7ffff7abcf9f > 8 tracemalloc_raw_alloc _tracemalloc.c 779 0x7ffff7afa803 > 9 tracemalloc_raw_malloc _tracemalloc.c 789 0x7ffff7afa844 > 10 PyMem_RawMalloc obmalloc.c 586 0x7ffff79dab8d > 11 decode_current_locale fileutils.c 472 0x7ffff7ada4ab > 12 _Py_DecodeLocaleEx fileutils.c 598 0x7ffff7adafce > 13 unicode_decode_locale unicodeobject.c 3970 0x7ffff7a13b65 > 14 PyUnicode_DecodeLocale unicodeobject.c 4012 0x7ffff7a18c79 > 15 PyErr_SetFromErrnoWithFilenameObjects errors.c 772 0x7ffff7a94178 > 16 PyErr_SetFromErrnoWithFilenameObject errors.c 750 0x7ffff7a942ce > 17 posix_path_object_error posixmodule.c 1709 0x7ffff7ae4201 > 18 path_object_error posixmodule.c 1719 0x7ffff7ae420f > 19 path_error posixmodule.c 1737 0x7ffff7ae4221 > 20 posix_do_stat posixmodule.c 2565 0x7ffff7af42f7 > 21 os_stat_impl posixmodule.c 2897 0x7ffff7af4491 > 22 os_stat posixmodule.c.h 71 0x7ffff7af45e5 > 23 cfunction_vectorcall_FASTCALL_KEYWORDS methodobject.c 443 0x7ffff79d2ece > 24 _PyObject_VectorcallTstate pycore_call.h 92 0x7ffff798b579 > 25 PyObject_Vectorcall call.c 299 0x7ffff798b65e > 26 _PyEval_EvalFrameDefault ceval.c 4772 0x7ffff7a75453 > 27 _PyEval_EvalFrame pycore_ceval.h 73 0x7ffff7a79887 > 28 _PyEval_Vector ceval.c 6435 0x7ffff7a799b1 > 29 _PyFunction_Vectorcall call.c 393 0x7ffff798b215 > 30 _PyObject_VectorcallTstate pycore_call.h 92 0x7ffff798b579 > 31 PyObject_CallOneArg call.c 376 0x7ffff798b6cd > 32 call_show_warning _warnings.c 609 0x7ffff7a31d24 > 33 warn_explicit _warnings.c 746 0x7ffff7a3223b > 34 do_warn _warnings.c 947 0x7ffff7a3236f > 35 warn_unicode _warnings.c 1106 0x7ffff7a32414 > 36 _PyErr_WarnFormatV _warnings.c 1126 0x7ffff7a32481 > 37 PyErr_ResourceWarning _warnings.c 1177 0x7ffff7a32d38 > 38 sock_finalize socketmodule.c 5073 0x7ffff6840cf3 > 39 PyObject_CallFinalizer object.c 208 0x7ffff79d6449 > 40 PyObject_CallFinalizerFromDealloc object.c 226 0x7ffff79d75ac > 41 subtype_dealloc typeobject.c 1382 0x7ffff79ecf81 > 42 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 43 Py_DECREF object.h 527 0x7ffff79c116e > 44 Py_XDECREF object.h 602 0x7ffff79c118d > 45 free_keys_object dictobject.c 664 0x7ffff79c120a > 46 dictkeys_decref dictobject.c 324 0x7ffff79c130f > 47 dict_dealloc dictobject.c 2378 0x7ffff79c2eeb > 48 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 49 Py_DECREF object.h 527 0x7ffff79eb06b > 50 subtype_dealloc typeobject.c 1438 0x7ffff79ed138 > 51 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 52 Py_DECREF object.h 527 0x7ffff7affa77 > 53 deque_clear _collectionsmodule.c 625 0x7ffff7b01e10 > 54 deque_dealloc _collectionsmodule.c 1311 0x7ffff7b030d9 > 55 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 56 Py_DECREF object.h 527 0x7ffff79c116e > 57 Py_XDECREF object.h 602 0x7ffff79c118d > 58 _PyObject_FreeInstanceAttributes dictobject.c 5583 0x7ffff79ca68a > 59 subtype_dealloc typeobject.c 1442 0x7ffff79ed18d > 60 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 61 Py_DECREF object.h 527 0x7ffff79c116e > 62 Py_XDECREF object.h 602 0x7ffff79c118d > 63 _PyObject_FreeInstanceAttributes dictobject.c 5583 0x7ffff79ca68a > 64 subtype_dealloc typeobject.c 1442 0x7ffff79ed18d > 65 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 66 Py_DECREF object.h 527 0x7ffff79c116e > 67 Py_XDECREF object.h 602 0x7ffff79c118d > 68 free_keys_object dictobject.c 672 0x7ffff79c127f > 69 dictkeys_decref dictobject.c 324 0x7ffff79c130f > 70 dict_dealloc dictobject.c 2378 0x7ffff79c2eeb > 71 odict_dealloc odictobject.c 1364 0x7ffff79ccc8c > 72 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 73 Py_DECREF object.h 527 0x7ffff79c116e > 74 Py_XDECREF object.h 602 0x7ffff79c118d > 75 _PyObject_FreeInstanceAttributes dictobject.c 5583 0x7ffff79ca68a > 76 subtype_dealloc typeobject.c 1442 0x7ffff79ed18d > 77 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 78 Py_DECREF object.h 527 0x7ffff79c116e > 79 Py_XDECREF object.h 602 0x7ffff79c118d > 80 _PyObject_FreeInstanceAttributes dictobject.c 5583 0x7ffff79ca68a > 81 subtype_dealloc typeobject.c 1442 0x7ffff79ed18d > 82 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 83 Py_DECREF object.h 527 0x7ffff79c116e > 84 Py_XDECREF object.h 602 0x7ffff79c118d > 85 _PyObject_FreeInstanceAttributes dictobject.c 5583 0x7ffff79ca68a > 86 subtype_dealloc typeobject.c 1442 0x7ffff79ed18d > 87 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 88 Py_DECREF object.h 527 0x7ffff79c116e > 89 Py_XDECREF object.h 602 0x7ffff79c118d > 90 free_keys_object dictobject.c 664 0x7ffff79c120a > 91 dictkeys_decref dictobject.c 324 0x7ffff79c130f > 92 dict_dealloc dictobject.c 2378 0x7ffff79c2eeb > 93 odict_dealloc odictobject.c 1364 0x7ffff79ccc8c > 94 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 95 Py_DECREF object.h 527 0x7ffff79c116e > 96 Py_XDECREF object.h 602 0x7ffff79c118d > 97 _PyObject_FreeInstanceAttributes dictobject.c 5583 0x7ffff79ca68a > 98 subtype_dealloc typeobject.c 1442 0x7ffff79ed18d > 99 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 100 Py_DECREF object.h 527 0x7ffff79c116e > 101 Py_XDECREF object.h 602 0x7ffff79c118d > 102 free_keys_object dictobject.c 664 0x7ffff79c120a > 103 dictkeys_decref dictobject.c 324 0x7ffff79c130f > 104 dict_dealloc dictobject.c 2378 0x7ffff79c2eeb > 105 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 106 Py_DECREF object.h 527 0x7ffff79c116e > 107 delitem_common dictobject.c 1986 0x7ffff79c4deb > 108 _PyDict_DelItem_KnownHash dictobject.c 2028 0x7ffff79c6c8b > 109 PyDict_DelItem dictobject.c 2003 0x7ffff79c6d3a > 110 _localdummy_destroyed _threadmodule.c 1044 0x7ffff7b31a85 > 111 cfunction_vectorcall_O methodobject.c 514 0x7ffff79d30f5 > 112 _PyObject_VectorcallTstate pycore_call.h 92 0x7ffff798b579 > 113 PyObject_CallOneArg call.c 376 0x7ffff798b6cd > 114 handle_callback weakrefobject.c 931 0x7ffff7a300ab > 115 PyObject_ClearWeakRefs weakrefobject.c 977 0x7ffff7a305cd > 116 localdummy_dealloc _threadmodule.c 673 0x7ffff7b31f18 > 117 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 118 Py_DECREF object.h 527 0x7ffff79c116e > 119 Py_XDECREF object.h 602 0x7ffff79c118d > 120 free_keys_object dictobject.c 664 0x7ffff79c120a > 121 dictkeys_decref dictobject.c 324 0x7ffff79c130f > 122 dict_dealloc dictobject.c 2378 0x7ffff79c2eeb > 123 _Py_Dealloc object.c 2390 0x7ffff79d6c38 > 124 Py_DECREF object.h 527 0x7ffff7aba1c9 > 125 PyThreadState_Clear pystate.c 1029 0x7ffff7abc790 > 126 PyGILState_Release pystate.c 1743 0x7ffff7abcef3 > 127 pythonactor_socket pythonactor.c 1021 0x555555709488 > 128 pythonactor_handle_msg pythonactor.c 1113 0x5555557098a5 > 129 pythonactor_handler pythonactor.c 1077 0x555555709716 > 130 sphactor_actor_run_once sphactor_actor.c 965 0x55555599bdfa > 131 sphactor_actor_run sphactor_actor.c 1052 0x55555599c1c0 > 132 s_thread_shim zactor.c 68 0x5555559a97de > 133 start_thread pthread_create.c 442 0x7ffff6fc8fd4 > 134 clone3 clone3.S 81 0x7ffff704966c > -- > https://mail.python.org/mailman/listinfo/python-list > From arnaud at sphaero.org Thu Mar 23 10:34:45 2023 From: arnaud at sphaero.org (Arnaud Loonstra) Date: Thu, 23 Mar 2023 15:34:45 +0100 Subject: PyGILState_Release called twice in embedded application In-Reply-To: <0709E328-8035-4B81-ADE1-8170834DBB8F@barrys-emacs.org> References: <0709E328-8035-4B81-ADE1-8170834DBB8F@barrys-emacs.org> Message-ID: <58852f4d-2654-a8be-a317-5219e30e21cf@sphaero.org> On 23-03-2023 13:33, Barry Scott wrote: > > >> On 23 Mar 2023, at 08:46, Arnaud Loonstra wrote: >> >> Hi all, >> >> I'm running in a crash due to a ResourceWarning (some socket is not closed in a used module) after calling PyGILState_Release. >> >> I'm running Python in a native thread (so a thread created by C not Python). I'm acquiring the GIL through PyGILState_Ensure before doing any CPYthon calls and releasing when finished using PyGILState_Release. >> >> This has worked fine. But now I'm using a python module (openai) which doesn't close its socket correctly which results in a ResourceWarning which triggers an assert. >> >> In the backtrace (below) I can see PyGILState_Release is called again. (7) while I've already called it (126). >> >> I can make the crash go away by adding >> >> import warnings >> warnings.simplefilter("ignore", ResourceWarning) >> >> to my python code. But I'd rather prevent this from happening in the first place. >> >> Any suggestion very welcomed cause I'm puzzled. > > What 3rd party C extension are you running with? > I'd be surprised if the cpython code was the issue. > > Barry I'm not using any 3rd party extension myself. But the issue is caused by the openai module using the requests module which is not closing sockets: https://github.com/openai/openai-python/issues/140 I'm not aware what C extensions they might use. Btw, I've tested this with python 3.8 and 3.11.2. Rg, Arnaud From list1 at tompassin.net Thu Mar 23 11:48:43 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 23 Mar 2023 11:48:43 -0400 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> Message-ID: <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> On 3/18/2023 3:05 PM, Thomas Passin wrote: >> downloaded and run HWiNFO and AVE not supported, not greened out > > That's too bad; you may be out of luck. It's possible that someone > has compiled the .pyd library in such a way that it does not need the > instruction set extensions. I'm sorry but I don't know how to find > out except by trying internet searches - or by downgrading to earlier > versions of Numpy hoping to find one that works and also can be used > by the other libraries/programs that need to use it. Here's a possibility to try - https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy "NumPy: a fundamental package needed for scientific computing with Python. Numpy+MKL is linked to the Intel? Math Kernel Library and includes required DLLs in the numpy.DLLs directory. Numpy+Vanilla is a minimal distribution, which does not include any optimized BLAS libray or C runtime DLLs." I didn't realize that Christoph Gohlke is still maintaining this site. I haven't needed to use it since PyPi got so much more complete about packages with binary code. He has tons of binary packages for all kinds of Python libraries. I think this one might work for you because it links to the Intel math library. So it may be able to use various or no instruction set extensions. If so, it could work with your old processor. Worth trying, anyway. From list1 at tompassin.net Thu Mar 23 13:16:38 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 23 Mar 2023 13:16:38 -0400 Subject: Python Infrequently Asked Questions Message-ID: <20c88e57-f6ec-5ff3-77d8-77b226aca84f@tompassin.net> I bookmarked this years ago and just came across it again. An oldie but goodie! http://norvig.com/python-iaq.html From barry at barrys-emacs.org Thu Mar 23 13:28:18 2023 From: barry at barrys-emacs.org (Barry) Date: Thu, 23 Mar 2023 17:28:18 +0000 Subject: PyGILState_Release called twice in embedded application In-Reply-To: <58852f4d-2654-a8be-a317-5219e30e21cf@sphaero.org> References: <58852f4d-2654-a8be-a317-5219e30e21cf@sphaero.org> Message-ID: > On 23 Mar 2023, at 14:34, Arnaud Loonstra wrote: > > ?On 23-03-2023 13:33, Barry Scott wrote: >>>> On 23 Mar 2023, at 08:46, Arnaud Loonstra wrote: >>> >>> Hi all, >>> >>> I'm running in a crash due to a ResourceWarning (some socket is not closed in a used module) after calling PyGILState_Release. >>> >>> I'm running Python in a native thread (so a thread created by C not Python). I'm acquiring the GIL through PyGILState_Ensure before doing any CPYthon calls and releasing when finished using PyGILState_Release. >>> >>> This has worked fine. But now I'm using a python module (openai) which doesn't close its socket correctly which results in a ResourceWarning which triggers an assert. >>> >>> In the backtrace (below) I can see PyGILState_Release is called again. (7) while I've already called it (126). >>> >>> I can make the crash go away by adding >>> >>> import warnings >>> warnings.simplefilter("ignore", ResourceWarning) >>> >>> to my python code. But I'd rather prevent this from happening in the first place. >>> >>> Any suggestion very welcomed cause I'm puzzled. >> What 3rd party C extension are you running with? >> I'd be surprised if the cpython code was the issue. >> Barry > > I'm not using any 3rd party extension myself. But the issue is caused by the openai module using the requests module which is not closing sockets: > > https://github.com/openai/openai-python/issues/140 > > I'm not aware what C extensions they might use. In gdb use info shared to see what is loaded. Leaving a socket open will not cause a logic error as you are encountering. I expect a bug in C/C++ cod3 that is not part of python itself. You are using 3rd party code, requests and openai that you name. Barry > > Btw, I've tested this with python 3.8 and 3.11.2. > > Rg, > > Arnaud > From egon at frerich.eu Thu Mar 23 13:44:13 2023 From: egon at frerich.eu (Egon Frerich) Date: Thu, 23 Mar 2023 18:44:13 +0100 Subject: Problem with __sub__ Message-ID: <5e621905-b5bd-ba0d-3c3d-90170001878b@frerich.eu> The class Betragswert is used for numerical values as string or integer and for additions and subtraction. If on the left side is '0' the result of a subtraction is wrong. *??? b1 = Betragswert(500) ??? b2 = 0 + b1 ??? b3 = 0 - b1 ??? b4 = 5 + b1 ??? b5 = 5 - b1* print(b1, b2, b3, b4, b5) shows 5,00 5,00 5,00 5,05 4,95; the third value (b3) should be -5,00 (not 5,00). Why is the substraction wrong? This is the module: import locale locale.setlocale(locale.LC_ALL, "") Trennzeichen = locale.localeconv()["thousands_sep"] def bereinigen(t): ??????? lg = len(t) ??????? if lg > 0: ??????????? if t[lg-1] == '\n': ??????????????? return t[0:lg-1] ??????? return t class Betragswert: ??? def __init__(self, Wert): ??????? self._Betrag = 0 ??????? if isinstance(Wert, type("123")): ??????????? "Zeichenkette wurde ?bergeben" ??????????? self._Betrag = _zeichenketteNACHganzzahl(Wert) ??????????? return ??????? if isinstance(Wert, type(23)): ??????????? "Cents wurden ?bergeben" ??????????? self._Betrag = int(Wert) ??????????? return ??????? if isinstance(Wert, type(self)): ??????????? "Instanz der Klasse Betragswert wurde ?bergeben" ??????????? self._Betrag = Wert.copy() ??????????? return ??????? raise TypeError("Umsetzung als Betragswert nicht m?glich: " + repr(Wert)) ??? def __str__(self): ??????? e, c = divmod(abs(self._Betrag), 100) ??????? cents = repr(c) ??????? cents = "0" * (2 - len(cents)) + cents ??????? return ( ??????????? "-"[: self._Betrag < 0] ??????????? + locale.format_string("%d", e, grouping=1) ??????????? + locale.localeconv()["decimal_point"] ??????????? + cents ??????? ) ??? def __repr__(self): ??????? return "Betragswert " + repr((str(self))) ??? def copy(self): ??????? return self._Betrag ??? def __cmp__(self, anderer): ??????? return cmp(self._Betrag, Betragswert(anderer)._Betrag) ??? def __neg__(self): ??????? return Betragswert(-self._Betrag) ??? def __abs__(self): ??????? if self._Betrag >= 0: ??????????? return self.copy() ??????? else: ??????????? return -self._Betrag ??? def __add__(self, zweiter): ??????? if not isinstance(zweiter, type(self)): ??????????? zweiter = Betragswert(zweiter) ??????? return Betragswert(self._Betrag + zweiter._Betrag) ??? def __radd__(self, zweiter): ??????? if not isinstance(zweiter, type(self)): ??????????? zweiter = Betragswert(zweiter) ??????? return Betragswert(self._Betrag + zweiter._Betrag) ??? def __sub__(self, zweiter): ??????? if not isinstance(zweiter, type(self)): ??????????? zweiter = Betragswert(zweiter) ??????? return Betragswert(self._Betrag - zweiter._Betrag) ??? def __rsub__(self, zweiter): ??????? if not isinstance(zweiter, type(self)): ??????????? zweiter = Betragswert(zweiter) ??????? return Betragswert(self._Betrag - zweiter._Betrag) ??? def hol(self): # notwendig f?r Tests ??????? return self._Betrag Reg_Ausdruck = ( ??? r""" ??? \s* ??? (?P[-+])? ??? ( ??????? (?P\d+) (""" ??? + "\\" ??? + locale.localeconv()["decimal_point"] ??? + r""" ??????????????????????? (?P\d*))? ??? | ??????? """ ??? + "\\" ??? + locale.localeconv()["decimal_point"] ??? + r""" ???????????????????????? (?P\d+) ??? ) ??? \s* $ """ ) import re _parser = re.compile(Reg_Ausdruck, re.VERBOSE).match del re def _zeichenketteNACHganzzahl(s): ??? s = bereinigen(s) ??? """s --> L""" ??? s = s.replace(Trennzeichen, "") ??? m = _parser(s) ??? if m is None: ??????? raise ValueError("Dies ist keine Zahl: " + repr(s)) ??? vor = m.group("vor") ??? if vor is None: ??????? vor = "0" ??????? nach = m.group("nurnach") ??? else: ??????? nach = m.group("nach") ??????? if nach is None or nach == "": ??????????? nach = "0" ??? if len(nach) == 1: ??????? nach = nach + "0" ??? elif len(nach) > 2: ??????? nach = nach[0:2] ??? b1 = Betragswert(500) ??? b2 = 0 + b1 ??? b3 = 0 - b1 ??? b4 = 5 + b1 ??? b5 = 5 - b1 ??? z = int(vor) * 100 + int(nach) ??? if m.group("vorzeichen") == "-": ??????? z = -z ??? return z if __name__ == '__main__': ??? b1 = Betragswert(500) ??? b2 = 0 + b1 ??? b3 = 0 - b1 ??? b4 = 5 + b1 ??? b5 = 5 - b1 ??? print(b1, b2, b3, b4, b5) From David.Raymond at tomtom.com Thu Mar 23 14:07:25 2023 From: David.Raymond at tomtom.com (David Raymond) Date: Thu, 23 Mar 2023 18:07:25 +0000 Subject: Problem with __sub__ In-Reply-To: <5e621905-b5bd-ba0d-3c3d-90170001878b@frerich.eu> References: <5e621905-b5bd-ba0d-3c3d-90170001878b@frerich.eu> Message-ID: I believe your problem is __rsub__, not __sub__. When you have then that uses the "r" version of the operators. In your __rsub__ (used when you have - ) you instead return - which is backwards. Notice how the final return should also be -4,95 and not the +4,95 it's returning. > If on the left side is '0' the result of a subtraction is wrong. > > * b1 = Betragswert(500) > b2 = 0 + b1 > b3 = 0 - b1 > b4 = 5 + b1 > b5 = 5 - b1* > > print(b1, b2, b3, b4, b5) shows 5,00 5,00 5,00 5,05 4,95; the third > value (b3) should be -5,00 (not 5,00). > > Why is the substraction wrong? > def __rsub__(self, zweiter): > if not isinstance(zweiter, type(self)): > zweiter = Betragswert(zweiter) > return Betragswert(self._Betrag - zweiter._Betrag) From mats at wichmann.us Thu Mar 23 15:38:29 2023 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 23 Mar 2023 13:38:29 -0600 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> Message-ID: <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> On 3/23/23 09:48, Thomas Passin wrote: > I didn't realize that Christoph Gohlke is still maintaining this site. Unless the the last-changed stuff stopped working, it's in a static state: by Christoph Gohlke.?Updated on 26 June 2022 at 07:27 UTC From list1 at tompassin.net Thu Mar 23 17:14:38 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 23 Mar 2023 17:14:38 -0400 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> Message-ID: <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> On 3/23/2023 3:38 PM, Mats Wichmann wrote: > On 3/23/23 09:48, Thomas Passin wrote: > >> I didn't realize that Christoph Gohlke is still maintaining this site. > > Unless the the last-changed stuff stopped working, it's in a static state: > > by Christoph Gohlke.?Updated on 26 June 2022 at 07:27 UTC I did see that. The OP needs a version that would work with Windows 7 and an older version of Python (3.7 or 3.8, IIRC), so things may work out. From patricksheehan.writer at gmail.com Sat Mar 25 16:03:55 2023 From: patricksheehan.writer at gmail.com (Patrick Sheehan) Date: Sat, 25 Mar 2023 16:03:55 -0400 Subject: Patrick Sheehan: Major Issues with Python Message-ID: Hello, I have been working with the attached book (See photo) to try to learn Python and so far it has been a complete nightmare trying to get python installed and operating correctly. I have received a plethora of error messages and consulted youtube videos and chat groups to try to remedy the issues. I am using a computer that is running Windows 10. I have installed, and un-installed several versions of Python and was able to complete the first two lessons in the attached book, but could not complete lesson 3 (Turtledemo)...Some of the error messages I have received include: "This app cannot run on your PC"; "Unable to initialize device PRN"; ?Python is not recognized as an internal or external command?: "Python was not found: run without arguments to install from Microsoft Store, or disable this shortcut from settings mange, app execution aliases:"...I have been at this for 4 days now at least three hours each day...Any information or help you can provide would be greatly appreciated. Additionally, I do have PyCharm installed (As you can tell, I am a beginner), is PyCharm the same thing as Python? Thank you in advance! Respectfully, Patrick Sheehan From mats at wichmann.us Sun Mar 26 09:31:12 2023 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 26 Mar 2023 07:31:12 -0600 Subject: Patrick Sheehan: Major Issues with Python In-Reply-To: References: Message-ID: On 3/25/23 14:03, Patrick Sheehan wrote: > Hello, > I have been working with the attached book (See photo) to try to learn > Python and so far it has been a complete nightmare trying to get python > installed and operating correctly. I have received a plethora of error > messages and consulted youtube videos and chat groups to try to remedy the > issues. I am using a computer that is running Windows 10. I have > installed, and un-installed several versions of Python and was able to > complete the first two lessons in the attached book, but could not complete > lesson 3 (Turtledemo)...Some of the error messages I have received > include: "This app cannot run on your PC"; "Unable to initialize device > PRN"; ?Python is not recognized as an internal or external command?: > "Python was not found: run without arguments to install from Microsoft > Store, or disable this shortcut from settings mange, app execution > aliases:"... If you installed the conventional way, use the command name "py" instead of "python" to run things from a command shell. Alternatively, you could try an installation of Python from the Microsoft Store (as the little stub program named python, which Microsoft preinstalls for the express purpose of giving you this hint). There are times when getting Python working without hassle is easier when going that route. You *can* add python to the search PATH, there's an option in the installer (you can rerun this from the Apps & features Settings applet)... in the screen for advanced options there's something that says "Add python to environment variables" or similar wording. >I have been at this for 4 days now at least three hours each > day...Any information or help you can provide would be greatly > appreciated. Additionally, I do have PyCharm installed (As you can tell, I > am a beginner), is PyCharm the same thing as Python? No. It's an "integrated development environment" - editor, debugger, source control wrangler and many other things. It still needs to have a working Python installed. It will probably find the installed Python more easily than you will. The concept of an IDE is you can do all your programming work without leaving it - you don't have to hop between editor, command line, and invoke other tools. PyCharm is only one of many entrants in this space for Python programmers. It's excellent, but I find it rather, ummm, "bulky", for beginners - there are a ton of features you'll not use early on in your journey, and thus I find it makes it much harder to find the things you do need in menus, help, etc. Up to you whether you push ahead with using it now, or leave it for a bit later when you're doing more complex things. We have no idea what book you're using, by the way, as the list strips images and other attachments. In any case, there are hundreds of Python books out now, most of us don't know about a particular one (unless we wrote it :) ) From python at mrabarnett.plus.com Sun Mar 26 09:33:14 2023 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 26 Mar 2023 14:33:14 +0100 Subject: Patrick Sheehan: Major Issues with Python In-Reply-To: References: Message-ID: <401ca0b9-520f-41c9-3369-802545f73054@mrabarnett.plus.com> On 2023-03-25 20:03, Patrick Sheehan wrote: > Hello, > I have been working with the attached book (See photo) to try to learn > Python and so far it has been a complete nightmare trying to get python > installed and operating correctly. I have received a plethora of error > messages and consulted youtube videos and chat groups to try to remedy the > issues. I am using a computer that is running Windows 10. I have > installed, and un-installed several versions of Python and was able to > complete the first two lessons in the attached book, but could not complete > lesson 3 (Turtledemo)...Some of the error messages I have received > include: "This app cannot run on your PC"; "Unable to initialize device > PRN"; ?Python is not recognized as an internal or external command?: > "Python was not found: run without arguments to install from Microsoft > Store, or disable this shortcut from settings mange, app execution > aliases:"...I have been at this for 4 days now at least three hours each > day...Any information or help you can provide would be greatly > appreciated. Additionally, I do have PyCharm installed (As you can tell, I > am a beginner), is PyCharm the same thing as Python? Thank you in advance! > This list strips attachments such as images, so I don't know which book you're referring to. I'd go for Python 3.11 and the installer "Windows installer (64-bit)" at https://www.python.org/downloads/release/python-3112/, i.e. "https://www.python.org/ftp/python/3.11.2/python-3.11.2-amd64.exe" (assuming that it's a 64-bit PC). To run Python, the recommended way is to use the Python Launcher, py.exe (so type "py my_program.py" in a Command window), or just double-click on it if it's a GUI program. As for PRN, that's the printer. Does anyone use PRN these days? And, no, PyCharm is not the same thing as Python. PyCharm is an IDE (integrated development environment) for Python, but Python is its own thing. From list1 at tompassin.net Sun Mar 26 09:45:25 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 26 Mar 2023 09:45:25 -0400 Subject: Patrick Sheehan: Major Issues with Python In-Reply-To: References: Message-ID: <33d04c41-f3cf-0de4-dee8-a7f10b642969@tompassin.net> On 3/25/2023 4:03 PM, Patrick Sheehan wrote: > Hello, I have been working with the attached book (See photo) Photos do not come through on this list, so don't bother to attach any. Type or copy-paste any useful text. > to try to learn Python and so far it has been a complete nightmare > trying to get python installed and operating correctly. I have > received a plethora of error messages and consulted youtube videos > and chat groups to try to remedy the issues. I am using a computer > that is running Windows 10. That's too bad. Normally a Python install on Windows is trouble free. Perhaps we can help. > I have installed, and un-installed several versions of Python Please give more information. What versions of Python, where did you get it, how did you install it, what options if any did you choose during the installation? > and was able to complete the first two lessons in the attached book, > but could not complete lesson 3 (Turtledemo)...Some of the error > messages I have received include: "This app cannot run on your PC"; > "Unable to initialize device PRN"; ?Python is not recognized as an > internal or external command?: "Python was not found: run without > arguments to install from Microsoft Store, or disable this shortcut > from settings mange, app execution aliases:" You need to tell us just what you have done. What was this "lesson" supposed to do? Did you try to run it while you were working in PyCharm? Just how did you try to run the lesson? > ...I have been at this > for 4 days now at least three hours each day...Any information or > help you can provide would be greatly appreciated. Additionally, I > do have PyCharm installed (As you can tell, I am a beginner), is > PyCharm the same thing as Python? Thank you in advance! No, PyCharm is an editor and Python IDE; it is not the same as Python. Python is a programming language. The problems you have been having could be caused by PyCharm not being set up to work with your installation of Python. To see if Python has been installed correctly, open a Windows console. If you don't know how, one way is to hit the Windows key and type "cmd". Windows will offer "Command Prompt". Hit the ENTER key to accept it, and a console window will open. (There are more convenient ways, but we don't need to get into them right now). In the console window, type (without the quotes) "py -V". You should see something like this (The first line is what I typed, the second line is the response): C:\Users\tom>py -V Python 3.10.9 If this works, Python has been installed and apparently working. If it is working, save the Python program from your lesson as a file with a name such as such as "lesson1.py". In an open console window. try to run it by typing py lesson1.py Instead of just "lesson1.py", you will either need to change directory (using the cd command) to the directory that contains that file, or you will need to use the full path to the file. For example, if the file is c:\temp\python\lesson1.py then run it by typing py c:\temp\python\lesson1.py Let us know how it goes. From jenkris at tutanota.com Sun Mar 26 13:43:44 2023 From: jenkris at tutanota.com (Jen Kris) Date: Sun, 26 Mar 2023 19:43:44 +0200 (CEST) Subject: How does a method of a subclass become a method of the base class? Message-ID: The base class: class Constraint(object): def __init__(self, strength): ??????? super(Constraint, self).__init__() ??????? self.strength = strength def satisfy(self, mark): ??????? global planner ??????? self.choose_method(mark) The subclass: class UrnaryConstraint(Constraint): def __init__(self, v, strength): ??????? super(UrnaryConstraint, self).__init__(strength) ??????? self.my_output = v ??????? self.satisfied = False ??????? self.add_constraint() ??? def choose_method(self, mark): ??????? if self.my_output.mark != mark and \ ?????????? Strength.stronger(self.strength, self.my_output.walk_strength): self.satisfied = True ??????? else: ??????????? self.satisfied = False The base class Constraint doesn?t have a "choose_method" class method, but it?s called as self.choose_method(mark) on the final line of Constraint shown above.? My question is:? what makes "choose_method" a method of the base class, called as self.choose_method instead of UrnaryConstraint.choose_method?? Is it super(UrnaryConstraint, self).__init__(strength) or just the fact that Constraint is its base class?? Also, this program also has a class BinaryConstraint that is also a subclass of Constraint and it also has a choose_method class method that is similar but not identical: def choose_method(self, mark): ??? if self.v1.mark == mark: ??????????? if self.v2.mark != mark and Strength.stronger(self.strength, self.v2.walk_strength): ??????????????? self.direction = Direction.FORWARD ??????????? else: ??????????????? self.direction = Direction.BACKWARD When called from Constraint, it uses the one at UrnaryConstraint.? How does it know which one to use?? Thanks, Jen From hjp-python at hjp.at Sun Mar 26 14:48:25 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 26 Mar 2023 20:48:25 +0200 Subject: How does a method of a subclass become a method of the base class? In-Reply-To: References: Message-ID: <20230326184825.vjb5zwhi3elrfxsw@hjp.at> On 2023-03-26 19:43:44 +0200, Jen Kris via Python-list wrote: > The base class: > > > class Constraint(object): [...] > def satisfy(self, mark): > ??????? global planner > ??????? self.choose_method(mark) > > The subclass: > > class UrnaryConstraint(Constraint): [...] > ??? def choose_method(self, mark): > ??????? if self.my_output.mark != mark and \ > ?????????? Strength.stronger(self.strength, self.my_output.walk_strength): > self.satisfied = True > ??????? else: > ??????????? self.satisfied = False > > The base class Constraint doesn?t have a "choose_method" class method, > but it?s called as self.choose_method(mark) on the final line of > Constraint shown above.? > > My question is:? what makes "choose_method" a method of the base > class, Nothing. choose_method isn't a method of the base class. > called as self.choose_method instead of > UrnaryConstraint.choose_method?? Is it super(UrnaryConstraint, > self).__init__(strength) or just the fact that Constraint is its base > class?? This works only if satisfy() is called on a subclass of Constraint which actually implements this method. If you do something like x = UrnaryConstraint() x.satisfy(whatever) Then x is a member of class UrnaryConstraint and will have a choose_method() method which can be called. > Also, this program also has a class BinaryConstraint that is also a > subclass of Constraint and it also has a choose_method class method > that is similar but not identical: ... > When called from Constraint, it uses the one at UrnaryConstraint.? How > does it know which one to use?? By inspecting self. If you call x.satisfy() on an object of class UrnaryConstraint, then self.choose_method will be the choose_method from UrnaryConstraint. If you call it on an object of class BinaryConstraint, then self.choose_method will be the choose_method from BinaryConstraint. hp PS: Pretty sure there's one "r" too many in UrnaryConstraint. -- _ | 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 Richard at Damon-Family.org Sun Mar 26 15:19:47 2023 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 26 Mar 2023 15:19:47 -0400 Subject: How does a method of a subclass become a method of the base class? In-Reply-To: References: Message-ID: On 3/26/23 1:43 PM, Jen Kris via Python-list wrote: > The base class: > > > class Constraint(object): > > def __init__(self, strength): > ??????? super(Constraint, self).__init__() > ??????? self.strength = strength > > def satisfy(self, mark): > ??????? global planner > ??????? self.choose_method(mark) > > The subclass: > > class UrnaryConstraint(Constraint): > > def __init__(self, v, strength): > ??????? super(UrnaryConstraint, self).__init__(strength) > ??????? self.my_output = v > ??????? self.satisfied = False > ??????? self.add_constraint() > > ??? def choose_method(self, mark): > ??????? if self.my_output.mark != mark and \ > ?????????? Strength.stronger(self.strength, self.my_output.walk_strength): > self.satisfied = True > ??????? else: > ??????????? self.satisfied = False > > The base class Constraint doesn?t have a "choose_method" class method, but it?s called as self.choose_method(mark) on the final line of Constraint shown above. > > My question is:? what makes "choose_method" a method of the base class, called as self.choose_method instead of UrnaryConstraint.choose_method?? Is it super(UrnaryConstraint, self).__init__(strength) or just the fact that Constraint is its base class? > > Also, this program also has a class BinaryConstraint that is also a subclass of Constraint and it also has a choose_method class method that is similar but not identical: > > def choose_method(self, mark): > ??? if self.v1.mark == mark: > ??????????? if self.v2.mark != mark and Strength.stronger(self.strength, self.v2.walk_strength): > ??????????????? self.direction = Direction.FORWARD > ??????????? else: > ??????????????? self.direction = Direction.BACKWARD > > When called from Constraint, it uses the one at UrnaryConstraint.? How does it know which one to use? > > Thanks, > > Jen Perhaps the key point to remember is that when looking up the methods on an object, those methods are part of the object as a whole, not particually "attached" to a given class. When creating the subclass typed object, first the most base class part is built, and all the methods of that class are put into the object, then the next level, and so on, and if a duplicate method is found, it just overwrites the connection. Then when the object is used, we see if there is a method by that name to use, so methods in the base can find methods in subclasses to use. Perhaps a more modern approach would be to use the concept of an "abstract base" which allows the base to indicate that a derived class needs to define certain abstract methods, (If you need that sort of support, not defining a method might just mean the subclass doesn't support some optional behavior defined by the base) -- Richard Damon From jenkris at tutanota.com Sun Mar 26 15:24:01 2023 From: jenkris at tutanota.com (Jen Kris) Date: Sun, 26 Mar 2023 21:24:01 +0200 (CEST) Subject: How does a method of a subclass become a method of the base class? In-Reply-To: References: Message-ID: Thanks to Richard Damon and Peter Holzer for your replies.? I'm working through the call chain to understand better so I can post a followup question if needed.? Thanks again. Jen Mar 26, 2023, 19:21 by Richard at Damon-Family.org: > On 3/26/23 1:43 PM, Jen Kris via Python-list wrote: > >> The base class: >> >> >> class Constraint(object): >> >> def __init__(self, strength): >> ??????? super(Constraint, self).__init__() >> ??????? self.strength = strength >> >> def satisfy(self, mark): >> ??????? global planner >> ??????? self.choose_method(mark) >> >> The subclass: >> >> class UrnaryConstraint(Constraint): >> >> def __init__(self, v, strength): >> ??????? super(UrnaryConstraint, self).__init__(strength) >> ??????? self.my_output = v >> ??????? self.satisfied = False >> ??????? self.add_constraint() >> >> ??? def choose_method(self, mark): >> ??????? if self.my_output.mark != mark and \ >> ?????????? Strength.stronger(self.strength, self.my_output.walk_strength): >> self.satisfied = True >> ??????? else: >> ??????????? self.satisfied = False >> >> The base class Constraint doesn?t have a "choose_method" class method, but it?s called as self.choose_method(mark) on the final line of Constraint shown above. >> >> My question is:? what makes "choose_method" a method of the base class, called as self.choose_method instead of UrnaryConstraint.choose_method?? Is it super(UrnaryConstraint, self).__init__(strength) or just the fact that Constraint is its base class? >> >> Also, this program also has a class BinaryConstraint that is also a subclass of Constraint and it also has a choose_method class method that is similar but not identical: >> >> def choose_method(self, mark): >> ??? if self.v1.mark == mark: >> ??????????? if self.v2.mark != mark and Strength.stronger(self.strength, self.v2.walk_strength): >> ??????????????? self.direction = Direction.FORWARD >> ??????????? else: >> ??????????????? self.direction = Direction.BACKWARD >> >> When called from Constraint, it uses the one at UrnaryConstraint.? How does it know which one to use? >> >> Thanks, >> >> Jen >> > > Perhaps the key point to remember is that when looking up the methods on an object, those methods are part of the object as a whole, not particually "attached" to a given class. When creating the subclass typed object, first the most base class part is built, and all the methods of that class are put into the object, then the next level, and so on, and if a duplicate method is found, it just overwrites the connection. Then when the object is used, we see if there is a method by that name to use, so methods in the base can find methods in subclasses to use. > > Perhaps a more modern approach would be to use the concept of an "abstract base" which allows the base to indicate that a derived class needs to define certain abstract methods, (If you need that sort of support, not defining a method might just mean the subclass doesn't support some optional behavior defined by the base) > > -- > Richard Damon > > -- > https://mail.python.org/mailman/listinfo/python-list > From jenkris at tutanota.com Sun Mar 26 16:36:18 2023 From: jenkris at tutanota.com (Jen Kris) Date: Sun, 26 Mar 2023 22:36:18 +0200 (CEST) Subject: How does a method of a subclass become a method of the base class? In-Reply-To: <20230326184825.vjb5zwhi3elrfxsw@hjp.at> References: <20230326184825.vjb5zwhi3elrfxsw@hjp.at> Message-ID: Based on your explanations, I went through the call chain and now I understand better how it works, but I have a follow-up question at the end.??? This code comes from the DeltaBlue benchmark in the Python benchmark suite.? 1 The call chain starts in a non-class program with the following call: EqualityConstraint(prev, v, Strength.REQUIRED) 2 EqualityConstraint is a subclass of BinaryConstraint, so first it calls the __init__ method of BinaryConstraint: ???? def __init__(self, v1, v2, strength): ??????? super(BinaryConstraint, self).__init__(strength) ??????? self.v1 = v1 ??????? self.v2 = v2 ??????? self.direction = Direction.NONE ??????? self.add_constraint() 3 At the final line shown above it calls add_constraint in the Constraint class, the base class of BinaryConstraint: ????? def add_constraint(self): ??????? global planner ??????? self.add_to_graph() ??????? planner.incremental_add(self) 4 At planner.incremental_add it calls incremental_add in the Planner class because planner is a global instance of the Planner class:? ??? def incremental_add(self, constraint): ??????? mark = self.new_mark() ??????? overridden = constraint.satisfy(mark) At the final line it calls "satisfy" in the Constraint class, and that line calls choose_method in the BinaryConstraint class.? Just as Peter Holzer said, it requires a call to "satisfy."? My only remaining question is, did it select the choose_method in the BinaryConstraint class instead of the choose_method in the UrnaryConstraint class because of "super(BinaryConstraint, self).__init__(strength)" in step 2 above?? Thanks for helping me clarify that.? Jen Mar 26, 2023, 18:55 by hjp-python at hjp.at: > On 2023-03-26 19:43:44 +0200, Jen Kris via Python-list wrote: > >> The base class: >> >> >> class Constraint(object): >> > [...] > >> def satisfy(self, mark): >> ??????? global planner >> ??????? self.choose_method(mark) >> >> The subclass: >> >> class UrnaryConstraint(Constraint): >> > [...] > >> ??? def choose_method(self, mark): >> ??????? if self.my_output.mark != mark and \ >> ?????????? Strength.stronger(self.strength, self.my_output.walk_strength): >> self.satisfied = True >> ??????? else: >> ??????????? self.satisfied = False >> >> The base class Constraint doesn?t have a "choose_method" class method, >> but it?s called as self.choose_method(mark) on the final line of >> Constraint shown above.? >> >> My question is:? what makes "choose_method" a method of the base >> class, >> > > Nothing. choose_method isn't a method of the base class. > >> called as self.choose_method instead of >> UrnaryConstraint.choose_method?? Is it super(UrnaryConstraint, >> self).__init__(strength) or just the fact that Constraint is its base >> class?? >> > > This works only if satisfy() is called on a subclass of Constraint which > actually implements this method. > > If you do something like > > x = UrnaryConstraint() > x.satisfy(whatever) > > Then x is a member of class UrnaryConstraint and will have a > choose_method() method which can be called. > > >> Also, this program also has a class BinaryConstraint that is also a >> subclass of Constraint and it also has a choose_method class method >> that is similar but not identical: >> > ... > >> When called from Constraint, it uses the one at UrnaryConstraint.? How >> does it know which one to use?? >> > > By inspecting self. If you call x.satisfy() on an object of class > UrnaryConstraint, then self.choose_method will be the choose_method from > UrnaryConstraint. If you call it on an object of class BinaryConstraint, > then self.choose_method will be the choose_method from BinaryConstraint. > > hp > > PS: Pretty sure there's one "r" too many in UrnaryConstraint. > > -- > _ | Peter J. Holzer | Story must make more sense than reality. > |_|_) | | > | | | hjp at hjp.at | -- Charles Stross, "Creative writing > __/ | http://www.hjp.at/ | challenge!" > From cs at cskk.id.au Sun Mar 26 18:44:00 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 27 Mar 2023 09:44:00 +1100 Subject: How does a method of a subclass become a method of the base class? In-Reply-To: References: Message-ID: On 26Mar2023 22:36, Jen Kris wrote: >At the final line it calls "satisfy" in the Constraint class, and that >line calls choose_method in the BinaryConstraint class.? Just as Peter >Holzer said, it requires a call to "satisfy."? > >My only remaining question is, did it select the choose_method in the >BinaryConstraint class instead of the choose_method in the >UrnaryConstraint class because of "super(BinaryConstraint, >self).__init__(strength)" in step 2 above?? Basicly, no. You've omitting the "class" lines of the class definitions, and they define the class inheritance, _not "__init__". The "__init__" method just initialises the state of the new objects (which has already been created). The: super(BinaryConstraint,_ self).__init__(strength) line simply calls the appropriate superclass "__init__" with the "strength" parameter to do that aspect of the initialisation. You haven't cited the line which calls the "choose_method" method, but I'm imagining it calls "choose_method" like this: self.choose_method(...) That searchs for the "choose_method" method based on the method resolution order of the object "self". So if "self" was an instance of "EqualityConstraint", and I'm guessing abut its class definition, assuming this: class EqualityConstraint(BinaryConstraint): Then a call to "self.choose_method" would look for a "choose_method" method first in the EqualityConstraint class and then via the BinaryConstraint class. I'm also assuming UrnaryConstraint is not in that class ancestry i.e. not an ancestor of BinaryConstraint, for example. The first method found is used. In practice, when you define a class like: class EqualityConstraint(BinaryConstraint): the complete class ancestry (the addition classes from which BinaryConstraint inherits) gets flatterned into a "method resultion order" list of classes to inspect in order, and that is stored as the ".__mro__" field on the new class (EqualityConstraint). You can look at it directly as "EqualityConstraint.__mro__". So looking up: self.choose_method() looks for a "choose_method" method on the classes in "type(self).__mro__". Cheers, Cameron Simpson From jenkris at tutanota.com Sun Mar 26 19:53:49 2023 From: jenkris at tutanota.com (Jen Kris) Date: Mon, 27 Mar 2023 01:53:49 +0200 (CEST) Subject: How does a method of a subclass become a method of the base class? In-Reply-To: References: <20230326184825.vjb5zwhi3elrfxsw@hjp.at> Message-ID: Cameron, Thanks for your reply.? You are correct about the class definition lines ? e.g. class EqualityConstraint(BinaryConstraint).? I didn?t post all of the code because this program is over 600 lines long.? It's DeltaBlue in the Python benchmark suite.? I?ve done some more work since this morning, and now I see what?s happening.? But it gave rise to another question, which I?ll ask at the end.? The call chain starts at ??? EqualityConstraint(prev, v, Strength.REQUIRED)? The class EqualityConstraint is a subclass of BinaryConstraint.? The entire class code is: ??? class EqualityConstraint(BinaryConstraint): ??????? def execute(self): ??????????? self.output().value = self.input().value Because EqualityConstraint is a subclass of BinaryConstraint, the init method of BinaryConstraint is called first.? During that initialization (I showed the call chain in my previous message), it calls choose_method.? When I inspect the code at "self.choose_method(mark):" in PyCharm, it shows: ??? > As EqualityConstraint is a subclass of BinaryConstraint it has bound the choose method from BinaryConstraint, apparently during the BinaryConstraint init process, and that?s the one it uses.? So that answers my original question.? But that brings up a new question.? I can create a class instance with x = BinaryConstraint(), but what happens when I have a line like "EqualityConstraint(prev, v, Strength.REQUIRED)"? Is it because the only method of EqualityConstraint is execute(self)?? Is execute a special function like a class __init__?? I?ve done research on that but I haven?t found an answer.? I?m asking all these question because I have worked in a procedural style for many years, with class work limited to only simple classes, but now I?m studying classes in more depth. The three answers I have received today, including yours, have helped a lot.? Thanks very much.? Jen Mar 26, 2023, 22:45 by cs at cskk.id.au: > On 26Mar2023 22:36, Jen Kris wrote: > >> At the final line it calls "satisfy" in the Constraint class, and that line calls choose_method in the BinaryConstraint class.? Just as Peter Holzer said, it requires a call to "satisfy."? >> >> My only remaining question is, did it select the choose_method in the BinaryConstraint class instead of the choose_method in the UrnaryConstraint class because of "super(BinaryConstraint, self).__init__(strength)" in step 2 above?? >> > > Basicly, no. > > You've omitting the "class" lines of the class definitions, and they define the class inheritance, _not "__init__". The "__init__" method just initialises the state of the new objects (which has already been created). The: > > super(BinaryConstraint,_ self).__init__(strength) > > line simply calls the appropriate superclass "__init__" with the "strength" parameter to do that aspect of the initialisation. > > You haven't cited the line which calls the "choose_method" method, but I'm imagining it calls "choose_method" like this: > > self.choose_method(...) > > That searchs for the "choose_method" method based on the method resolution order of the object "self". So if "self" was an instance of "EqualityConstraint", and I'm guessing abut its class definition, assuming this: > > class EqualityConstraint(BinaryConstraint): > > Then a call to "self.choose_method" would look for a "choose_method" method first in the EqualityConstraint class and then via the BinaryConstraint class. I'm also assuming UrnaryConstraint is not in that class ancestry i.e. not an ancestor of BinaryConstraint, for example. > > The first method found is used. > > In practice, when you define a class like: > > class EqualityConstraint(BinaryConstraint): > > the complete class ancestry (the addition classes from which BinaryConstraint inherits) gets flatterned into a "method resultion order" list of classes to inspect in order, and that is stored as the ".__mro__" field on the new class (EqualityConstraint). You can look at it directly as "EqualityConstraint.__mro__". > > So looking up: > > self.choose_method() > > looks for a "choose_method" method on the classes in "type(self).__mro__". > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > From cs at cskk.id.au Sun Mar 26 21:03:29 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 27 Mar 2023 12:03:29 +1100 Subject: How does a method of a subclass become a method of the base class? In-Reply-To: References: Message-ID: On 27Mar2023 01:53, Jen Kris wrote: >Thanks for your reply.? You are correct about the class definition >lines ? e.g. class EqualityConstraint(BinaryConstraint).? I didn?t post >all of the code because this program is over 600 lines long.? It's >DeltaBlue in the Python benchmark suite.? Doubtless. But the "class ...:" line is the critical thing. >I?ve done some more work since this morning, and now I see what?s happening.? But it gave rise to another question, which I?ll ask at the end.? > >The call chain starts at > >??? EqualityConstraint(prev, v, Strength.REQUIRED)? > >The class EqualityConstraint is a subclass of BinaryConstraint.? The entire class code is: > >??? class EqualityConstraint(BinaryConstraint): >??????? def execute(self): >??????????? self.output().value = self.input().value Ok, so it is effectively a BinaryConstraint with a single customised execute() method. >Because EqualityConstraint is a subclass of BinaryConstraint, the init method of BinaryConstraint is called first. That is courtesy of the MRO: EqualityConstraint has no __init__, so the one found in BinaryConstraint is found and used. >During that initialization (I showed the call chain in my previous >message), it calls choose_method.? When I inspect the code at >"self.choose_method(mark):" in PyCharm, it shows: > >??? > This says that it found found the choose_method method in the BinaryConstraint class definition, but that it is _bound_ to the EqualityConstraint instance you're using (self). >As EqualityConstraint is a subclass of BinaryConstraint it has bound the choose method from BinaryConstraint, apparently during the BinaryConstraint init process, and that?s the one it uses.? So that answers my original question.? Incorrectly, I think. __init__ does _nothing_ about other methods, if you mean "__init__" in the sentence above. The class definition results in an EqualityConstraint.__mro__ list of classes, which is where _every_ method is looked for _at call time_. >But that brings up a new question.? I can create a class instance with >x = BinaryConstraint(), That makes an instance of EqualityConstraint. >but what happens when I have a line like "EqualityConstraint(prev, v, >Strength.REQUIRED)"? That makes an instance of EqualityConstraint. >Is it because the only method of EqualityConstraint is execute(self)? I don't know what you're asking here. >Is execute a special function like a class __init__? No. It's just a method. In a sense, __init__ isn't very special either. It is just _called_ during new instance setup as the final step. By that time, self is a fully set up instance of... whatever and the __init__ function is just being called to do whatever initial attribute setup every instance of that class needs. Python doesn't magicly call _all_ the __init__ methods of all the superclasses; it calls the first found. So for an EqualityConstraint it finds the one from BinaryConstraint because EqualityConstraint does not provide an overriding one of its own. If EqualityConstraint _did_ provide one, it might typically be structured as: class EqualityConstraint(BinaryConstraint): def __init__(self, prev, v, strength, something_extra): super().__init__(prev, v, strength) self.extra = something_extra So: - Python only calls _one_ __init__ method - in the example above, it finds one in EqualityConstraint and uses it - because Python calls _only_ that, in order to _also_ do the normal setup a BinaryConstraint needs, we pass the parameters used by BinaryConstraint to the new __init__ up the chain by calling super().__init__(BinaryConstraint-parameters-here) - we do our own special something with the something_extra That super().__init__() call is the _only_ thing which arranges that superclass inits get to run. This givens you full control to sompletely replace some superclass' init with a custom one. By calling super().__init__() we're saying we not replacing that stuff, we're running the old stuff and just doing something additional for our subclass. Cheers, Cameron Simpson From cs at cskk.id.au Sun Mar 26 22:10:38 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 27 Mar 2023 13:10:38 +1100 Subject: How does a method of a subclass become a method of the base class? In-Reply-To: References: Message-ID: On 27Mar2023 12:03, Cameron Simpson wrote: >On 27Mar2023 01:53, Jen Kris wrote: >>But that brings up a new question.? I can create a class instance with >>x = BinaryConstraint(), > >That makes an instance of EqualityConstraint. Copy/paste mistake on my part. This makes an instance of BinaryConstraint. Apologies, Cameron Simpson From hjp-python at hjp.at Mon Mar 27 08:52:15 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 27 Mar 2023 14:52:15 +0200 Subject: How does a method of a subclass become a method of the base class? In-Reply-To: References: <20230326184825.vjb5zwhi3elrfxsw@hjp.at> Message-ID: <20230327125215.dz2xx2qcrdpygyei@hjp.at> On 2023-03-27 01:53:49 +0200, Jen Kris via Python-list wrote: > But that brings up a new question.? I can create a class instance with > x = BinaryConstraint(), but what happens when I have a line like > "EqualityConstraint(prev, v, Strength.REQUIRED)"? If that is the whole statement it will create a new object of class EqualityConstraint and immediately discard it. That may have some useful side effect (for example the object may add itself to a list of constraints) but this is not apparent from this line. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From mats at wichmann.us Mon Mar 27 10:08:44 2023 From: mats at wichmann.us (Mats Wichmann) Date: Mon, 27 Mar 2023 08:08:44 -0600 Subject: How does a method of a subclass become a method of the base class? In-Reply-To: References: <20230326184825.vjb5zwhi3elrfxsw@hjp.at> Message-ID: On 3/26/23 17:53, Jen Kris via Python-list wrote: > I?m asking all these question because I have worked in a procedural style for many years, with class work limited to only simple classes, but now I?m studying classes in more depth. The three answers I have received today, including yours, have helped a lot. Classes in Python don't work quite like they do in many other languages. You may find a lightbulb if you listen to Raymond Hettinger talk about them: https://dailytechvideo.com/raymond-hettinger-pythons-class-development-toolkit/ I'd also advise that benchmarks often do very strange things to set up the scenario they're trying to test, a benchmark sure wouldn't be my first place to look in learning a new piece of Python - I don't know if it was the first place, but thought this was worth a mention. From jenkris at tutanota.com Mon Mar 27 10:47:26 2023 From: jenkris at tutanota.com (Jen Kris) Date: Mon, 27 Mar 2023 16:47:26 +0200 (CEST) Subject: How does a method of a subclass become a method of the base class? In-Reply-To: References: <20230326184825.vjb5zwhi3elrfxsw@hjp.at> Message-ID: Thanks to everyone who answered this question.? Your answers have helped a lot.? Jen Mar 27, 2023, 14:12 by mats at wichmann.us: > On 3/26/23 17:53, Jen Kris via Python-list wrote: > >> I?m asking all these question because I have worked in a procedural style for many years, with class work limited to only simple classes, but now I?m studying classes in more depth. The three answers I have received today, including yours, have helped a lot. >> > > Classes in Python don't work quite like they do in many other languages. > > You may find a lightbulb if you listen to Raymond Hettinger talk about them: > > https://dailytechvideo.com/raymond-hettinger-pythons-class-development-toolkit/ > > I'd also advise that benchmarks often do very strange things to set up the scenario they're trying to test, a benchmark sure wouldn't be my first place to look in learning a new piece of Python - I don't know if it was the first place, but thought this was worth a mention. > > > -- > https://mail.python.org/mailman/listinfo/python-list > From aapost at idontexist.club Sun Mar 26 14:42:14 2023 From: aapost at idontexist.club (aapost) Date: Sun, 26 Mar 2023 14:42:14 -0400 Subject: How does a method of a subclass become a method of the base class? In-Reply-To: References: Message-ID: On 3/26/23 13:43, Jen Kris wrote: > > My question is:? what makes "choose_method" a method of the base class, called as self.choose_method instead of UrnaryConstraint.choose_method?? Is it super(UrnaryConstraint, self).__init__(strength) or just the fact that Constraint is its base class? When referring to "self" you are referring to an "instance" of the class or classes, think in terms of objects (the instance, usually self) vs a blueprint (the class, usually cls). saying self.choose_method(mark) checks the "instance" of self to see if it has something called choose_method at run time (instances being created at run time). If you have an instance of just Constraint, and never had a choose_method defined for it, you will get an error because it can't find it (which in this case is presumed as designed). If the "instance" is of a subclass of Constraint that does have a choose_method, that also inherits the stuff from Constraint, it will successfully call it against the "instance" that has been constructed with attributes of both classes. if the instance of a subclass has a definition for something that is in the base class, for instance IF UrnaryConstraint had it's own def satisfy() method, the instance would call the subclass version. In the case given, it does not, so it looks to the parent to see if it has inherited satisfy() from higher up. Hopefully that helps a little bit.. just have to get a feel for OO instantiated object vs class.. From loris.bennett at fu-berlin.de Mon Mar 27 09:00:52 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Mon, 27 Mar 2023 15:00:52 +0200 Subject: Standard class for time *period*? Message-ID: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> Hi, I have been around long enough to know that, due to time-zones, daylight saving and whatnot, time-related stuff is complicated. So even if I think something connected with time should exist, there may well be a very good reason why it does not. My problem: I need to deal with what I call a 'period', which is a span of time limited by two dates, start and end. The period has a 'duration', which is the elapsed time between start and end. The duration is essentially a number of seconds, but in my context, because the durations are usually hours or days, I would generally want to display the duration in a format such as "dd-hh:mm:ss" My (possibly ill-founded) expectation: There is a standard class which encapsulates this sort of functionality. My (possibly insufficiently researched) conclusion: Such a standard class does not exist. What is at fault here? My expectation or my conclusion? Cheers, Loris -- This signature is currently under constuction. From manta103g at gmail.com Mon Mar 27 10:07:44 2023 From: manta103g at gmail.com (a a) Date: Mon, 27 Mar 2023 07:07:44 -0700 (PDT) Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> Message-ID: On Thursday, 23 March 2023 at 22:15:10 UTC+1, Thomas Passin wrote: > On 3/23/2023 3:38 PM, Mats Wichmann wrote: > > On 3/23/23 09:48, Thomas Passin wrote: > > > >> I didn't realize that Christoph Gohlke is still maintaining this site. > > > > Unless the the last-changed stuff stopped working, it's in a static state: > > > > by Christoph Gohlke.?Updated on 26 June 2022 at 07:27 UTC > I did see that. The OP needs a version that would work with Windows 7 > and an older version of Python (3.7 or 3.8, IIRC), so things may work out. Thank you Thomas for your excellent work you did for me. Ok, I know, I need to switch to Windows 10 run on another PC next to me. I need to learn how to copy and move every web page opened in Firefox as a reference to social media, web sites for Python, chat and more (about 50 web pages live opened ;) I really love the limited functionality of w3schools to let me live open and run Python examples, especiallly Matplotlib examples. Unfortunately chat forum at w3schools is low traffic, showing no interest to add more examples. https://www.w3schools.com/python/trypython.asp?filename=demo_matplotlib_subplots3 https://www.w3schools.com/python/matplotlib_subplot.asp thank you Thomas, darius From loris.bennett at fu-berlin.de Mon Mar 27 10:20:06 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Mon, 27 Mar 2023 16:20:06 +0200 Subject: Standard class for time *period*? References: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <87fs9qjmy1.fsf@hornfels.zedat.fu-berlin.de> ram at zedat.fu-berlin.de (Stefan Ram) writes: > ram at zedat.fu-berlin.de (Stefan Ram) writes: >>d = datetime_diff.days >>h, rem = divmod( datetime_diff.seconds, 3600 ) >>m, s = divmod( rem, 60 ) >>print( f'{d:02}-{h:02}:{m:02}:{s:02}' ) > > If the default formatting is acceptable to you, you can also > print the datetime_diff in a shorter way: > > main.py > > from datetime import datetime > > format = '%Y-%m-%dT%H:%M:%S%z' > datetime_0 = datetime.strptime( '2023-03-27T14:00:52+01:00', format ) > datetime_1 = datetime.strptime( '2023-03-27T14:27:23+01:00', format ) > > print( datetime_1 - datetime_0 ) > > sys.stdout > > 0:26:31 > > . Days will also be shown if greater than zero. Thanks for the examples, but I am not really interested in how to write a bunch of code to do what I need, as I can already do that. I am interested in whether there is a standard class for this and, if there is not such a class, why this is the case. Cheers, Loris -- This signature is currently under constuction. From bowman at montana.com Mon Mar 27 11:34:14 2023 From: bowman at montana.com (rbowman) Date: 27 Mar 2023 15:34:14 GMT Subject: Standard class for time *period*? References: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> Message-ID: On Mon, 27 Mar 2023 15:00:52 +0200, Loris Bennett wrote: > I need to deal with what I call a 'period', which is a span of time > limited by two dates, start and end. The period has a 'duration', > which is the elapsed time between start and end. The duration is > essentially a number of seconds, but in my context, because the > durations are usually hours or days, I would generally want to display > the duration in a format such as "dd-hh:mm:ss" https://www.programiz.com/python-programming/datetime Scroll down to timedelta. If '14 days, 13:55:39' isn't good enough you'll have to format it yourself. From gherron at digipen.edu Mon Mar 27 12:43:02 2023 From: gherron at digipen.edu (Gary Herron) Date: Mon, 27 Mar 2023 09:43:02 -0700 Subject: Standard class for time *period*? In-Reply-To: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> References: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <022846e9-3a89-b217-4884-93c39e23048a@digipen.edu> The Python standard library module datetime seems to be what you want.? It has objects representing date/times, and deltatimes (i.e., durations).? These can be timezone aware or not as you wish. Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology On 3/27/23 6:00 AM, loris.bennett at fu-berlin.de wrote: > Hi, > > I have been around long enough to know that, due to time-zones, daylight > saving and whatnot, time-related stuff is complicated. So even if I > think something connected with time should exist, there may well be a > very good reason why it does not. > > My problem: > > I need to deal with what I call a 'period', which is a span of time > limited by two dates, start and end. The period has a 'duration', > which is the elapsed time between start and end. The duration is > essentially a number of seconds, but in my context, because the > durations are usually hours or days, I would generally want to display > the duration in a format such as "dd-hh:mm:ss" > > My (possibly ill-founded) expectation: > > There is a standard class which encapsulates this sort of functionality. > > My (possibly insufficiently researched) conclusion: > > Such a standard class does not exist. > > What is at fault here? My expectation or my conclusion? > > Cheers, > > Loris > From list1 at tompassin.net Mon Mar 27 13:19:01 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 27 Mar 2023 13:19:01 -0400 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> Message-ID: <93802e9e-7443-7814-27f0-6c483ba3a854@tompassin.net> On 3/27/2023 10:07 AM, a a wrote: > Ok, I know, I need to switch to Windows 10 run on another PC next to me. > > I need to learn how to copy and move every web page opened in Firefox as a reference to social media, web sites for Python, chat and more (about 50 web pages live opened ? This sounds like you mean when you get a new Windows 10 PC, you will want to move your open tabs to the new machine. I see several possibilities for this. 1. Copy your Firefox profile folder to the new computer, and tell Firefox to use it as the default profile. I *think* this will include the open tabs, but I haven't tried it. Saving that folder is useful for backup anyway. (If you use Thunderbird for email, you really *must* back up its profile folder because all your email with its folder structure is there. BTW, you can even copy the profile over to a Linux machine that has Thunderbird, and presto, all your email will be there. The Firefox profile would probably transfer just as well). 2. Bookmark all your open tabs under a new heading "open tabs", then export the bookmarks. In the new machine, import them into Firefox there. They won't open in tabs, but it will be easy to find them and open them when you want to. You probably will want to copy over your bookmarks anyway, so this adds little effort. 3. There may be a specific record of open tabs that you can copy or export. I don't know about this but an internet search should help. Good luck. From list1 at tompassin.net Mon Mar 27 13:25:22 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 27 Mar 2023 13:25:22 -0400 Subject: Standard class for time *period*? In-Reply-To: References: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <0354c275-33d2-f3c2-1700-56166ef5153c@tompassin.net> On 3/27/2023 11:34 AM, rbowman wrote: > On Mon, 27 Mar 2023 15:00:52 +0200, Loris Bennett wrote: > > >> I need to deal with what I call a 'period', which is a span of time >> limited by two dates, start and end. The period has a 'duration', >> which is the elapsed time between start and end. The duration is >> essentially a number of seconds, but in my context, because the >> durations are usually hours or days, I would generally want to display >> the duration in a format such as "dd-hh:mm:ss" > > https://www.programiz.com/python-programming/datetime > > Scroll down to timedelta. If '14 days, 13:55:39' isn't good enough you'll > have to format it yourself. I second this. timedelta should give the OP exactly what he's talking about. From manta103g at gmail.com Mon Mar 27 15:07:54 2023 From: manta103g at gmail.com (a a) Date: Mon, 27 Mar 2023 12:07:54 -0700 (PDT) Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> <93802e9e-7443-7814-27f0-6c483ba3a854@tompassin.net> Message-ID: On Monday, 27 March 2023 at 19:19:41 UTC+2, Thomas Passin wrote: > On 3/27/2023 10:07 AM, a a wrote: > > Ok, I know, I need to switch to Windows 10 run on another PC next to me. > > > > I need to learn how to copy and move every web page opened in Firefox as a reference to social media, web sites for Python, chat and more (about 50 web pages live opened ? > > This sounds like you mean when you get a new Windows 10 PC, you will > want to move your open tabs to the new machine. I see several > possibilities for this. > > 1. Copy your Firefox profile folder to the new computer, and tell > Firefox to use it as the default profile. I *think* this will include > the open tabs, but I haven't tried it. Saving that folder is useful for > backup anyway. (If you use Thunderbird for email, you really *must* > back up its profile folder because all your email with its folder > structure is there. BTW, you can even copy the profile over to a Linux > machine that has Thunderbird, and presto, all your email will be there. > The Firefox profile would probably transfer just as well). > > 2. Bookmark all your open tabs under a new heading "open tabs", then > export the bookmarks. In the new machine, import them into Firefox > there. They won't open in tabs, but it will be easy to find them and > open them when you want to. You probably will want to copy over your > bookmarks anyway, so this adds little effort. > > 3. There may be a specific record of open tabs that you can copy or > export. I don't know about this but an internet search should help. > > Good luck. a nice solution comes from How to Copy URLs of All Open Tabs in Firefox https://www.howtogeek.com/723921/how-to-copy-urls-of-all-open-tabs-in-firefox/ right clicking opened tab, all opened tabs can be selected moving via menu to bookmarks/ booksmarks management url bookmarks can be right-mouse clicked to copy urls finally, urls can be pasted into Notepad++ and saved as a file unfortunately, saving as .html file fails to generate html file with clickable web links Notepad++ keeps urls active, selectable but not ready to be opened in Firefox so I need to learn how to make Notepad++ or another editor to save urls as html file BTW Selecting all opened tabs I get 1,000+ active urls (opened web pages ), so something must be wrong From list1 at tompassin.net Mon Mar 27 16:02:16 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 27 Mar 2023 16:02:16 -0400 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> <93802e9e-7443-7814-27f0-6c483ba3a854@tompassin.net> Message-ID: On 3/27/2023 3:07 PM, a a wrote: > On Monday, 27 March 2023 at 19:19:41 UTC+2, Thomas Passin wrote: >> On 3/27/2023 10:07 AM, a a wrote: >>> Ok, I know, I need to switch to Windows 10 run on another PC next to me. >>> >>> I need to learn how to copy and move every web page opened in Firefox as a reference to social media, web sites for Python, chat and more (about 50 web pages live opened ? >> >> This sounds like you mean when you get a new Windows 10 PC, you will >> want to move your open tabs to the new machine. I see several >> possibilities for this. >> >> 1. Copy your Firefox profile folder to the new computer, and tell >> Firefox to use it as the default profile. I *think* this will include >> the open tabs, but I haven't tried it. Saving that folder is useful for >> backup anyway. (If you use Thunderbird for email, you really *must* >> back up its profile folder because all your email with its folder >> structure is there. BTW, you can even copy the profile over to a Linux >> machine that has Thunderbird, and presto, all your email will be there. >> The Firefox profile would probably transfer just as well). >> >> 2. Bookmark all your open tabs under a new heading "open tabs", then >> export the bookmarks. In the new machine, import them into Firefox >> there. They won't open in tabs, but it will be easy to find them and >> open them when you want to. You probably will want to copy over your >> bookmarks anyway, so this adds little effort. >> >> 3. There may be a specific record of open tabs that you can copy or >> export. I don't know about this but an internet search should help. >> >> Good luck. > > a nice solution comes from > > How to Copy URLs of All Open Tabs in Firefox > > https://www.howtogeek.com/723921/how-to-copy-urls-of-all-open-tabs-in-firefox/ > > right clicking opened tab, all opened tabs can be selected > moving via menu to bookmarks/ booksmarks management > url bookmarks can be right-mouse clicked to copy urls > finally, urls can be pasted into Notepad++ > and saved as a file > unfortunately, saving as .html file > fails to generate html file with clickable web links > Don't go pasting urls into a text file one by one. Instead, do my #2 above. That will import all the bookmarks, including the tabs you saved as bookmarks. Then import the exported bookmark file into the new browser. There's no reason to fuss around trying to get text copies of urls to open. For that matter, the exported bookmarks file is an HTML file and can be opened directly in a browser, with clickable links. From list1 at tompassin.net Mon Mar 27 20:07:06 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 27 Mar 2023 20:07:06 -0400 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> <93802e9e-7443-7814-27f0-6c483ba3a854@tompassin.net> Message-ID: <87be9be4-4292-ef73-83c1-4272c8866f0b@tompassin.net> On 3/27/2023 4:02 PM, Thomas Passin wrote: > On 3/27/2023 3:07 PM, a a wrote: >> On Monday, 27 March 2023 at 19:19:41 UTC+2, Thomas Passin wrote: >>> On 3/27/2023 10:07 AM, a a wrote: >>>> Ok, I know, I need to switch to Windows 10 run on another PC next to >>>> me. >>>> >>>> I need to learn how to copy and move every web page opened in >>>> Firefox as a reference to social media, web sites for Python, chat >>>> and more (about 50 web pages live opened ? >>> >>> This sounds like you mean when you get a new Windows 10 PC, you will >>> want to move your open tabs to the new machine. I see several >>> possibilities for this. >>> >>> 1. Copy your Firefox profile folder to the new computer, and tell >>> Firefox to use it as the default profile. I *think* this will include >>> the open tabs, but I haven't tried it. Saving that folder is useful for >>> backup anyway. (If you use Thunderbird for email, you really *must* >>> back up its profile folder because all your email with its folder >>> structure is there. BTW, you can even copy the profile over to a Linux >>> machine that has Thunderbird, and presto, all your email will be there. >>> The Firefox profile would probably transfer just as well). >>> >>> 2. Bookmark all your open tabs under a new heading "open tabs", then >>> export the bookmarks. In the new machine, import them into Firefox >>> there. They won't open in tabs, but it will be easy to find them and >>> open them when you want to. You probably will want to copy over your >>> bookmarks anyway, so this adds little effort. >>> >>> 3. There may be a specific record of open tabs that you can copy or >>> export. I don't know about this but an internet search should help. >>> >>> Good luck. >> >> a nice solution comes from >> >> How to Copy URLs of All Open Tabs in Firefox >> >> https://www.howtogeek.com/723921/how-to-copy-urls-of-all-open-tabs-in-firefox/ >> >> right clicking opened tab, all opened tabs can be selected >> moving via menu to bookmarks/ booksmarks management >> url bookmarks can be right-mouse clicked to copy urls >> finally, urls can be pasted into Notepad++ >> and saved as a file >> unfortunately, saving as .html file >> fails to generate html file with clickable web links >> > > Don't go pasting urls into a text file one by one.? Instead, do my #2 > above. That will import all the bookmarks, including the tabs you saved > as bookmarks.? Then import the exported bookmark file into the new > browser.? There's no reason to fuss around trying to get text copies of > urls to open. > > For that matter, the exported bookmarks file is an HTML file and can be > opened directly in a browser, with clickable links. All right, I think I've got the easiest way to go. You *can* bookmark all the tabs at once - see below. Then, as I already proposed, export the bookmarks and import them into Firefox on the new computer. To save the tabs, right click any one of them and select the "Select All Tabs" item. They will all highlight. Right click on one of them and select the "Bookmark Tabs" item. A dialog box will open with an entry lone for the Name to use (like "Tabset1") and a location - a bookmark folder - for them to go into. CAREFUL - if you just click "Save", you may not be able to find them. Use the dropdown arrow to save them in one of the top level folders, like "Bookmarks Toolbars". From travisgriggs at gmail.com Mon Mar 27 21:25:01 2023 From: travisgriggs at gmail.com (Travis Griggs) Date: Mon, 27 Mar 2023 18:25:01 -0700 Subject: What kind of "thread safe" are deque's actually? Message-ID: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> A while ago I chose to use a deque that is shared between two threads. I did so because the docs say: "Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.? (https://docs.python.org/3.11/library/collections.html?highlight=deque#collections.deque) Earlier today, looking through some server logs I noticed that from time to I?m getting a RuntimeError: deque mutated during iteration I guess this surprised me. When I see ?thread safe?, I don?t expect to get errors. Interestingly the error also only started showing up when I switched from running a statistics.mean() on one of these, instead of what I had been using, a statistics.median(). Apparently the kind of iteration done in a mean, is more conflict prone than a median? I?ve got a couple ways I can work around this. But I was surprised. From rosuav at gmail.com Mon Mar 27 21:35:34 2023 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Mar 2023 12:35:34 +1100 Subject: What kind of "thread safe" are deque's actually? In-Reply-To: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> References: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> Message-ID: On Tue, 28 Mar 2023 at 12:26, Travis Griggs wrote: > > A while ago I chose to use a deque that is shared between two threads. I did so because the docs say: > > "Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.? > > (https://docs.python.org/3.11/library/collections.html?highlight=deque#collections.deque) > > Earlier today, looking through some server logs I noticed that from time to I?m getting a > > RuntimeError: deque mutated during iteration > > I guess this surprised me. When I see ?thread safe?, I don?t expect to get errors. > I'd like to see your code, but here's an example with no threads whatsoever that has the same error: >>> from collections import deque >>> q = deque([1, 2, 3, 4]) >>> for item in q: ... if item % 2: q.append(item * 2) ... print(item) ... 1 Traceback (most recent call last): File "", line 1, in RuntimeError: deque mutated during iteration This error comes from having an active iterator, then mutating the deque, then continuing to iterate. That MAY be a result of threading, but it isn't necessarily. For threaded usage, I would recommend restricting yourself to append/appendleft/pop/popleft (the standard mutators), with any operations on the entire queue being done on a copy instead (either q.copy() or list(q) depending on what you need). The act of taking a copy should itself be thread-safe, and obviously anything done on a separate copy will be independent of changes to the original. ChrisA From grant.b.edwards at gmail.com Mon Mar 27 21:54:30 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 27 Mar 2023 18:54:30 -0700 (PDT) Subject: What kind of "thread safe" are deque's actually? References: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> Message-ID: <642248d6.050a0220.5bfa6.c773@mx.google.com> On 2023-03-28, Travis Griggs wrote: > A while ago I chose to use a deque that is shared between two threads. I did so because the docs say: > > "Deques support thread-safe, memory efficient appends and pops from > either side of the deque with approximately the same O(1) > performance in either direction.? > > (https://docs.python.org/3.11/library/collections.html?highlight=deque#collections.deque) > > Earlier today, looking through some server logs I noticed that from > time to I?m getting a > > RuntimeError: deque mutated during iteration > > I guess this surprised me. When I see ?thread safe?, I don?t expect > to get errors. Well, I guess it doesn't say that iteration of a deque is thread safe. It only claims that appends and pops from either end are thread safe. It doesn't even claim that inserts, removes, clear, copy, or any other operations are thread-safe. -- Grant From 2QdxY4RzWzUUiLuE at potatochowder.com Mon Mar 27 21:41:13 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Mon, 27 Mar 2023 21:41:13 -0400 Subject: What kind of "thread safe" are deque's actually? In-Reply-To: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> References: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> Message-ID: On 2023-03-27 at 18:25:01 -0700, Travis Griggs wrote: > "Deques support thread-safe, memory efficient appends and pops from > either side of the deque with approximately the same O(1) performance > in either direction.? > (https://docs.python.org/3.11/library/collections.html?highlight=deque#collections.deque) [...] > I guess this surprised me. When I see ?thread safe?, I don?t expect to > get errors. Even without threads, mutating a collection while iterating over it usually results in bad things happening. $ python Python 3.10.10 (main, Mar 5 2023, 22:26:53) [GCC 12.2.1 20230201] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import collections >>> x = collections.deque() >>> x.append(44) >>> x.append(55) >>> x.append(66) >>> x.append(77) >>> x deque([44, 55, 66, 77]) >>> for y in x: x.pop() 77 Traceback (most recent call last): File "", line 1, in RuntimeError: deque mutated during iteration Concurrency just increases the likeliness of mutating while iterating. From manta103g at gmail.com Mon Mar 27 20:37:15 2023 From: manta103g at gmail.com (a a) Date: Mon, 27 Mar 2023 17:37:15 -0700 (PDT) Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> <93802e9e-7443-7814-27f0-6c483ba3a854@tompassin.net> <87be9be4-4292-ef73-83c1-4272c8866f0b@tompassin.net> Message-ID: <16ab8232-1ba8-4cbd-b70d-22186a006676n@googlegroups.com> On Tuesday, 28 March 2023 at 02:07:43 UTC+2, Thomas Passin wrote: > On 3/27/2023 4:02 PM, Thomas Passin wrote: > > On 3/27/2023 3:07 PM, a a wrote: > >> On Monday, 27 March 2023 at 19:19:41 UTC+2, Thomas Passin wrote: > >>> On 3/27/2023 10:07 AM, a a wrote: > >>>> Ok, I know, I need to switch to Windows 10 run on another PC next to > >>>> me. > >>>> > >>>> I need to learn how to copy and move every web page opened in > >>>> Firefox as a reference to social media, web sites for Python, chat > >>>> and more (about 50 web pages live opened ? > >>> > >>> This sounds like you mean when you get a new Windows 10 PC, you will > >>> want to move your open tabs to the new machine. I see several > >>> possibilities for this. > >>> > >>> 1. Copy your Firefox profile folder to the new computer, and tell > >>> Firefox to use it as the default profile. I *think* this will include > >>> the open tabs, but I haven't tried it. Saving that folder is useful for > >>> backup anyway. (If you use Thunderbird for email, you really *must* > >>> back up its profile folder because all your email with its folder > >>> structure is there. BTW, you can even copy the profile over to a Linux > >>> machine that has Thunderbird, and presto, all your email will be there. > >>> The Firefox profile would probably transfer just as well). > >>> > >>> 2. Bookmark all your open tabs under a new heading "open tabs", then > >>> export the bookmarks. In the new machine, import them into Firefox > >>> there. They won't open in tabs, but it will be easy to find them and > >>> open them when you want to. You probably will want to copy over your > >>> bookmarks anyway, so this adds little effort. > >>> > >>> 3. There may be a specific record of open tabs that you can copy or > >>> export. I don't know about this but an internet search should help. > >>> > >>> Good luck. > >> > >> a nice solution comes from > >> > >> How to Copy URLs of All Open Tabs in Firefox > >> > >> https://www.howtogeek.com/723921/how-to-copy-urls-of-all-open-tabs-in-firefox/ > >> > >> right clicking opened tab, all opened tabs can be selected > >> moving via menu to bookmarks/ booksmarks management > >> url bookmarks can be right-mouse clicked to copy urls > >> finally, urls can be pasted into Notepad++ > >> and saved as a file > >> unfortunately, saving as .html file > >> fails to generate html file with clickable web links > >> > > > > Don't go pasting urls into a text file one by one. Instead, do my #2 > > above. That will import all the bookmarks, including the tabs you saved > > as bookmarks. Then import the exported bookmark file into the new > > browser. There's no reason to fuss around trying to get text copies of > > urls to open. > > > > For that matter, the exported bookmarks file is an HTML file and can be > > opened directly in a browser, with clickable links. > All right, I think I've got the easiest way to go. You *can* bookmark > all the tabs at once - see below. Then, as I already proposed, export > the bookmarks and import them into Firefox on the new computer. > > To save the tabs, right click any one of them and select the "Select All > Tabs" item. They will all highlight. Right click on one of them and > select the "Bookmark Tabs" item. A dialog box will open with an entry > lone for the Name to use (like "Tabset1") and a location - a bookmark > folder - for them to go into. CAREFUL - if you just click "Save", you > may not be able to find them. Use the dropdown arrow to save them in > one of the top level folders, like "Bookmarks Toolbars". I can select All Opened Tabs (as from the given link) and get 1,000+ Opened Tabs ( I am afraid, this is s number of all saved bookmarks in the past) I go to menu, Bookmarks, Manage Boomarks and copy Tabs and https://www.textfixer.com/html/convert-url-to-html-link.php does the job, converting text urls into clickable web links I copy the result and past into Notepad++ to save file as html and what I get is web page of clickable Opened Tabs since icon and page name are lost I would prefer another solution already ofered by Firex to generate web page of recently visited web pages, unfortunately coming with limits on the number of visited web pages, so I contacted Firefox, Notepad++ for help From list1 at tompassin.net Tue Mar 28 00:27:55 2023 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 28 Mar 2023 00:27:55 -0400 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: <16ab8232-1ba8-4cbd-b70d-22186a006676n@googlegroups.com> References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> <93802e9e-7443-7814-27f0-6c483ba3a854@tompassin.net> <87be9be4-4292-ef73-83c1-4272c8866f0b@tompassin.net> <16ab8232-1ba8-4cbd-b70d-22186a006676n@googlegroups.com> Message-ID: <90b97e3b-b83f-6c72-b271-7cbd04ad3dfc@tompassin.net> On 3/27/2023 8:37 PM, a a wrote: >> To save the tabs, right click any one of them and select the "Select All >> Tabs" item. They will all highlight. Right click on one of them and >> select the "Bookmark Tabs" item. A dialog box will open with an entry >> lone for the Name to use (like "Tabset1") and a location - a bookmark >> folder - for them to go into. CAREFUL - if you just click "Save", you >> may not be able to find them. Use the dropdown arrow to save them in >> one of the top level folders, like "Bookmarks Toolbars". > I can select All Opened Tabs (as from the given link) > and get 1,000+ Opened Tabs ( I am afraid, this is s number of all saved bookmarks in the past) > I go to menu, Bookmarks, Manage Boomarks and copy Tabs > > and > https://www.textfixer.com/html/convert-url-to-html-link.php > > does the job, converting text urls into clickable web links > > I copy the result and past into Notepad++ to save file as html > > and what I get is web page of clickable Opened Tabs > > since icon and page name are lost I don't understand this. You don't really have 1000 tabs open at the same time, do you? If you select all the open tabs - I think you wrote that you only have 50 - then you can save them as bookmarks under a folder name you choose. That folder will contain the 50 open links. I tried it this evening, so I know that's how it works. (It happens that I'm working on my own bookmark manager just now, so I've been messing around with importing, exporting, and reading the bookmark files). Then you can export them and import the same bookmark file into another browser on another computer. Whenever you want to reopen some of those tabs, you would navigate to that part of the bookmarks and open the tabs you want. Maybe you have something else in mind? Do you want to send the links of the opened tab set to someone else, but not all your bookmarks? Please explain more carefully what you want to do. From list1 at tompassin.net Tue Mar 28 00:41:40 2023 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 28 Mar 2023 00:41:40 -0400 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: <16ab8232-1ba8-4cbd-b70d-22186a006676n@googlegroups.com> References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> <93802e9e-7443-7814-27f0-6c483ba3a854@tompassin.net> <87be9be4-4292-ef73-83c1-4272c8866f0b@tompassin.net> <16ab8232-1ba8-4cbd-b70d-22186a006676n@googlegroups.com> Message-ID: <5994464c-d679-11da-1265-444c1965e45d@tompassin.net> On 3/27/2023 8:37 PM, a a wrote: > I can select All Opened Tabs (as from the given link) > and get 1,000+ Opened Tabs ( I am afraid, this is s number of all saved bookmarks in the past) > I go to menu, Bookmarks, Manage Boomarks and copy Tabs > > and > https://www.textfixer.com/html/convert-url-to-html-link.php > > does the job, converting text urls into clickable web links > > I copy the result and past into Notepad++ to save file as html > > and what I get is web page of clickable Opened Tabs You can get that directly in Notepad++. Load Firefox's HTML format bookmark file into Notepad++. View it in a browser using the "View/View Current File In" menu item. True, you could have opened it directly in the browser, but now you can edit the file and cut out the parts you don't need, and check to make sure you get what you intended. The structure of the HTML is very regular. If you have saved your set of opened links under a distinctive heading near the top of the collection - as I suggested earlier - it should be easy to find the start and end points of their HTML elements, and delete all the ones you don't want. You could import this shortened bookmark file into another installation of Firefox and this would add them to the bookmarks in the other browser, all grouped by your custom heading. From yogeshtirthkar-vendor at gic.com.sg Tue Mar 28 00:56:24 2023 From: yogeshtirthkar-vendor at gic.com.sg (Yogesh Tirthkar) Date: Tue, 28 Mar 2023 04:56:24 +0000 Subject: [Request for Assistance] To uninstall python installed in other user profile (Win 10) Message-ID: Hi Team, Could you please advise on the scenario in windows 10 machine : Where we need to uninstall/remove python from user profile A (installed by user A in its own profile folder) - via an admin user or system account. Currently when we try to uninstall it via admin/system account - it displays that the python product is not installed for this user (admin/system). Appreciate your assistance. Regards, Yogesh. _________________________________________________________________________________ Technology Group | GIC Private Limited | 168 Robinson Road, #37-01, Capital Tower, Singapore 068912 This email from GIC may contain confidential information. Unauthorised communication and disclosure of any information in this email is prohibited. If you are not the intended recipient, please notify the sender and delete this email immediately. From loris.bennett at fu-berlin.de Tue Mar 28 02:14:55 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Tue, 28 Mar 2023 08:14:55 +0200 Subject: Standard class for time *period*? References: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> <0354c275-33d2-f3c2-1700-56166ef5153c@tompassin.net> Message-ID: <87y1nhflls.fsf@debian-BULLSEYE-live-builder-AMD64> Thomas Passin writes: > On 3/27/2023 11:34 AM, rbowman wrote: >> On Mon, 27 Mar 2023 15:00:52 +0200, Loris Bennett wrote: >> >>> I need to deal with what I call a 'period', which is a span of time >>> limited by two dates, start and end. The period has a 'duration', >>> which is the elapsed time between start and end. The duration is >>> essentially a number of seconds, but in my context, because the >>> durations are usually hours or days, I would generally want to display >>> the duration in a format such as "dd-hh:mm:ss" >> https://www.programiz.com/python-programming/datetime >> Scroll down to timedelta. If '14 days, 13:55:39' isn't good enough >> you'll >> have to format it yourself. > > I second this. timedelta should give the OP exactly what he's talking > about. No, it doesn't. I already know about timedelta. I must have explained the issue badly, because everyone seems to be fixating on the formatting, which is not a problem and is incidental to what I am really interested in, namely: 1. Is there a standard class for a 'period', i.e. length of time specified by a start point and an end point? The start and end points could obviously be datetimes and the difference a timedelta, but the period '2022-03-01 00:00 to 2022-03-02 00:00' would be different to '2023-03-01 00:00 to 2023-03-02 00:00' even if the *duration* of both periods is the same. 2. If such a standard class doesn't exist, why does it not exist? Cheers, Loris -- This signature is currently under constuction. From wlfraed at ix.netcom.com Tue Mar 28 08:05:40 2023 From: wlfraed at ix.netcom.com (Dennis Lee Bieber) Date: Tue, 28 Mar 2023 08:05:40 -0400 Subject: Standard class for time *period*? References: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> <0354c275-33d2-f3c2-1700-56166ef5153c@tompassin.net> <87y1nhflls.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: On Tue, 28 Mar 2023 08:14:55 +0200, "Loris Bennett" declaimed the following: > >No, it doesn't. I already know about timedelta. I must have explained >the issue badly, because everyone seems to be fixating on the >formatting, which is not a problem and is incidental to what I am really >interested in, namely: > >1. Is there a standard class for a 'period', i.e. length of time > specified by a start point and an end point? The start and end > points could obviously be datetimes and the difference a timedelta, > but the period '2022-03-01 00:00 to 2022-03-02 00:00' would be > different to '2023-03-01 00:00 to 2023-03-02 00:00' even if the > *duration* of both periods is the same. > >2. If such a standard class doesn't exist, why does it not exist? > So far, you seem to be the only person who has ever asked for a single entity incorporating an EPOCH (datetime.datetime) + a DURATION (datetime.timedelta). You are asking for two durations of the same length to be considered different if they were computed from different "zero" references (epochs). I don't think I've ever encountered an application that doesn't use a single epoch (possibly per run) with all internal computations using a timedelta FROM THAT EPOCH! (The exception may have been computing star atlases during the conversion from B1900 to J2000 reference frames.) From loris.bennett at fu-berlin.de Tue Mar 28 09:11:14 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Tue, 28 Mar 2023 15:11:14 +0200 Subject: Standard class for time *period*? References: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> <0354c275-33d2-f3c2-1700-56166ef5153c@tompassin.net> <87y1nhflls.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: <87a5zxf2bx.fsf@debian-BULLSEYE-live-builder-AMD64> Dennis Lee Bieber writes: > On Tue, 28 Mar 2023 08:14:55 +0200, "Loris Bennett" > declaimed the following: > >> >>No, it doesn't. I already know about timedelta. I must have explained >>the issue badly, because everyone seems to be fixating on the >>formatting, which is not a problem and is incidental to what I am really >>interested in, namely: >> >>1. Is there a standard class for a 'period', i.e. length of time >> specified by a start point and an end point? The start and end >> points could obviously be datetimes and the difference a timedelta, >> but the period '2022-03-01 00:00 to 2022-03-02 00:00' would be >> different to '2023-03-01 00:00 to 2023-03-02 00:00' even if the >> *duration* of both periods is the same. >> >>2. If such a standard class doesn't exist, why does it not exist? >> > > So far, you seem to be the only person who has ever asked for a single > entity incorporating an EPOCH (datetime.datetime) + a DURATION > (datetime.timedelta). You are asking for two durations of the same length > to be considered different if they were computed from different "zero" > references (epochs). I thought I was asking for two periods of the same duration to be considered different, if they have different starting points :-) > I don't think I've ever encountered an application > that doesn't use a single epoch (possibly per run) with all internal > computations using a timedelta FROM THAT EPOCH! (The exception may have > been computing star atlases during the conversion from B1900 to J2000 > reference frames.) But even if I have a single epoch, January 2022 is obviously different to January 2023, even thought the duration might be the same. I am just surprised that there is no standard Period class, with which I could create objects and then be able to sort, check for identity, equality of length, amount of overlap, etc. I suppose people just use a datetime.datetime pair, as I have been doing so far, and tack on just the specific bit of functionality they need. -- This signature is currently under constuction. From bowman at montana.com Tue Mar 28 10:17:08 2023 From: bowman at montana.com (rbowman) Date: 28 Mar 2023 14:17:08 GMT Subject: Standard class for time *period*? References: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> <0354c275-33d2-f3c2-1700-56166ef5153c@tompassin.net> <87y1nhflls.fsf@debian-BULLSEYE-live-builder-AMD64> <87a5zxf2bx.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: On Tue, 28 Mar 2023 15:11:14 +0200, Loris Bennett wrote: > But even if I have a single epoch, January 2022 is obviously different > to January 2023, even thought the duration might be the same. I am just > surprised that there is no standard Period class, with which I could > create objects and then be able to sort, check for identity, equality of > length, amount of overlap, etc. I suppose people just use a > datetime.datetime pair, as I have been doing so far, and tack on just > the specific bit of functionality they need. It's called Unix time... Convert the seconds into whatever you want. From pranavbhardwaj773 at gmail.com Tue Mar 28 11:14:44 2023 From: pranavbhardwaj773 at gmail.com (pranavbhardwaj773 at gmail.com) Date: Tue, 28 Mar 2023 20:44:44 +0530 Subject: found older version of python in my command prompt Message-ID: <06827EC2-EB03-49A6-AA23-E802529EFC91@hxcore.ol> ? ? Sent from [1]Mail for Windows Dear sir, ????????????? I am Pranav Bhardwaj and I am facing issue regarding python version. When I try to open python in my command prompt, I see there is very older version in it that is python 2.7.13 as a default version. I want to switch my default version to the latest version in my command prompt. Plese help me how can I do this. ? References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From manta103g at gmail.com Tue Mar 28 08:19:20 2023 From: manta103g at gmail.com (a a) Date: Tue, 28 Mar 2023 05:19:20 -0700 (PDT) Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> <93802e9e-7443-7814-27f0-6c483ba3a854@tompassin.net> <87be9be4-4292-ef73-83c1-4272c8866f0b@tompassin.net> <90b97e3b-b83f-6c72-b271-7cbd04ad3dfc@tompassin.net> <16ab8232-1ba8-4cbd-b70d-22186a006676n@googlegroups.com> Message-ID: <3112f38c-5ad2-4196-9b86-e0487c8547c5n@googlegroups.com> On Tuesday, 28 March 2023 at 06:33:44 UTC+2, Thomas Passin wrote: > On 3/27/2023 8:37 PM, a a wrote: > >> To save the tabs, right click any one of them and select the "Select All > >> Tabs" item. They will all highlight. Right click on one of them and > >> select the "Bookmark Tabs" item. A dialog box will open with an entry > >> lone for the Name to use (like "Tabset1") and a location - a bookmark > >> folder - for them to go into. CAREFUL - if you just click "Save", you > >> may not be able to find them. Use the dropdown arrow to save them in > >> one of the top level folders, like "Bookmarks Toolbars". > > I can select All Opened Tabs (as from the given link) > > and get 1,000+ Opened Tabs ( I am afraid, this is s number of all saved bookmarks in the past) > > I go to menu, Bookmarks, Manage Boomarks and copy Tabs > > > > and > > https://www.textfixer.com/html/convert-url-to-html-link.php > > > > does the job, converting text urls into clickable web links > > > > I copy the result and past into Notepad++ to save file as html > > > > and what I get is web page of clickable Opened Tabs > > > > since icon and page name are lost > I don't understand this. You don't really have 1000 tabs open at the > same time, do you? If you select all the open tabs - I think you wrote > that you only have 50 - then you can save them as bookmarks under a > folder name you choose. That folder will contain the 50 open links. I > tried it this evening, so I know that's how it works. (It happens that > I'm working on my own bookmark manager just now, so I've been messing > around with importing, exporting, and reading the bookmark files). > > Then you can export them and import the same bookmark file into another > browser on another computer. Whenever you want to reopen some of those > tabs, you would navigate to that part of the bookmarks and open the tabs > you want. > > Maybe you have something else in mind? Do you want to send the links of > the opened tab set to someone else, but not all your bookmarks? Please > explain more carefully what you want to do. Ok, I was not aware of the real number of the opened Tabs in Firefox, since I can jump from left to right and vice versa in real time, so the number given by me: 50 opened Tabs was my general estimate, but I can read the real number of opened Tabs from the same menu (line below) to be 1,000+ What I copy and paste into Notepad++ is 1,000+ -line file. It's hard to verify if the above number is made of opened Tabs only or bookmarks are included, since I exactly use and keep multi Tabs opened as my live bookmarks and cache memory, when I work on my projects (watching, counting sunspots, Earthquakes prediction in Turkey, ... ) I would like to fund the development of such smart Tabs Manager to replace boomarks, to let me group Tabs belonging to different projects. It doesn't look to be complicated, if supported by the Firefox team. Firefox 97. comes with alike functionality (when I open a new Tab) but limited to 4 rows of web-page icons + names and 4 rows called: Recent activity All I need is to replace opened Tabs by history of the Recent activity - default Firefox page, when I open a new Tab It's hard to imagine, I can have 1,000+ Tabs live opened in Firefox but I really need such feature, called in the past as: MyLifeBits by MS So I have to ask Firefox team today to lift 4 rows limit on web links and 4 rows limit on the recent activity, coming with New Tab opened When I am busy on a project I can open 100+ web pages via search engine in one day and would prefer 100+ opened Tabs to be saved in html format for the records as a reference. Hope to get some support from Firefox team via Twitter. Ok, smart bookmarks manager can offer the above functionality right now, so I go to search engine to get one. darius From manta103g at gmail.com Tue Mar 28 08:47:35 2023 From: manta103g at gmail.com (a a) Date: Tue, 28 Mar 2023 05:47:35 -0700 (PDT) Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <398cc44e-3865-43d1-9fa2-b1765012716en@googlegroups.com> <668280b7-a2c3-467f-9af6-932fa7374c98n@googlegroups.com> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> <93802e9e-7443-7814-27f0-6c483ba3a854@tompassin.net> <87be9be4-4292-ef73-83c1-4272c8866f0b@tompassin.net> <90b97e3b-b83f-6c72-b271-7cbd04ad3dfc@tompassin.net> <16ab8232-1ba8-4cbd-b70d-22186a006676n@googlegroups.com> Message-ID: On Tuesday, 28 March 2023 at 06:33:44 UTC+2, Thomas Passin wrote: > On 3/27/2023 8:37 PM, a a wrote: > >> To save the tabs, right click any one of them and select the "Select All > >> Tabs" item. They will all highlight. Right click on one of them and > >> select the "Bookmark Tabs" item. A dialog box will open with an entry > >> lone for the Name to use (like "Tabset1") and a location - a bookmark > >> folder - for them to go into. CAREFUL - if you just click "Save", you > >> may not be able to find them. Use the dropdown arrow to save them in > >> one of the top level folders, like "Bookmarks Toolbars". > > I can select All Opened Tabs (as from the given link) > > and get 1,000+ Opened Tabs ( I am afraid, this is s number of all saved bookmarks in the past) > > I go to menu, Bookmarks, Manage Boomarks and copy Tabs > > > > and > > https://www.textfixer.com/html/convert-url-to-html-link.php > > > > does the job, converting text urls into clickable web links > > > > I copy the result and past into Notepad++ to save file as html > > > > and what I get is web page of clickable Opened Tabs > > > > since icon and page name are lost > I don't understand this. You don't really have 1000 tabs open at the > same time, do you? If you select all the open tabs - I think you wrote > that you only have 50 - then you can save them as bookmarks under a > folder name you choose. That folder will contain the 50 open links. I > tried it this evening, so I know that's how it works. (It happens that > I'm working on my own bookmark manager just now, so I've been messing > around with importing, exporting, and reading the bookmark files). > > Then you can export them and import the same bookmark file into another > browser on another computer. Whenever you want to reopen some of those > tabs, you would navigate to that part of the bookmarks and open the tabs > you want. > > Maybe you have something else in mind? Do you want to send the links of > the opened tab set to someone else, but not all your bookmarks? Please > explain more carefully what you want to do. Ok, I can export bookmarks to html file and open it in Firefox to get a long list of clickable urls but icon of the bookmarked web page is missing. When I open Bookmarks as right a side-bar I can view and identify an individual Boomarks by icon, so I would like Firefox Library to export Bookmarks to html file, icons included ;) Since accessing opened Tabs is my default use of history in Firefox and has worked fine for years I paid no special interest to bookmark opened Tabs and assign labels to individual bookmark. So, generally speaking, I am happy with 1,000+ opened Tabs in Firefox , not being sure if this number is for real or refers to every bookmark from the history + opened Tabs But definitely I need a smarter solution and approach to manage 10,000+ opened Tabs in Firefox in a future ;) - I just build personal search engine resembling targets set by MyLifeBits Project by Microsoft in the past. darius From Karsten.Hilbert at gmx.net Tue Mar 28 11:42:23 2023 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Tue, 28 Mar 2023 17:42:23 +0200 Subject: Aw: Re: Standard class for time *period*? In-Reply-To: <87y1nhflls.fsf@debian-BULLSEYE-live-builder-AMD64> References: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> <0354c275-33d2-f3c2-1700-56166ef5153c@tompassin.net> <87y1nhflls.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: > No, it doesn't. I already know about timedelta. I must have explained > the issue badly, because everyone seems to be fixating on the > formatting, which is not a problem and is incidental to what I am really > interested in, namely: > > 1. Is there a standard class for a 'period', i.e. length of time > specified by a start point and an end point? The start and end > points could obviously be datetimes and the difference a timedelta, > but the period '2022-03-01 00:00 to 2022-03-02 00:00' would be > different to '2023-03-01 00:00 to 2023-03-02 00:00' even if the > *duration* of both periods is the same. Not that I know, within the constraints of the standard library. However: class CalendarPeriod: def __init__(self, start, end): self.start = start self.end = end ? For this to be *useful* more needs need to be explained. Until then - YAGNI. Karsten From list1 at tompassin.net Tue Mar 28 12:04:32 2023 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 28 Mar 2023 12:04:32 -0400 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> <93802e9e-7443-7814-27f0-6c483ba3a854@tompassin.net> <87be9be4-4292-ef73-83c1-4272c8866f0b@tompassin.net> <90b97e3b-b83f-6c72-b271-7cbd04ad3dfc@tompassin.net> <16ab8232-1ba8-4cbd-b70d-22186a006676n@googlegroups.com> Message-ID: On 3/28/2023 8:47 AM, a a wrote: > Ok, I can export bookmarks to html file and open it in Firefox to get > a long list of clickable urls but icon of the bookmarked web page is missing. > > When I open Bookmarks as right a side-bar I can view and identify an individual Boomarks by icon, > so I would like Firefox Library to export Bookmarks to html file, icons included ? > > Since accessing opened Tabs is my default use of history in Firefox and has worked fine for years > I paid no special interest to bookmark opened Tabs and assign labels to individual bookmark. > > So, generally speaking, I am happy with 1,000+ opened Tabs in Firefox , not being sure if this number is for real or refers to every bookmark from the history + opened Tabs > > But definitely I need a smarter solution and approach to manage 10,000+ opened Tabs in Firefox in a future ? I think you had better start using another name for this thread, if it continues. The HTML export file will contain the icons, but the HTML elements do not provide for showing them. I can't imagine how you can find anything among nor navigate through 1000 open tabs, let alone 10,000 in the future. I would think the memory usage would be impossibly high. So I hope you are mostly using the history and do not really have that many tabs open at once! From grant.b.edwards at gmail.com Tue Mar 28 12:13:02 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 28 Mar 2023 09:13:02 -0700 (PDT) Subject: Standard class for time *period*? References: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> <0354c275-33d2-f3c2-1700-56166ef5153c@tompassin.net> <87y1nhflls.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: <6423120e.050a0220.5bfa6.d186@mx.google.com> On 2023-03-28, Dennis Lee Bieber wrote: > So far, you seem to be the only person who has ever asked for a > single entity incorporating an EPOCH (datetime.datetime) + a > DURATION (datetime.timedelta). It seems to me that tuple of two timdate objects (start,end) is the more obvious representation, but it's six of one and a horse of the same color. If one really needs it to be a class, then it woulnd't be much more than a dozen or two lines of code... -- Grant From list1 at tompassin.net Tue Mar 28 12:18:43 2023 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 28 Mar 2023 12:18:43 -0400 Subject: [Request for Assistance] To uninstall python installed in other user profile (Win 10) In-Reply-To: References: Message-ID: On 3/28/2023 12:56 AM, Yogesh Tirthkar wrote: > Hi Team, > > Could you please advise on the scenario in windows 10 machine : Where we need to uninstall/remove python from user profile A (installed by user A in its own profile folder) - via an admin user or system account. > > Currently when we try to uninstall it via admin/system account - it displays that the python product is not installed for this user (admin/system). > > Appreciate your assistance. It depends on where the Python installation is located, but I would just delete the entire folder tree at %APPDATA%\Python\Python3xxx. If Python was installed for all users, its main set of files will probably be in "c:\Program Files" and Window's "Add or Remove" page should remove it. If it was installed just for User A, then the "Add or Remove" page will find it if run from User A's account. If for some reason User A will not or cannot cooperate, the admin could change User A's password and then run "Add or Remove". Of course the admin would not be able to change the pw back, but if User A is not cooperating maybe that wouldn't matter. From list1 at tompassin.net Tue Mar 28 12:29:26 2023 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 28 Mar 2023 12:29:26 -0400 Subject: Standard class for time *period*? In-Reply-To: <6423120e.050a0220.5bfa6.d186@mx.google.com> References: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> <0354c275-33d2-f3c2-1700-56166ef5153c@tompassin.net> <87y1nhflls.fsf@debian-BULLSEYE-live-builder-AMD64> <6423120e.050a0220.5bfa6.d186@mx.google.com> Message-ID: <5a5a2d97-baab-9960-bfda-b352136e4f7c@tompassin.net> On 3/28/2023 12:13 PM, Grant Edwards wrote: > On 2023-03-28, Dennis Lee Bieber wrote: > >> So far, you seem to be the only person who has ever asked for a >> single entity incorporating an EPOCH (datetime.datetime) + a >> DURATION (datetime.timedelta). > > It seems to me that tuple of two timdate objects (start,end) is the > more obvious representation, but it's six of one and a horse of the > same color. > > If one really needs it to be a class, then it woulnd't be much more > than a dozen or two lines of code... I think it would be more than that. The OP said "But even if I have a single epoch, January 2022 is obviously different to January 2023, even thought the duration might be the same. I am just surprised that there is no standard Period class, with which I could create objects and then be able to sort, check for identity, equality of length, amount of overlap, etc. I suppose people just use a datetime.datetime pair, as I have been doing so far, and tack on just the specific bit of functionality they need." A class could be devised to have methods to do those things, but it would take some thought to be sure if they all made sense. Take sorting, for example. Are two "Periods" really comparable? Can we have complete ordering here? "Identity" too would have to be carefully defined, and then a __eq__ method could be implemented. And so on. It would take more than 10 or 20 lines, I would think. But the hard work of figuring out exactly what is wanted and what even makes sense to implement needs to be done first. From grant.b.edwards at gmail.com Tue Mar 28 12:49:32 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 28 Mar 2023 09:49:32 -0700 (PDT) Subject: Standard class for time *period*? References: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> <0354c275-33d2-f3c2-1700-56166ef5153c@tompassin.net> <87y1nhflls.fsf@debian-BULLSEYE-live-builder-AMD64> <6423120e.050a0220.5bfa6.d186@mx.google.com> <5a5a2d97-baab-9960-bfda-b352136e4f7c@tompassin.net> Message-ID: <64231a9c.020a0220.22fa8.2d2c@mx.google.com> On 2023-03-28, Thomas Passin wrote: > On 3/28/2023 12:13 PM, Grant Edwards wrote: >> On 2023-03-28, Dennis Lee Bieber wrote: >> >>> So far, you seem to be the only person who has ever asked for a >>> single entity incorporating an EPOCH (datetime.datetime) + a >>> DURATION (datetime.timedelta). >> >> It seems to me that tuple of two timdate objects (start,end) is the >> more obvious representation, but it's six of one and a horse of the >> same color. >> >> If one really needs it to be a class, then it woulnd't be much more >> than a dozen or two lines of code... > > I think it would be more than that. The OP said You're right. I had forgotten about a few of the operations mentioned, so it might take a bit more than a couple dozen line, but not _that_ much more. The hard part would be defining those operations, and as the OP says, it doesn't seem to me like there is an obvious definition for many of them. If there's no obvious common definition for what a class is supposed to do, then there can't really be a standard one... -- Grant From manta103g at gmail.com Tue Mar 28 13:50:50 2023 From: manta103g at gmail.com (a a) Date: Tue, 28 Mar 2023 10:50:50 -0700 (PDT) Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <6f9f9b8d-8683-f0df-c925-ab0afd9f5db8@tompassin.net> <63fcc9f1-4474-d32c-ea1b-a9d36ad6e0bc@tompassin.net> <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> <93802e9e-7443-7814-27f0-6c483ba3a854@tompassin.net> <87be9be4-4292-ef73-83c1-4272c8866f0b@tompassin.net> <90b97e3b-b83f-6c72-b271-7cbd04ad3dfc@tompassin.net> <16ab8232-1ba8-4cbd-b70d-22186a006676n@googlegroups.com> Message-ID: On Tuesday, 28 March 2023 at 18:12:40 UTC+2, Thomas Passin wrote: > On 3/28/2023 8:47 AM, a a wrote: > > Ok, I can export bookmarks to html file and open it in Firefox to get > > a long list of clickable urls but icon of the bookmarked web page is missing. > > > > When I open Bookmarks as right a side-bar I can view and identify an individual Boomarks by icon, > > so I would like Firefox Library to export Bookmarks to html file, icons included ? > > > > Since accessing opened Tabs is my default use of history in Firefox and has worked fine for years > > I paid no special interest to bookmark opened Tabs and assign labels to individual bookmark. > > > > So, generally speaking, I am happy with 1,000+ opened Tabs in Firefox , not being sure if this number is for real or refers to every bookmark from the history + opened Tabs > > > > But definitely I need a smarter solution and approach to manage 10,000+ opened Tabs in Firefox in a future ? > > I think you had better start using another name for this thread, if it > continues. > > The HTML export file will contain the icons, but the HTML elements do > not provide for showing them. > > I can't imagine how you can find anything among nor navigate through > 1000 open tabs, let alone 10,000 in the future. I would think the memory > usage would be impossibly high. So I hope you are mostly using the > history and do not really have that many tabs open at once! I am a plain guy, so if Firefox counted 1,000+ opened Tabs, I can be surprised, but have no idea how to check that number. You are exactly right, icon URI and icon data come with saved opened Tabs, a single example below. So I am going to ask Firefox team to offer export to html, modified to have : icon, name of web page, url address to appear in a single row (feature already supported by Firefox, when you open new Tab and click: enter URL or search string - input field, you get such list List is limited in size for the reasons unknown to me, but feature works fine. -- So would prefer a horizontal list of opened Tabs by htmlized, vertical list of the same opened Tabs, featuring: icon, name of web-site, URL address Thank you for your excellent support darius "NASA's SDO Watches a Sunspot Turn Toward Earth | NASA From PythonList at DancesWithMice.info Tue Mar 28 14:48:41 2023 From: PythonList at DancesWithMice.info (dn) Date: Wed, 29 Mar 2023 07:48:41 +1300 Subject: Standard class for time *period*? In-Reply-To: <87a5zxf2bx.fsf@debian-BULLSEYE-live-builder-AMD64> References: <87sfdqjqm3.fsf@hornfels.zedat.fu-berlin.de> <0354c275-33d2-f3c2-1700-56166ef5153c@tompassin.net> <87y1nhflls.fsf@debian-BULLSEYE-live-builder-AMD64> <87a5zxf2bx.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: >>> 1. Is there a standard class for a 'period', i.e. length of time >>> specified by a start point and an end point? The start and end >>> points could obviously be datetimes and the difference a timedelta, >>> but the period '2022-03-01 00:00 to 2022-03-02 00:00' would be >>> different to '2023-03-01 00:00 to 2023-03-02 00:00' even if the >>> *duration* of both periods is the same. >>> > But even if I have a single epoch, January 2022 is obviously different > to January 2023, even thought the duration might be the same. I am just > surprised that there is no standard Period class, with which I could > create objects and then be able to sort, check for identity, equality of > length, amount of overlap, etc. I suppose people just use a > datetime.datetime pair, as I have been doing so far, and tack on just > the specific bit of functionality they need. The request for a "standard class" has probably been answered. Please give a use-case example to help outline the problem to be solved... eg if the Apple-picking season starts in January and runs for some weeks, and the Pear-picking season starts in February (etc), then calculation will reveal if one team of pickers can do both jobs or if two teams will be needed. If a list of tasks is to be displayed/printed, then it would be useful to list both, but in chronological order - perhaps by start-date. (this idea of possible application fails to illustrate a rationale for some of the functionality listed, above, but you get the idea of how to give us the idea...) In a custom-class, an __eq__( self, other, ) may be defined to consider any single or combination of attributes of the two classes. So, roll-your-own may not be that difficult - although anything involving time-calculations is wont to open a can-of-worms... -- Regards, =dn From barry at barrys-emacs.org Tue Mar 28 16:42:08 2023 From: barry at barrys-emacs.org (Barry) Date: Tue, 28 Mar 2023 21:42:08 +0100 Subject: found older version of python in my command prompt In-Reply-To: <06827EC2-EB03-49A6-AA23-E802529EFC91@hxcore.ol> References: <06827EC2-EB03-49A6-AA23-E802529EFC91@hxcore.ol> Message-ID: > On 28 Mar 2023, at 16:44, pranavbhardwaj773 at gmail.com wrote: > > ? > > > > Sent from [1]Mail for Windows > > Dear sir, > > I am Pranav Bhardwaj and I am facing issue regarding python > version. When I try to open python in my command prompt, I see there is > very older version in it that is python 2.7.13 as a default version. I > want to switch my default version to the latest version in my command > prompt. Plese help me how can I do this. Uninstall python 2.7 in the usual windows way. Download python 3.11 from python.org and run the installer. In a cmd terminal window run py.exe and you should get the python prompt. Barry > > > > References > > Visible links > 1. https://go.microsoft.com/fwlink/?LinkId=550986 > -- > https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Tue Mar 28 15:44:35 2023 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 28 Mar 2023 15:44:35 -0400 Subject: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ? In-Reply-To: References: <02593e8c-1bf3-051f-6f47-482074691b70@tompassin.net> <713671f6-f01d-3a23-434a-9b1979d88ba5@tompassin.net> <3ee715cc-6beb-7f45-362b-733145a866ac@wichmann.us> <93802e9e-7443-7814-27f0-6c483ba3a854@tompassin.net> <87be9be4-4292-ef73-83c1-4272c8866f0b@tompassin.net> <90b97e3b-b83f-6c72-b271-7cbd04ad3dfc@tompassin.net> <16ab8232-1ba8-4cbd-b70d-22186a006676n@googlegroups.com> Message-ID: <5b1ab972-a36e-0c03-8240-c0081fcff2a5@tompassin.net> On 3/28/2023 1:50 PM, a a wrote: > On Tuesday, 28 March 2023 at 18:12:40 UTC+2, Thomas Passin wrote: >> On 3/28/2023 8:47 AM, a a wrote: >>> Ok, I can export bookmarks to html file and open it in Firefox to get >>> a long list of clickable urls but icon of the bookmarked web page is missing. >>> >>> When I open Bookmarks as right a side-bar I can view and identify an individual Boomarks by icon, >>> so I would like Firefox Library to export Bookmarks to html file, icons included ? >>> >>> Since accessing opened Tabs is my default use of history in Firefox and has worked fine for years >>> I paid no special interest to bookmark opened Tabs and assign labels to individual bookmark. >>> >>> So, generally speaking, I am happy with 1,000+ opened Tabs in Firefox , not being sure if this number is for real or refers to every bookmark from the history + opened Tabs >>> >>> But definitely I need a smarter solution and approach to manage 10,000+ opened Tabs in Firefox in a future ? >> >> I think you had better start using another name for this thread, if it >> continues. >> >> The HTML export file will contain the icons, but the HTML elements do >> not provide for showing them. >> >> I can't imagine how you can find anything among nor navigate through >> 1000 open tabs, let alone 10,000 in the future. I would think the memory >> usage would be impossibly high. So I hope you are mostly using the >> history and do not really have that many tabs open at once! > > > I am a plain guy, so if Firefox counted 1,000+ opened Tabs, I can be surprised, but have no idea how to check that number. > > You are exactly right, icon URI and icon data come with saved opened Tabs, > a single example below. > > So I am going to ask Firefox team to offer > export to html, modified to have : > icon, name of web page, url address > to appear in a single row (feature already supported by Firefox, when you open new Tab > and click: enter URL or search string - input field, > you get such list > List is limited in size for the reasons unknown to me, but feature works fine. You should be aware that the HTML format for bookmarks is a standard developed back in the day by Netscape. It goes back to the early 1990s, I think. The FF folks will not be modifying it, since all browsers know how to generate it and consume it, and who knows how many software packages consume it. No one can afford to have a change, even one that's supposed to be harmless, inadvertently break software that's worked for years. They are going to need a lot of persuading. Maybe there's something else they would be willing and able to do. But you can expect that any proposed new feature will probably need to have some strong support. Raymond Chen at Microsoft has written how each new feature proposal starts off with -100 points. Only if the advantages get the score up above zero can the feature have any chance of getting adopted - and then it has to compete with other potential features that have their own scores. > -- > So would prefer a horizontal list of opened Tabs > by htmlized, vertical list of the same opened Tabs, > featuring: > icon, name of web-site, URL address > > Thank you for your excellent support You're welcome. From miked at dewhirst.com.au Tue Mar 28 18:37:29 2023 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Wed, 29 Mar 2023 09:37:29 +1100 Subject: found older version of python in my command prompt In-Reply-To: <06827EC2-EB03-49A6-AA23-E802529EFC91@hxcore.ol> Message-ID: <4PmPq94HJ5znVG3@mail.python.org> The quickest and dirtiest fix is to edit your %path% variable in windows. Remove all python versions you don't want from the path and Windows won't find them.You can then just delete the unwanted python directories.That doesn't remove any old dll files in secret locations but this is a dirty fix.--(Unsigned mail from my phone) -------- Original message --------From: pranavbhardwaj773 at gmail.com Date: 29/3/23 02:43 (GMT+10:00) To: Python-list at python.org Subject: found older version of python in my command prompt ?? ??? ??? Sent from [1]Mail for Windows?? Dear sir,?? ????????????? I am Pranav Bhardwaj and I am facing issue regarding python?? version. When I try to open python in my command prompt, I see there is?? very older version in it that is python 2.7.13 as a default version. I?? want to switch my default version to the latest version in my command?? prompt. Plese help me how can I do this.?? ?References?? Visible links?? 1. https://go.microsoft.com/fwlink/?LinkId=550986-- https://mail.python.org/mailman/listinfo/python-list From giga at uol.com.br Tue Mar 28 18:39:18 2023 From: giga at uol.com.br (giga at uol.com.br) Date: Tue, 28 Mar 2023 19:39:18 -0300 Subject: recent-files Message-ID: <64236c968fa17_28d72addf33bd110745b9@ip-10-81-19-90.ec2.internal.mail> In Python 3.11.2,? the recent-files list keeps always increasing because it is impossible to edit the list; the corresponding .txt file has disappeared. Please help! Giorgio Gambirasio giga at uol.com.br ? ? ? From mats at wichmann.us Tue Mar 28 19:51:25 2023 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 28 Mar 2023 17:51:25 -0600 Subject: recent-files In-Reply-To: <64236c968fa17_28d72addf33bd110745b9@ip-10-81-19-90.ec2.internal.mail> References: <64236c968fa17_28d72addf33bd110745b9@ip-10-81-19-90.ec2.internal.mail> Message-ID: <36bfb517-ab04-07b3-fd0a-d6df1627491c@wichmann.us> On 3/28/23 16:39, giga at uol.com.br wrote: > In Python 3.11.2,? the recent-files list keeps always increasing because > it is impossible to edit the list; the corresponding .txt file has > disappeared. > Please help! Please explain what you're asking about. What recent-files list? Python itself has no such concept. From cs at cskk.id.au Tue Mar 28 20:36:38 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 29 Mar 2023 11:36:38 +1100 Subject: Standard class for time *period*? In-Reply-To: References: Message-ID: On 28Mar2023 08:05, Dennis Lee Bieber wrote: > So far, you seem to be the only person who has ever asked for a > single >entity incorporating an EPOCH (datetime.datetime) + a DURATION >(datetime.timedelta). But not the only person to want one. I've got a timeseries data format where (within a file) time slots are represented as a seconds offset, and the file has an associated epoch starting point. Dual to that is that a timeslot has an offset from the file start, and that is effectively a (file-epoch, duration) notion. I've got plenty of code using that which passes around UNIX timestamp start/stop pairs. Various conversions happen to select the appropriate file (this keeps the files of bounded size while supporting an unbounded time range). Even a UNIX timestamp has an implied epoch, and therefore kind of represents that epoch plus the timestamp as a duration. I'm not sure I understand Loris' other requirements though. It might be hard to write a general thing which was also still useful. Cheers, Cameron Simpson From greg.ewing at canterbury.ac.nz Wed Mar 29 01:54:06 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 29 Mar 2023 18:54:06 +1300 Subject: What kind of "thread safe" are deque's actually? In-Reply-To: References: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> Message-ID: On 28/03/23 2:25 pm, Travis Griggs wrote: > Interestingly the error also only started showing up when I switched from running a statistics.mean() on one of these, instead of what I had been using, a statistics.median(). Apparently the kind of iteration done in a mean, is more conflict prone than a median? It may be a matter of whether the GIL is held or not. I had a look at the source for deque, and it doesn't seem to explicitly do anything about locking, it just relies on the GIL. So maybe statistics.median() is implemented in C and statistics.mean() in Python, or something like that? -- Greg From rosuav at gmail.com Wed Mar 29 02:08:21 2023 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Mar 2023 17:08:21 +1100 Subject: What kind of "thread safe" are deque's actually? In-Reply-To: References: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> Message-ID: On Wed, 29 Mar 2023 at 16:56, Greg Ewing via Python-list wrote: > > On 28/03/23 2:25 pm, Travis Griggs wrote: > > Interestingly the error also only started showing up when I switched from running a statistics.mean() on one of these, instead of what I had been using, a statistics.median(). Apparently the kind of iteration done in a mean, is more conflict prone than a median? > > It may be a matter of whether the GIL is held or not. I had a look > at the source for deque, and it doesn't seem to explicitly do > anything about locking, it just relies on the GIL. > > So maybe statistics.median() is implemented in C and statistics.mean() > in Python, or something like that? > Both functions are implemented in Python, but median() starts out with this notable line: data = sorted(data) which gives back a copy, iterated over rapidly in C. All subsequent work is done on that copy. The same effect could be had with mean() by taking a snapshot using list(q) and, I believe, would have the same effect (the source code for the sorted() function begins by calling PySequence_List). In any case, it makes *conceptual* sense to do your analysis on a copy of the queue, thus ensuring that your stats are stable. The other threads can keep going while you do your calculations, even if that means changing the queue. ChrisA From tdldev at gmail.com Wed Mar 29 10:50:49 2023 From: tdldev at gmail.com (Jack Dangler) Date: Wed, 29 Mar 2023 10:50:49 -0400 Subject: What kind of "thread safe" are deque's actually? In-Reply-To: References: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> Message-ID: <4720a4e8-ab93-bf0d-77b1-4dd1ac381e35@gmail.com> On 3/29/23 02:08, Chris Angelico wrote: > On Wed, 29 Mar 2023 at 16:56, Greg Ewing via Python-list > wrote: >> On 28/03/23 2:25 pm, Travis Griggs wrote: >>> Interestingly the error also only started showing up when I switched from running a statistics.mean() on one of these, instead of what I had been using, a statistics.median(). Apparently the kind of iteration done in a mean, is more conflict prone than a median? >> It may be a matter of whether the GIL is held or not. I had a look >> at the source for deque, and it doesn't seem to explicitly do >> anything about locking, it just relies on the GIL. >> >> So maybe statistics.median() is implemented in C and statistics.mean() >> in Python, or something like that? >> > Both functions are implemented in Python, but median() starts out with > this notable line: > > data = sorted(data) > > which gives back a copy, iterated over rapidly in C. All subsequent > work is done on that copy. > > The same effect could be had with mean() by taking a snapshot using > list(q) and, I believe, would have the same effect (the source code > for the sorted() function begins by calling PySequence_List). > > In any case, it makes *conceptual* sense to do your analysis on a copy > of the queue, thus ensuring that your stats are stable. The other > threads can keep going while you do your calculations, even if that > means changing the queue. > > ChrisA Sorry for any injected confusion here, but that line "data = sorted(data)" appears as though it takes the value of the variable named _data_, sorts it and returns it to the same variable store, so no copy would be created. Am I missing something there? From grant.b.edwards at gmail.com Wed Mar 29 11:06:34 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 29 Mar 2023 08:06:34 -0700 (PDT) Subject: What kind of "thread safe" are deque's actually? References: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> <4720a4e8-ab93-bf0d-77b1-4dd1ac381e35@gmail.com> Message-ID: <642453fa.050a0220.c4026.b44a@mx.google.com> On 2023-03-29, Jack Dangler wrote: > >> data = sorted(data) > > Sorry for any injected confusion here, but that line "data = > sorted(data)" appears as though it takes the value of the variable named > _data_, sorts it and returns it to the same variable store, so no copy > would be created. Am I missing something there? Yes, you're missing the basics of what an assignment does in Python and how objects work. Python doesn't have such a thing as "a variable st store". The assignment operator binds a name to an object. The 'sorted(data)' expression creates a new object containing a sorted copy of 'data'. The assignment then binds the name "data" to that new object. The old, unsorted object then becomes inaccessable (unless there are other names bound to it, or it's being otherwise used). At some point that old, unsorted object will "go away" completely and cease to exist. -- Grant From loris.bennett at fu-berlin.de Wed Mar 29 02:17:47 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Wed, 29 Mar 2023 08:17:47 +0200 Subject: Standard class for time *period*? References: Message-ID: <87edp8krn8.fsf@debian-BULLSEYE-live-builder-AMD64> Cameron Simpson writes: > On 28Mar2023 08:05, Dennis Lee Bieber wrote: >> So far, you seem to be the only person who has ever asked for >> a single >>entity incorporating an EPOCH (datetime.datetime) + a DURATION >>(datetime.timedelta). > > But not the only person to want one. I've got a timeseries data format > where (within a file) time slots are represented as a seconds offset, > and the file has an associated epoch starting point. Dual to that is > that a timeslot has an offset from the file start, and that is > effectively a (file-epoch, duration) notion. > > I've got plenty of code using that which passes around UNIX timestamp > start/stop pairs. Various conversions happen to select the appropriate > file (this keeps the files of bounded size while supporting an > unbounded time range). > > Even a UNIX timestamp has an implied epoch, and therefore kind of > represents that epoch plus the timestamp as a duration. > > I'm not sure I understand Loris' other requirements though. It might > be hard to write a general thing which was also still useful. I am glad to hear that I am not alone :-) However, my use-case is fairly trivial, indeed less complicated than yours. So, in truth I don't really need a Period class. I just thought it might be a sufficiently generic itch that someone else with a more complicated use-case could have already scratched. After all, that the datetime classes exist, even though I only use a tiny part of the total functionality. Cheers, Loris -- This signature is currently under constuction. From list1 at tompassin.net Wed Mar 29 12:48:33 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 29 Mar 2023 12:48:33 -0400 Subject: Standard class for time *period*? In-Reply-To: <87edp8krn8.fsf@debian-BULLSEYE-live-builder-AMD64> References: <87edp8krn8.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: <9634ab73-3b32-7461-2057-22fe65ca4759@tompassin.net> On 3/29/2023 2:17 AM, Loris Bennett wrote: > > I am glad to hear that I am not alone :-) However, my use-case is fairly > trivial, indeed less complicated than yours. So, in truth I don't > really need a Period class. I just thought it might be a sufficiently > generic itch that someone else with a more complicated use-case could > have already scratched. After all, that the datetime classes exist, > even though I only use a tiny part of the total functionality. > > Cheers, > > Loris > Maybe there is - https://github.com/LinkCareServices/period "Period is a basic time period checking library. Period is based on period.py by William S. Annis. (available at https://www.biostat.wisc.edu/~annis/creations/period.py.html) and ported to python3 with a few improvements. Period.py was in part inspired by perl's Time::Period module and the time class mechanism of Cfengine." I have not worked with it, but it may be worth looking at. I found this by going to PyPi.org and asking for "period". From rosuav at gmail.com Wed Mar 29 13:13:12 2023 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Mar 2023 04:13:12 +1100 Subject: What kind of "thread safe" are deque's actually? In-Reply-To: <4720a4e8-ab93-bf0d-77b1-4dd1ac381e35@gmail.com> References: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> <4720a4e8-ab93-bf0d-77b1-4dd1ac381e35@gmail.com> Message-ID: On Thu, 30 Mar 2023 at 01:52, Jack Dangler wrote: > > > On 3/29/23 02:08, Chris Angelico wrote: > > On Wed, 29 Mar 2023 at 16:56, Greg Ewing via Python-list > > wrote: > >> On 28/03/23 2:25 pm, Travis Griggs wrote: > >>> Interestingly the error also only started showing up when I switched from running a statistics.mean() on one of these, instead of what I had been using, a statistics.median(). Apparently the kind of iteration done in a mean, is more conflict prone than a median? > >> It may be a matter of whether the GIL is held or not. I had a look > >> at the source for deque, and it doesn't seem to explicitly do > >> anything about locking, it just relies on the GIL. > >> > >> So maybe statistics.median() is implemented in C and statistics.mean() > >> in Python, or something like that? > >> > > Both functions are implemented in Python, but median() starts out with > > this notable line: > > > > data = sorted(data) > > > > which gives back a copy, iterated over rapidly in C. All subsequent > > work is done on that copy. > > > > The same effect could be had with mean() by taking a snapshot using > > list(q) and, I believe, would have the same effect (the source code > > for the sorted() function begins by calling PySequence_List). > > > > In any case, it makes *conceptual* sense to do your analysis on a copy > > of the queue, thus ensuring that your stats are stable. The other > > threads can keep going while you do your calculations, even if that > > means changing the queue. > > > > ChrisA > Sorry for any injected confusion here, but that line "data = > sorted(data)" appears as though it takes the value of the variable named > _data_, sorts it and returns it to the same variable store, so no copy > would be created. Am I missing something there? The variable name "data" is the parameter to median(), so it's whatever you ask for the median of. (I didn't make that obvious in my previous post - an excess of brevity on my part.) The sorted() function, UNlike list.sort(), returns a sorted copy of what it's given. I delved into the CPython source code for that, and it begins with the PySequence_List call to (effectively) call list(data) to get a copy of it. It ought to be a thread-safe copy due to holding the GIL the entire time. I'm not sure what would happen in a GIL-free world but most likely the lock on the input object would still ensure thread safety. ChrisA From pranavbhardwaj773 at gmail.com Wed Mar 29 12:46:46 2023 From: pranavbhardwaj773 at gmail.com (Pranav Bhardwaj) Date: Wed, 29 Mar 2023 22:16:46 +0530 Subject: Ole version set as default Message-ID: Dear sir, I am Pranav Bhardwaj and I stuck in a problem. My problem is that in my system I have python 3.11.2 but when I type python in my command prompt, my command prompt show that python version 2.7.13 as a default. And I can't be able to find python 2.7.13 in my system in any file and I tried various methods to set python 3.11.2 as a default but can't be able to do so. I tried to change environment variables, try to find and delete python 2.7.13 , try to set python 3.11.2 as default, but I can't be able to do so. So can you help me how can I solve this problem? From wlfraed at ix.netcom.com Wed Mar 29 13:43:00 2023 From: wlfraed at ix.netcom.com (Dennis Lee Bieber) Date: Wed, 29 Mar 2023 13:43:00 -0400 Subject: What kind of "thread safe" are deque's actually? References: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> <4720a4e8-ab93-bf0d-77b1-4dd1ac381e35@gmail.com> Message-ID: On Wed, 29 Mar 2023 10:50:49 -0400, Jack Dangler declaimed the following: >Sorry for any injected confusion here, but that line "data = >sorted(data)" appears as though it takes the value of the variable named >_data_, sorts it and returns it to the same variable store, so no copy >would be created. Am I missing something there? The entire Python object/data model. Data is not "stored in" variables -- rather names are "attached to" data. sorted() creates a new data object, allocating memory for it. THEN the name "data" is attached to this new data object (and disconnected from the previous object). If there are no names left connected to the original object, the garbage collector reaps its memory. From list1 at tompassin.net Wed Mar 29 14:12:30 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 29 Mar 2023 14:12:30 -0400 Subject: Ole version set as default In-Reply-To: References: Message-ID: <842dc5cc-0cd4-bba0-4dd8-41ab840e69d3@tompassin.net> On 3/29/2023 12:46 PM, Pranav Bhardwaj wrote: > Dear sir, > I am Pranav Bhardwaj and I stuck in a problem. My problem is > that in my system I have python 3.11.2 but when I type python in my command > prompt, my command prompt show that python version 2.7.13 as a default. And > I can't be able to find python 2.7.13 in my system in any file and I tried > various methods to set python 3.11.2 as a default but can't be able to do > so. I tried to change environment variables, try to find and delete python > 2.7.13 , try to set python 3.11.2 as default, but I can't be able to do so. > So can you help me how can I solve this problem? If you installed Python3 from python.org, then type "py". This will run the latest version installed on your machine. "py" will give you the option of running the latest version or earlier versions by specifying them on the command line: "py -2" will give you Python 2+, "py -3.9" will run Python 3.9 if it is installed, and so on. This will run Python3.11, but you may still get the wrong version when you try to run a Python-installed script from the command line. For example, if you type "pip" to install packages that can be installed from PyPi by the Pip command, the pip program for Python 2 may run instead. Some of these programs, like pip, are Python modules and can be run using the "-m" option: py -m pip This will run the right version of pip for whatever version of Python it launches. I always run pip this way, and you should too. Many or most of the Python scripts that were installed into the Python Scripts directory can be run this way too. That leaves other cases where a script might get launched from Python2's Scripts directory because it is on your PATH. The way to make Python3's directories get used instead of Python2's is to put them first on the PATH, so that they will get checked first for the target file. It would be too long to go into the details for changing the PATH here. If you still have trouble after doing what I said above, feel free to come back and ask how to do it. You can find out how to change the PATH on the internet, so you probably won't need to come back here. One final possibility for getting the wrong version of Python is if you try to run a file whose name ends with ".py" without typing "py" before it. In other words, on the command line you should type "py program.py", not just "program.py". The installer for Python 3.11 should have taken care of these file associations (as they are called in Windows) so it will probably not be a problem. If it is, just make sure to include the "py" when you run a Python program. From tdldev at gmail.com Wed Mar 29 14:14:48 2023 From: tdldev at gmail.com (Jack Dangler) Date: Wed, 29 Mar 2023 14:14:48 -0400 Subject: What kind of "thread safe" are deque's actually? In-Reply-To: References: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> <4720a4e8-ab93-bf0d-77b1-4dd1ac381e35@gmail.com> Message-ID: On 3/29/23 13:13, Chris Angelico wrote: > On Thu, 30 Mar 2023 at 01:52, Jack Dangler wrote: >> >> On 3/29/23 02:08, Chris Angelico wrote: >>> On Wed, 29 Mar 2023 at 16:56, Greg Ewing via Python-list >>> wrote: >>>> On 28/03/23 2:25 pm, Travis Griggs wrote: >>>>> Interestingly the error also only started showing up when I switched from running a statistics.mean() on one of these, instead of what I had been using, a statistics.median(). Apparently the kind of iteration done in a mean, is more conflict prone than a median? >>>> It may be a matter of whether the GIL is held or not. I had a look >>>> at the source for deque, and it doesn't seem to explicitly do >>>> anything about locking, it just relies on the GIL. >>>> >>>> So maybe statistics.median() is implemented in C and statistics.mean() >>>> in Python, or something like that? >>>> >>> Both functions are implemented in Python, but median() starts out with >>> this notable line: >>> >>> data = sorted(data) >>> >>> which gives back a copy, iterated over rapidly in C. All subsequent >>> work is done on that copy. >>> >>> The same effect could be had with mean() by taking a snapshot using >>> list(q) and, I believe, would have the same effect (the source code >>> for the sorted() function begins by calling PySequence_List). >>> >>> In any case, it makes *conceptual* sense to do your analysis on a copy >>> of the queue, thus ensuring that your stats are stable. The other >>> threads can keep going while you do your calculations, even if that >>> means changing the queue. >>> >>> ChrisA >> Sorry for any injected confusion here, but that line "data = >> sorted(data)" appears as though it takes the value of the variable named >> _data_, sorts it and returns it to the same variable store, so no copy >> would be created. Am I missing something there? > The variable name "data" is the parameter to median(), so it's > whatever you ask for the median of. (I didn't make that obvious in my > previous post - an excess of brevity on my part.) > > The sorted() function, UNlike list.sort(), returns a sorted copy of > what it's given. I delved into the CPython source code for that, and > it begins with the PySequence_List call to (effectively) call > list(data) to get a copy of it. It ought to be a thread-safe copy due > to holding the GIL the entire time. I'm not sure what would happen in > a GIL-free world but most likely the lock on the input object would > still ensure thread safety. > > ChrisA Aah - thanks, Chris! That makes much more sense. From eryksun at gmail.com Wed Mar 29 14:30:36 2023 From: eryksun at gmail.com (Eryk Sun) Date: Wed, 29 Mar 2023 13:30:36 -0500 Subject: Ole version set as default In-Reply-To: References: Message-ID: On 3/29/23, Pranav Bhardwaj wrote: > I am Pranav Bhardwaj and I stuck in a problem. My problem is > that in my system I have python 3.11.2 but when I type python in my command > prompt, my command prompt show that python version 2.7.13 as a default. Run the following command in the shell where.exe python Note the first directory where "python" is found. Edit both the system and the user environment variables to remove that directory from both the system and user "Path" environment variable. Open a new shell from Explorer, and confirm that "python" no longer runs Python 2. If "python" still runs Python 2, repeat this procedure. Next run the Python 3.11 installer again to modify the installation. On the second page, enable the option to add Python to the environment variables, and click "install". After it's done, open a new shell. Running "python" should start Python 3.11. Also "pip" should work. You should also be able to run Python using the "py" launcher and pip via "py -m pip". To ensure that that .py file association is correct, open the system settings app and navigate to "Apps" -> "Default Apps". Enter ".py" and ensure that it's associated with the Python app that has a rocket on its icon (i.e. Python's "py" launcher). Repeat this for ".pyw", ".pyz", and ".pyc". From mats at wichmann.us Wed Mar 29 14:32:47 2023 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 29 Mar 2023 12:32:47 -0600 Subject: Ole version set as default In-Reply-To: References: Message-ID: On 3/29/23 10:46, Pranav Bhardwaj wrote: > Dear sir, > I am Pranav Bhardwaj and I stuck in a problem. My problem is > that in my system I have python 3.11.2 but when I type python in my command > prompt, my command prompt show that python version 2.7.13 as a default. And > I can't be able to find python 2.7.13 in my system in any file once you open that Olde Python that you can't find: >>> import sys >>> sys.executable voila! you've found it. and I tried > various methods to set python 3.11.2 as a default but can't be able to do > so. I tried to change environment variables, try to find and delete python > 2.7.13 , try to set python 3.11.2 as default, but I can't be able to do so. > So can you help me how can I solve this problem? As noted elsewhere, for the python.org version, the Python Launcher exists for this purpose. py --list shows you which Pythons it knows about, and with a '*' which one is the default. You can instruct py which one should be default (for that you need to create an ini file), but it will otherwise choose the latest, so you shouldn't have the problem of it choosing 2.7 over 3.11 with the launcher. From mk1853387 at gmail.com Wed Mar 29 14:40:00 2023 From: mk1853387 at gmail.com (marc nicole) Date: Wed, 29 Mar 2023 20:40:00 +0200 Subject: combinations of all rows and cols from a dataframe Message-ID: Hello everyone, Given a dataframe like this: 2 6 8 5 I want to yield the following list of lists: [ [[2],[6,5]], [[2],[6]], [[2],[5]], [[8],[6,5]], [[8],[6]], [[8],[5]], [[6],[2,8]], [[6],[8]], [[6],[2]], [[5],[2,8]], [[5],[2]], [[5],[8]], [[6,5],[2,8]] ] I have written the following (which doesn't yield the expected results) import pandas as pd > from itertools import combinations > import numpy as np > resList=[] > resListTmp=[] > resListTmp2=[] > dataframe = > pd.read_excel("C:\\Users\\user\\Desktop\\testData.xlsx",index_col=False,header=None) for i in range(0, len(dataframe)+1): > for j in range(0, len(dataframe.columns)): > for k in range (0,len(dataframe)+1): > for xVals in list(combinations(dataframe.iloc[k:i,j], i)): > if list(xVals) not in resListTmp: > resListTmp.append(list(xVals)) > resListTmp2.append(resListTmp) > resList.append(resListTmp2) > print(resList) > What is wrong with my code? From greg.ewing at canterbury.ac.nz Wed Mar 29 16:30:08 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 30 Mar 2023 09:30:08 +1300 Subject: What kind of "thread safe" are deque's actually? In-Reply-To: References: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> <4720a4e8-ab93-bf0d-77b1-4dd1ac381e35@gmail.com> Message-ID: On 30/03/23 6:13 am, Chris Angelico wrote: > I'm not sure what would happen in > a GIL-free world but most likely the lock on the input object would > still ensure thread safety. In a GIL-free world, I would not expect deque to hold a lock the entire time that something was iterating over it. That would require holding the lock as long as an iterator object existed referencing it, which could be a long time, even longer than the caller expects (no reference counting, remember!) So for future-proofing I would recommend using deque's copy() method to copy it before doing anything that iterates over it. Hopefully that would be implemented in a thread-safe way (although the docs don't currently promise that). -- Greg From greg.ewing at canterbury.ac.nz Wed Mar 29 16:50:51 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 30 Mar 2023 09:50:51 +1300 Subject: How to add clickable url links to 3D Matplotlib chart ? In-Reply-To: References: Message-ID: On 30/03/23 8:39 am, a a wrote: > How to add clickable url links to the following 3D Matplotlib chart to make it knowledge representation 3D chart, make of 1,000+ open Tabs in Firefox ? It seems that matplotlib can be made to generate SVG images with hyperlinks in them: https://matplotlib.org/stable/gallery/misc/hyperlinks_sgskip.html -- Greg From aewindhorn at gmail.com Wed Mar 29 16:47:25 2023 From: aewindhorn at gmail.com (windhorn) Date: Wed, 29 Mar 2023 13:47:25 -0700 (PDT) Subject: Python file location Message-ID: <4f75241c-3396-4b0d-a3c8-92895aaf3ef9n@googlegroups.com> I have an older laptop I use for programming, particularly Python and Octave, running a variety of Debian Linux, and I am curious if there is a "standard" place in the file system to store this type of program file. OK, I know they should go in a repository and be managed by an IDE but this seems like way overkill for the kind of programming that I do, normally a single file. Any suggestions welcome, thanks. Regards, Allen From manta103g at gmail.com Wed Mar 29 19:11:22 2023 From: manta103g at gmail.com (a a) Date: Wed, 29 Mar 2023 16:11:22 -0700 (PDT) Subject: How to add clickable url links to 3D Matplotlib chart ? In-Reply-To: References: Message-ID: <6b011cd2-faff-4d02-a6da-2cd32109ed45n@googlegroups.com> On Wednesday, 29 March 2023 at 22:51:15 UTC+2, Greg Ewing wrote: > On 30/03/23 8:39 am, a a wrote: > > How to add clickable url links to the following 3D Matplotlib chart to make it knowledge representation 3D chart, make of 1,000+ open Tabs in Firefox ? > It seems that matplotlib can be made to generate SVG images with > hyperlinks in them: > > https://matplotlib.org/stable/gallery/misc/hyperlinks_sgskip.html > > -- > Greg thank you but I need mouse hover-on, mouse click events to be handled by a simple algorithm to calculate which ball/circle has been selected (in the Matplotlib 3D animated chart above) to make the selected ball to flash and have label opened made of url icon, name of url, followed by url (exactly what Firefox makes with Tabs) For knowledge representation, 1,000+ Tabs open in Firefox, earthquakes 3D live chart by Giuseppe is a nice tool. One axis can represent time (timeline), two other axis can represent features attributed to to opened Tabs, like frequency of visits, ranking. Ok, balls should overlayed with a respective url icon, as done in Firefox (Tabs row) : url icon + label's name abbreviated From cs at cskk.id.au Wed Mar 29 20:13:09 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 30 Mar 2023 11:13:09 +1100 Subject: Standard class for time *period*? In-Reply-To: References: Message-ID: On 30Mar2023 10:13, Cameron Simpson wrote: >I do in fact have a `TimePartition` in my timeseries module; it >presently doesn't do comparisons because I'm not comparing them - I'm >just using them as slices into the timeseries data on the whole. > >https://github.com/cameron-simpson/css/blob/0ade6d191833b87cab8826d7ecaee4d114992c45/lib/python/cs/timeseries.py#L2163 On review it isn't a great match for a simple time range; it's aimed at expressing the time ranges into which my time series data files are broken up. I think most of the code using this particular class just starts with a `start_unixtime` and `end_unixtime` and indexes whichever timeseries it's using, and these come into play internally to access the relevant files. There are a bunch of methods to take a pair of start/stop unixtimes and return time slot indices etc. So even I don't have a purely time period class, right now anyway; passing around a pair of floats is so simple that I probably haven't elaborated on it. Just made ways to make that pair from what I'm given. Cheers, Cameron Simpson From cs at cskk.id.au Wed Mar 29 19:13:42 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 30 Mar 2023 10:13:42 +1100 Subject: Standard class for time *period*? In-Reply-To: <87edp8krn8.fsf@debian-BULLSEYE-live-builder-AMD64> References: <87edp8krn8.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: On 29Mar2023 08:17, Loris Bennett wrote: >I am glad to hear that I am not alone :-) However, my use-case is fairly >trivial, indeed less complicated than yours. So, in truth I don't >really need a Period class. I just thought it might be a sufficiently >generic itch that someone else with a more complicated use-case could >have already scratched. Well, my attitude to time spans is to get the start and end (or start and length, but I prefer the former) as UNIX timestamps and work from that. I try to stay as far from datetimes as possible, because of their foibles (particularly timezones, but really the whole calendar decomposition etc) and use them only for presentation. I do in fact have a `TimePartition` in my timeseries module; it presently doesn't do comparisons because I'm not comparing them - I'm just using them as slices into the timeseries data on the whole. https://github.com/cameron-simpson/css/blob/0ade6d191833b87cab8826d7ecaee4d114992c45/lib/python/cs/timeseries.py#L2163 But it would be easy to give that class `__lt__` etc methods. You're welcome to use it, or anything from the module (it's on PyPI). Cheers, Cameron Simpson From rosuav at gmail.com Wed Mar 29 21:39:54 2023 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Mar 2023 12:39:54 +1100 Subject: What kind of "thread safe" are deque's actually? In-Reply-To: References: <71BF8D21-1A75-4B86-AE0C-7E28DBE702CD@gmail.com> <4720a4e8-ab93-bf0d-77b1-4dd1ac381e35@gmail.com> Message-ID: On Thu, 30 Mar 2023 at 07:36, Greg Ewing via Python-list wrote: > > On 30/03/23 6:13 am, Chris Angelico wrote: > > I'm not sure what would happen in > > a GIL-free world but most likely the lock on the input object would > > still ensure thread safety. > > In a GIL-free world, I would not expect deque to hold a lock > the entire time that something was iterating over it. That > would require holding the lock as long as an iterator object > existed referencing it, which could be a long time, even > longer than the caller expects (no reference counting, > remember!) Certainly not, but I *would* expect the sorted() call to retain a lock on the input object while it copies it (or, more precisely, for the PySequence_List() call to do that). > So for future-proofing I would recommend using deque's > copy() method to copy it before doing anything that iterates > over it. Hopefully that would be implemented in a thread-safe > way (although the docs don't currently promise that). > Probably? It's actually less clear there, since a deque's copy method is built on top of basic iteration and broadly looks like this (though in C, not in Python): def copy(self): ret = deque() ret.extend(self) return ret Simplified, but mostly accurate. And extending is done by getting an iterator, then repeatedly appending. So.... probably safe? Question mark? ChrisA From cs at cskk.id.au Wed Mar 29 21:24:11 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 30 Mar 2023 12:24:11 +1100 Subject: Python file location In-Reply-To: <4f75241c-3396-4b0d-a3c8-92895aaf3ef9n@googlegroups.com> References: <4f75241c-3396-4b0d-a3c8-92895aaf3ef9n@googlegroups.com> Message-ID: On 29Mar2023 13:47, windhorn wrote: >I have an older laptop I use for programming, particularly Python and >Octave, running a variety of Debian Linux, and I am curious if there is >a "standard" place in the file system to store this type of program >file. OK, I know they should go in a repository and be managed by an >IDE but this seems like way overkill for the kind of programming that I >do, normally a single file. Any suggestions welcome, thanks. Are you writing personal scripts? ~/bin then. Person modules you import in your personal scripts? I put these in ~/lib/python/cs/ for my modules, which are all named "cs.*" (avoids conflict). But that's just me. Cheers, Cameron Simpson From rosuav at gmail.com Wed Mar 29 21:56:34 2023 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Mar 2023 12:56:34 +1100 Subject: Python file location In-Reply-To: <4f75241c-3396-4b0d-a3c8-92895aaf3ef9n@googlegroups.com> References: <4f75241c-3396-4b0d-a3c8-92895aaf3ef9n@googlegroups.com> Message-ID: On Thu, 30 Mar 2023 at 11:08, windhorn wrote: > > I have an older laptop I use for programming, particularly Python and Octave, running a variety of Debian Linux, and I am curious if there is a "standard" place in the file system to store this type of program file. OK, I know they should go in a repository and be managed by an IDE but this seems like way overkill for the kind of programming that I do, normally a single file. Any suggestions welcome, thanks. > Standard? No. Do whatever you like :) But there are a few useful conventions. Personally, I keep all my random tools in a shed - specifically, ~/shed, which is a single git repository in which I throw all sorts of random junk, mostly those single-file scripts that don't have any other real identity. (Some of them do end up growing more files. It's rather ill-defined as a concept.) You could also just leave them in your home directory. That's pretty decent too. ChrisA From PythonList at DancesWithMice.info Wed Mar 29 23:59:59 2023 From: PythonList at DancesWithMice.info (dn) Date: Thu, 30 Mar 2023 16:59:59 +1300 Subject: Python file location In-Reply-To: <4f75241c-3396-4b0d-a3c8-92895aaf3ef9n@googlegroups.com> References: <4f75241c-3396-4b0d-a3c8-92895aaf3ef9n@googlegroups.com> Message-ID: <2a2f649e-9a9c-7591-32f9-0226479a1e50@DancesWithMice.info> On 30/03/2023 09.47, windhorn wrote: > I have an older laptop I use for programming, particularly Python and Octave, running a variety of Debian Linux, and I am curious if there is a "standard" place in the file system to store this type of program file. OK, I know they should go in a repository and be managed by an IDE but this seems like way overkill for the kind of programming that I do, normally a single file. Any suggestions welcome, thanks. My home-directory has a sub-dir called Projects. Larger and identifiable projects are put in their own sub-dir of that. There are also 'buckets' which contain (usually single) files such as you describe, eg PythonTraining, NotesInClass, and the one used when folk 'here' ask code-questions: "experiments". NB "Projects" may or may not be Python-based, eg may be the name of a course, with sub-directories off that for each lecture or tutorial. Python doesn't actually care where code is placed. The act of running a script causes Python to add the script's directory to the PYTHONPATH. That means that it will 'find' any files used by/from the script, relative to that dir. Accordingly, use a dir-structure is probably more about exerting some order over what would otherwise quickly become a confusion! As you say, I see little point in making "experiments" into a repo. The life-time of any such code is that of the thread/conversation (Note to self: should clean-up some of the old-stuff in there). The others are set-up under git. That to enable the use of a GitLab instance* as a form of off-site backup, or as a means of exchange with others (at the project-level). Again, agreeing with you: if PyCharm is not running, it might not be worth (waiting while) firing it up just to check some 'experiment'. In which case, either the task can be accomplished using the Python REPL, or maybe a simple text-editor will be quite sufficient to copy-paste code from an email-message and provide a basis for the-whatever (in a file called "Allan.py", for example), and from which a suggested-solution may be posted afterwards... YMMV! * New Zealand Open Source Society perq of membership -- Regards, =dn From ssfirodia at gmail.com Thu Mar 30 10:17:25 2023 From: ssfirodia at gmail.com (Sumeet Firodia) Date: Thu, 30 Mar 2023 19:47:25 +0530 Subject: Python not showing correct version In-Reply-To: References: Message-ID: > > Hi Team, > > I have installed Python 3.8 for Snowpark but when I check the version in > command prompt it shows me Python 3.10.10. > > C:\Users\admin>python --version > Python 3.10.10 > > Also when I try to uninstall 3.10 it says no such version is installed. > > C:\Users\admin>pip uninstall python 3.10.10 > WARNING: Skipping python as it is not installed. > WARNING: Skipping 3.10.10 as it is not installed. > > Can you please help me here as my snowpark assignment is stuck because of > this issue. > > Thanks > Sumeet > > From auriocus at gmx.de Thu Mar 30 01:54:50 2023 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 30 Mar 2023 07:54:50 +0200 Subject: How to add clickable url links to 3D Matplotlib chart ? In-Reply-To: <6b011cd2-faff-4d02-a6da-2cd32109ed45n@googlegroups.com> References: <6b011cd2-faff-4d02-a6da-2cd32109ed45n@googlegroups.com> Message-ID: Am 30.03.23 um 01:11 schrieb a a: > On Wednesday, 29 March 2023 at 22:51:15 UTC+2, Greg Ewing wrote: >> On 30/03/23 8:39 am, a a wrote: >>> How to add clickable url links to the following 3D Matplotlib chart to make it knowledge representation 3D chart, make of 1,000+ open Tabs in Firefox ? >> It seems that matplotlib can be made to generate SVG images with >> hyperlinks in them: >> >> https://matplotlib.org/stable/gallery/misc/hyperlinks_sgskip.html >> >> -- >> Greg > thank you > but I need mouse hover-on, mouse click events to be handled by a simple algorithm to calculate which ball/circle has been selected (in the Matplotlib 3D animated chart above) to make the selected ball to flash and have label opened made of url icon, name of url, followed by url (exactly what Firefox makes with Tabs) > > For knowledge representation, 1,000+ Tabs open in Firefox, earthquakes 3D live chart by Giuseppe is a nice tool. > > One axis can represent time (timeline), two other axis can represent features attributed to to opened Tabs, like frequency of visits, ranking. > > Ok, balls should overlayed with a respective url icon, as done in Firefox (Tabs row) : url icon + label's name abbreviated It doesn't sound as if there is a "one-line" solution to this problem. It sounds more like you want a video game engine to interact with a 3D world. There used to be a 3D version of HTML, called VRML, with the successor of X3D that could show such a thing in the browser, but I doubt that there is easy support for it any more in recent browsers. Therefore it would be difficult to post this to the internet, unless you invest in some JS programming. In case you want to run this on your local computer, as opposed to in the browser, you can check out Python game engines. Christian From loris.bennett at fu-berlin.de Thu Mar 30 02:19:03 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Thu, 30 Mar 2023 08:19:03 +0200 Subject: Python file location References: <4f75241c-3396-4b0d-a3c8-92895aaf3ef9n@googlegroups.com> Message-ID: <87355mpxrc.fsf@debian-BULLSEYE-live-builder-AMD64> windhorn writes: > I have an older laptop I use for programming, particularly Python and > Octave, running a variety of Debian Linux, and I am curious if there > is a "standard" place in the file system to store this type of program > file. OK, I know they should go in a repository and be managed by an > IDE but this seems like way overkill for the kind of programming that > I do, normally a single file. Any suggestions welcome, thanks. How about /usr/local/bin? That should already be included in $PATH. Cheers, Loris -- This signature is currently under constuction. From andreas.eisele at gmail.com Thu Mar 30 05:15:51 2023 From: andreas.eisele at gmail.com (Andreas Eisele) Date: Thu, 30 Mar 2023 02:15:51 -0700 (PDT) Subject: built-in pow() vs. math.pow() Message-ID: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> I sometimes make use of the fact that the built-in pow() function has an optional third argument for modulo calculation, which is handy when dealing with tasks from number theory, very large numbers, problems from Project Euler, etc. I was unpleasantly surprised that math.pow() does not have this feature, hence "from math import *" overwrites the built-in pow() function with a function that lacks functionality. I am wondering for the rationale of this. Does math.pow() do anything that the built-in version can not do, and if not, why is it even there? Thanks in advance for any enlightening comment on this. Best regards, Andreas From manta103g at gmail.com Thu Mar 30 07:14:22 2023 From: manta103g at gmail.com (a a) Date: Thu, 30 Mar 2023 04:14:22 -0700 (PDT) Subject: How to add clickable url links to 3D Matplotlib chart ? In-Reply-To: References: <6b011cd2-faff-4d02-a6da-2cd32109ed45n@googlegroups.com> Message-ID: On Thursday, 30 March 2023 at 07:55:13 UTC+2, Christian Gollwitzer wrote: > Am 30.03.23 um 01:11 schrieb a a: > > On Wednesday, 29 March 2023 at 22:51:15 UTC+2, Greg Ewing wrote: > >> On 30/03/23 8:39 am, a a wrote: > >>> How to add clickable url links to the following 3D Matplotlib chart to make it knowledge representation 3D chart, make of 1,000+ open Tabs in Firefox ? > >> It seems that matplotlib can be made to generate SVG images with > >> hyperlinks in them: > >> > >> https://matplotlib.org/stable/gallery/misc/hyperlinks_sgskip.html > >> > >> -- > >> Greg > > thank you > > but I need mouse hover-on, mouse click events to be handled by a simple algorithm to calculate which ball/circle has been selected (in the Matplotlib 3D animated chart above) to make the selected ball to flash and have label opened made of url icon, name of url, followed by url (exactly what Firefox makes with Tabs) > > > > For knowledge representation, 1,000+ Tabs open in Firefox, earthquakes 3D live chart by Giuseppe is a nice tool. > > > > One axis can represent time (timeline), two other axis can represent features attributed to to opened Tabs, like frequency of visits, ranking. > > > > Ok, balls should overlayed with a respective url icon, as done in Firefox (Tabs row) : url icon + label's name abbreviated > It doesn't sound as if there is a "one-line" solution to this problem. > It sounds more like you want a video game engine to interact with a 3D > world. > > There used to be a 3D version of HTML, called VRML, with the successor > of X3D that could show such a thing in the browser, but I doubt that > there is easy support for it any more in recent browsers. Therefore it > would be difficult to post this to the internet, unless you invest in > some JS programming. In case you want to run this on your local > computer, as opposed to in the browser, you can check out Python game > engines. > > Christian VRML is to heavy for me -- http://mpld3.github.io/examples/index.html#example-gallery Matplotlib charts can be integrated into web browser / Javascript mpld3 ? Bringing Matplotlib to the Browser mpld3.github.io mpld3 project brings together Matplotlib, the popular Python-based graphing library, and D3js, the popular JavaScript library for creating interactive Javascript can track mouse position, mouse events, so I can calculate which ball/circle is selected to modify hue and generate active label assigned to the ball and have url link in the label opened by 2 mouse clicks. WebGL is nice but heavy for my project https://webglsamples.org/ https://en.wikipedia.org/wiki/WebGL All I need is Javascript to get access to database rendering geolocated balls, charted by Matplolib to update input data for a given ball and have Matplotlib chart to refresh on mouse click/ mouse hover - on To get 3D space I need to geolocate 1,000+Tabs open in Firefox Website geolocation I can read from domain register/s I need to project spherical Earth's globo to the place to get X - Y axis As a newbie to Python, I am looking for an experienced coder. From manta103g at gmail.com Thu Mar 30 07:19:40 2023 From: manta103g at gmail.com (a a) Date: Thu, 30 Mar 2023 04:19:40 -0700 (PDT) Subject: How to add clickable url links to 3D Matplotlib chart ? In-Reply-To: References: <6b011cd2-faff-4d02-a6da-2cd32109ed45n@googlegroups.com> Message-ID: <99cbb011-b9a9-426c-ab11-57f6ff9ff97fn@googlegroups.com> On Thursday, 30 March 2023 at 13:14:33 UTC+2, a a wrote: > On Thursday, 30 March 2023 at 07:55:13 UTC+2, Christian Gollwitzer wrote: > > Am 30.03.23 um 01:11 schrieb a a: > > > On Wednesday, 29 March 2023 at 22:51:15 UTC+2, Greg Ewing wrote: > > >> On 30/03/23 8:39 am, a a wrote: > > >>> How to add clickable url links to the following 3D Matplotlib chart to make it knowledge representation 3D chart, make of 1,000+ open Tabs in Firefox ? > > >> It seems that matplotlib can be made to generate SVG images with > > >> hyperlinks in them: > > >> > > >> https://matplotlib.org/stable/gallery/misc/hyperlinks_sgskip.html > > >> > > >> -- > > >> Greg > > > thank you > > > but I need mouse hover-on, mouse click events to be handled by a simple algorithm to calculate which ball/circle has been selected (in the Matplotlib 3D animated chart above) to make the selected ball to flash and have label opened made of url icon, name of url, followed by url (exactly what Firefox makes with Tabs) > > > > > > For knowledge representation, 1,000+ Tabs open in Firefox, earthquakes 3D live chart by Giuseppe is a nice tool. > > > > > > One axis can represent time (timeline), two other axis can represent features attributed to to opened Tabs, like frequency of visits, ranking. > > > > > > Ok, balls should overlayed with a respective url icon, as done in Firefox (Tabs row) : url icon + label's name abbreviated > > It doesn't sound as if there is a "one-line" solution to this problem. > > It sounds more like you want a video game engine to interact with a 3D > > world. > > > > There used to be a 3D version of HTML, called VRML, with the successor > > of X3D that could show such a thing in the browser, but I doubt that > > there is easy support for it any more in recent browsers. Therefore it > > would be difficult to post this to the internet, unless you invest in > > some JS programming. In case you want to run this on your local > > computer, as opposed to in the browser, you can check out Python game > > engines. > > > > Christian > VRML is to heavy for me > > -- > > > http://mpld3.github.io/examples/index.html#example-gallery > > Matplotlib charts can be integrated into web browser / Javascript > > mpld3 ? Bringing Matplotlib to the Browser > mpld3.github.io > > mpld3 project brings together Matplotlib, the popular Python-based graphing library, and D3js, the popular JavaScript library for creating interactive > > Javascript can track mouse position, mouse events, so I can calculate > which ball/circle is selected to modify hue and generate active label assigned to the ball and have url link in the label opened by 2 mouse clicks. > > WebGL is nice but heavy for my project > https://webglsamples.org/ > > https://en.wikipedia.org/wiki/WebGL > > All I need is Javascript to get access to database rendering geolocated balls, charted by Matplolib > to update input data for a given ball and have Matplotlib chart to refresh on mouse click/ mouse hover - on > > To get 3D space I need to geolocate 1,000+Tabs open in Firefox > > Website geolocation I can read from domain register/s > > I need to project spherical Earth's globo to the place to get X - Y axis > > > As a newbie to Python, I am looking for an experienced coder. follow-up http://mpld3.github.io/examples/index.html#example-gallery I need to loop Matplotlib charts to get refreshed with new data inputs with mouse events (ball selection, selected ball new hue) Please keep in mind I need to open great Matplotlib charts by Giuseppe in web browser to serve as a knowledge representation and visualization for 1,000+ Tab open in Firefox https://twitter.com/gmrpetricca/status/1633477532526817281 From manta103g at gmail.com Thu Mar 30 07:37:56 2023 From: manta103g at gmail.com (a a) Date: Thu, 30 Mar 2023 04:37:56 -0700 (PDT) Subject: How to add clickable url links to 3D Matplotlib chart ? In-Reply-To: <99cbb011-b9a9-426c-ab11-57f6ff9ff97fn@googlegroups.com> References: <6b011cd2-faff-4d02-a6da-2cd32109ed45n@googlegroups.com> <99cbb011-b9a9-426c-ab11-57f6ff9ff97fn@googlegroups.com> Message-ID: <8abcce90-6ac5-4f83-aeae-11351f506af1n@googlegroups.com> On Thursday, 30 March 2023 at 13:19:51 UTC+2, a a wrote: > On Thursday, 30 March 2023 at 13:14:33 UTC+2, a a wrote: > > On Thursday, 30 March 2023 at 07:55:13 UTC+2, Christian Gollwitzer wrote: > > > Am 30.03.23 um 01:11 schrieb a a: > > > > On Wednesday, 29 March 2023 at 22:51:15 UTC+2, Greg Ewing wrote: > > > >> On 30/03/23 8:39 am, a a wrote: > > > >>> How to add clickable url links to the following 3D Matplotlib chart to make it knowledge representation 3D chart, make of 1,000+ open Tabs in Firefox ? > > > >> It seems that matplotlib can be made to generate SVG images with > > > >> hyperlinks in them: > > > >> > > > >> https://matplotlib.org/stable/gallery/misc/hyperlinks_sgskip.html > > > >> > > > >> -- > > > >> Greg > > > > thank you > > > > but I need mouse hover-on, mouse click events to be handled by a simple algorithm to calculate which ball/circle has been selected (in the Matplotlib 3D animated chart above) to make the selected ball to flash and have label opened made of url icon, name of url, followed by url (exactly what Firefox makes with Tabs) > > > > > > > > For knowledge representation, 1,000+ Tabs open in Firefox, earthquakes 3D live chart by Giuseppe is a nice tool. > > > > > > > > One axis can represent time (timeline), two other axis can represent features attributed to to opened Tabs, like frequency of visits, ranking. > > > > > > > > Ok, balls should overlayed with a respective url icon, as done in Firefox (Tabs row) : url icon + label's name abbreviated > > > It doesn't sound as if there is a "one-line" solution to this problem. > > > It sounds more like you want a video game engine to interact with a 3D > > > world. > > > > > > There used to be a 3D version of HTML, called VRML, with the successor > > > of X3D that could show such a thing in the browser, but I doubt that > > > there is easy support for it any more in recent browsers. Therefore it > > > would be difficult to post this to the internet, unless you invest in > > > some JS programming. In case you want to run this on your local > > > computer, as opposed to in the browser, you can check out Python game > > > engines. > > > > > > Christian > > VRML is to heavy for me > > > > -- > > > > > > http://mpld3.github.io/examples/index.html#example-gallery > > > > Matplotlib charts can be integrated into web browser / Javascript > > > > mpld3 ? Bringing Matplotlib to the Browser > > mpld3.github.io > > > > mpld3 project brings together Matplotlib, the popular Python-based graphing library, and D3js, the popular JavaScript library for creating interactive > > > > Javascript can track mouse position, mouse events, so I can calculate > > which ball/circle is selected to modify hue and generate active label assigned to the ball and have url link in the label opened by 2 mouse clicks. > > > > WebGL is nice but heavy for my project > > https://webglsamples.org/ > > > > https://en.wikipedia.org/wiki/WebGL > > > > All I need is Javascript to get access to database rendering geolocated balls, charted by Matplolib > > to update input data for a given ball and have Matplotlib chart to refresh on mouse click/ mouse hover - on > > > > To get 3D space I need to geolocate 1,000+Tabs open in Firefox > > > > Website geolocation I can read from domain register/s > > > > I need to project spherical Earth's globo to the place to get X - Y axis > > > > > > As a newbie to Python, I am looking for an experienced coder. > follow-up > > http://mpld3.github.io/examples/index.html#example-gallery > > I need to loop Matplotlib charts to get refreshed with new data inputs with mouse events > (ball selection, selected ball new hue) > > Please keep in mind I need to open great Matplotlib charts by Giuseppe in web browser > to serve as a knowledge representation and visualization for 1,000+ Tab open in Firefox > > https://twitter.com/gmrpetricca/status/1633477532526817281 2D Matplotlib solution for my project http://mpld3.github.io/examples/html_tooltips.html How to get it upgraded to 3D Matplotlib and get label to feature web link url assigned to a specified ball/ circle ? From barry at barrys-emacs.org Thu Mar 30 13:11:31 2023 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 30 Mar 2023 18:11:31 +0100 Subject: built-in pow() vs. math.pow() In-Reply-To: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> References: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> Message-ID: <2F5598B0-14E1-44A0-9DA1-666CC846E020@barrys-emacs.org> > On 30 Mar 2023, at 10:15, Andreas Eisele wrote: > > I sometimes make use of the fact that the built-in pow() function has an optional third argument for modulo calculation, which is handy when dealing with tasks from number theory, very large numbers, problems from Project Euler, etc. I was unpleasantly surprised that math.pow() does not have this feature, hence "from math import *" overwrites the built-in pow() function with a function that lacks functionality. I am wondering for the rationale of this. Does math.pow() do anything that the built-in version can not do, and if not, why is it even there? Maybe math.pow() aways using IEEE 754(?) float point via the C runtime math routines. pow() will give int answer if called with int args. Barry > Thanks in advance for any enlightening comment on this. > Best regards, Andreas > -- > https://mail.python.org/mailman/listinfo/python-list > From barry at barrys-emacs.org Thu Mar 30 13:14:51 2023 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 30 Mar 2023 18:14:51 +0100 Subject: Python not showing correct version In-Reply-To: References: Message-ID: > On 30 Mar 2023, at 15:17, Sumeet Firodia wrote: > >> >> Hi Team, >> >> I have installed Python 3.8 for Snowpark but when I check the version in >> command prompt it shows me Python 3.10.10. >> >> C:\Users\admin>python --version >> Python 3.10.10 Try this: py -3.8 And this to list all version of python installed: py -0 >> >> Also when I try to uninstall 3.10 it says no such version is installed. >> >> C:\Users\admin>pip uninstall python 3.10.10 >> WARNING: Skipping python as it is not installed. >> WARNING: Skipping 3.10.10 as it is not installed. PIP is for installing python modules not the python program. The python program is installed by running the .exe that you get from python.org , for example. Use the standard Windows method to uninstall a program. Search the web for "windows uninstall software" if you are not sure how to do this. Barry >> >> Can you please help me here as my snowpark assignment is stuck because of >> this issue. >> >> Thanks >> Sumeet >> >> > -- > https://mail.python.org/mailman/listinfo/python-list > From barry at barrys-emacs.org Thu Mar 30 13:15:57 2023 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 30 Mar 2023 18:15:57 +0100 Subject: built-in pow() vs. math.pow() In-Reply-To: <2F5598B0-14E1-44A0-9DA1-666CC846E020@barrys-emacs.org> References: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> <2F5598B0-14E1-44A0-9DA1-666CC846E020@barrys-emacs.org> Message-ID: > On 30 Mar 2023, at 18:11, Barry Scott wrote: > > > >> On 30 Mar 2023, at 10:15, Andreas Eisele wrote: >> >> I sometimes make use of the fact that the built-in pow() function has an optional third argument for modulo calculation, which is handy when dealing with tasks from number theory, very large numbers, problems from Project Euler, etc. I was unpleasantly surprised that math.pow() does not have this feature, hence "from math import *" overwrites the built-in pow() function with a function that lacks functionality. I am wondering for the rationale of this. Does math.pow() do anything that the built-in version can not do, and if not, why is it even there? > > Maybe math.pow() aways using IEEE 754(?) float point via the C runtime math routines. > pow() will give int answer if called with int args. And the C version of pow only supports 2 arg call. SYNOPSIS #include double pow(double x, double y); long double powl(long double x, long double y); float powf(float x, float y); > > Barry > > >> Thanks in advance for any enlightening comment on this. >> Best regards, Andreas >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > -- > https://mail.python.org/mailman/listinfo/python-list > From roel at roelschroeven.net Thu Mar 30 13:22:53 2023 From: roel at roelschroeven.net (Roel Schroeven) Date: Thu, 30 Mar 2023 19:22:53 +0200 Subject: built-in pow() vs. math.pow() In-Reply-To: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> References: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> Message-ID: Andreas Eisele schreef op 30/03/2023 om 11:15: > I sometimes make use of the fact that the built-in pow() function has an optional third argument for modulo calculation, which is handy when dealing with tasks from number theory, very large numbers, problems from Project Euler, etc. I was unpleasantly surprised that math.pow() does not have this feature, hence "from math import *" overwrites the built-in pow() function with a function that lacks functionality. I am wondering for the rationale of this. Does math.pow() do anything that the built-in version can not do, and if not, why is it even there? According to the docs, "Unlike the built-in ** operator, math.pow() converts both its arguments to type float. Use ** or the built-in pow() function for computing exact integer powers." I think that means that math.pow() is more meant to work with floats, while the built-in is more meant for integers (even though the built-in works with floats just fine). In any case, I would strongly advocate against "from math import *" (not just for math but for any module really). One of the reasons is the potential for name conflicts, which is exactly what you experience here. Either import the things you need explicitly: "from math import sin, cos, exp" (for example). Or a plain import: "import math" combined with "math.sin", "math.cos". Or use an abbreviation: "import math as m" combined with "m.sin", "m.cos". -- "There is no cause so noble that it will not attract fuggheads." -- Larry Niven From list1 at tompassin.net Thu Mar 30 13:25:30 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 30 Mar 2023 13:25:30 -0400 Subject: built-in pow() vs. math.pow() In-Reply-To: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> References: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> Message-ID: <61154096-2d94-1ea7-b5de-54db14719bce@tompassin.net> On 3/30/2023 5:15 AM, Andreas Eisele wrote: > I sometimes make use of the fact that the built-in pow() function has an optional third argument for modulo calculation, which is handy when dealing with tasks from number theory, very large numbers, problems from Project Euler, etc. I was unpleasantly surprised that math.pow() does not have this feature, hence "from math import *" overwrites the built-in pow() function with a function that lacks functionality. I am wondering for the rationale of this. Does math.pow() do anything that the built-in version can not do, and if not, why is it even there? Not an answer to your question, but it's better not to use "import *". It's usually better to import just the names you actually need. From list1 at tompassin.net Thu Mar 30 13:23:34 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 30 Mar 2023 13:23:34 -0400 Subject: Python not showing correct version In-Reply-To: References: Message-ID: <614d3168-029c-18f4-a942-8963178d5f48@tompassin.net> On 3/30/2023 10:17 AM, Sumeet Firodia wrote: >> >> Hi Team, >> >> I have installed Python 3.8 for Snowpark but when I check the version in >> command prompt it shows me Python 3.10.10. >> >> C:\Users\admin>python --version >> Python 3.10.10 >> >> Also when I try to uninstall 3.10 it says no such version is installed. >> >> C:\Users\admin>pip uninstall python 3.10.10 >> WARNING: Skipping python as it is not installed. >> WARNING: Skipping 3.10.10 as it is not installed. >> >> Can you please help me here as my snowpark assignment is stuck because of >> this issue. You cannot uninstall Python using pip. It was not installed using it. You probably should not uninstall Python 3.10.10. There are two possibilities: 1. The Snowpack programs will work with Python 3.10. Just run them with "python". This is likely. I notice that its location is unusual, and I wonder how and why it got installed there. 2. For some reason, you have to use the Python 3.8 installation. Either find out where it is located on your system, and create a batch file to run it - you could name it "py38" and type "py38" instead of "python". Or you may be able to use the "py" launcher. It will be there if Python was installed using the ordinary Python installer from python.org. You would type "py -38" instead of "python". From grant.b.edwards at gmail.com Thu Mar 30 15:15:03 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 30 Mar 2023 12:15:03 -0700 (PDT) Subject: built-in pow() vs. math.pow() References: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> <61154096-2d94-1ea7-b5de-54db14719bce@tompassin.net> Message-ID: <6425dfb7.920a0220.dcc7b.045d@mx.google.com> On 2023-03-30, Thomas Passin wrote: > On 3/30/2023 5:15 AM, Andreas Eisele wrote: >> [...] I was unpleasantly surprised that math.pow() does not have >> this feature, hence "from math import *" overwrites the built-in >> pow() function with a function that lacks functionality. [...] > > Not an answer to your question, but it's better not to use "import *". > It's usually better to import just the names you actually need. Or to imporot math and then use math.pow(). Unfortunately, the official Python documentation always seems to assume you do "from import *". I think that leads people to believe it's a good practice when, in fact, it's a frequent source of trouble as the OP found out. -- Grant From wlfraed at ix.netcom.com Thu Mar 30 15:49:54 2023 From: wlfraed at ix.netcom.com (Dennis Lee Bieber) Date: Thu, 30 Mar 2023 15:49:54 -0400 Subject: built-in pow() vs. math.pow() References: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> Message-ID: On Thu, 30 Mar 2023 19:22:53 +0200, Roel Schroeven declaimed the following: >Either import the things you need explicitly: "from math import sin, >cos, exp" (for example). >Or a plain import: "import math" combined with "math.sin", "math.cos". >Or use an abbreviation: "import math as m" combined with "m.sin", "m.cos". Or, for this particular example of not wanting math.pow... >>> from math import * >>> pow(3, 4) 81.0 >>> del pow >>> pow(3, 4) 81 >>> From avi.e.gross at gmail.com Thu Mar 30 17:02:18 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 30 Mar 2023 17:02:18 -0400 Subject: built-in pow() vs. math.pow() In-Reply-To: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> References: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> Message-ID: <00af01d9634a$ea4d3b40$bee7b1c0$@gmail.com> Some questions are more reasonable than others. If the version of a function used in a package were IDENTICAL to the built-in, then why have it? There are many possible reasons a package may tune a function for their own preferences or re-use a name that ends up blocking the view of another name. The bottom line is if you do not want the other one, then don't ask for it by not importing the entire module into your namespace or by explicitly asking for the base function in the ways python provides. Others have replied about differences in various implementations of pow() and reiterated my point above that if you want a specific function instance, it is your responsibility to make sure you get it. One method I would mention that I have not seen is to copy pow() to your own name before importing other things. Something like: pow3 = pow import ... Then use the new name. Or import all of math (despite advice not to) and then make pow3 a synonym for the base version. Most people most of the time will want a small and fast function that does what they asked for and does not waste time looking for an optional third argument and doing something additional. Would you be satisfied if math::pow() simply checked for a third argument and turned around and called base::pow() to handle it? A deeper question I can appreciate is wondering if it is a bug or feature that python (and many other languages) allow results where you can hide a variable or function name. I call it a feature. As with all such variables, scope rules and other such things apply and make the language powerful and sometimes a tad dangerous. -----Original Message----- From: Python-list On Behalf Of Andreas Eisele Sent: Thursday, March 30, 2023 5:16 AM To: python-list at python.org Subject: built-in pow() vs. math.pow() I sometimes make use of the fact that the built-in pow() function has an optional third argument for modulo calculation, which is handy when dealing with tasks from number theory, very large numbers, problems from Project Euler, etc. I was unpleasantly surprised that math.pow() does not have this feature, hence "from math import *" overwrites the built-in pow() function with a function that lacks functionality. I am wondering for the rationale of this. Does math.pow() do anything that the built-in version can not do, and if not, why is it even there? Thanks in advance for any enlightening comment on this. Best regards, Andreas -- https://mail.python.org/mailman/listinfo/python-list From oscar.j.benjamin at gmail.com Thu Mar 30 17:11:33 2023 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 30 Mar 2023 22:11:33 +0100 Subject: built-in pow() vs. math.pow() In-Reply-To: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> References: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> Message-ID: On Thu, 30 Mar 2023 at 17:31, Andreas Eisele wrote: > > I sometimes make use of the fact that the built-in pow() function has an optional third argument for modulo calculation, which is handy when dealing with tasks from number theory, very large numbers, problems from Project Euler, etc. I was unpleasantly surprised that math.pow() does not have this feature, hence "from math import *" overwrites the built-in pow() function with a function that lacks functionality. I am wondering for the rationale of this. Does math.pow() do anything that the built-in version can not do, and if not, why is it even there? It is useful for when you want the pure floating point power which has an approximately fixed computational cost (unlike integer powers). Perhaps it would have been better if it was named fpow similar to fsum vs sum. -- Oscar From rosuav at gmail.com Thu Mar 30 17:27:39 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Mar 2023 08:27:39 +1100 Subject: built-in pow() vs. math.pow() In-Reply-To: References: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> Message-ID: On Fri, 31 Mar 2023 at 08:13, Oscar Benjamin wrote: > > On Thu, 30 Mar 2023 at 17:31, Andreas Eisele wrote: > > > > I sometimes make use of the fact that the built-in pow() function has an optional third argument for modulo calculation, which is handy when dealing with tasks from number theory, very large numbers, problems from Project Euler, etc. I was unpleasantly surprised that math.pow() does not have this feature, hence "from math import *" overwrites the built-in pow() function with a function that lacks functionality. I am wondering for the rationale of this. Does math.pow() do anything that the built-in version can not do, and if not, why is it even there? > > It is useful for when you want the pure floating point power which has > an approximately fixed computational cost (unlike integer powers). > Perhaps it would have been better if it was named fpow similar to fsum > vs sum. > It's called math.pow. That on its own should be a strong indication that it's designed to work with floats. ChrisA From barry at barrys-emacs.org Fri Mar 31 02:39:25 2023 From: barry at barrys-emacs.org (Barry) Date: Fri, 31 Mar 2023 07:39:25 +0100 Subject: built-in pow() vs. math.pow() In-Reply-To: References: Message-ID: > On 30 Mar 2023, at 22:30, Chris Angelico wrote: > > ?On Fri, 31 Mar 2023 at 08:13, Oscar Benjamin wrote: >> >>> On Thu, 30 Mar 2023 at 17:31, Andreas Eisele wrote: >>> >>> I sometimes make use of the fact that the built-in pow() function has an optional third argument for modulo calculation, which is handy when dealing with tasks from number theory, very large numbers, problems from Project Euler, etc. I was unpleasantly surprised that math.pow() does not have this feature, hence "from math import *" overwrites the built-in pow() function with a function that lacks functionality. I am wondering for the rationale of this. Does math.pow() do anything that the built-in version can not do, and if not, why is it even there? >> >> It is useful for when you want the pure floating point power which has >> an approximately fixed computational cost (unlike integer powers). >> Perhaps it would have been better if it was named fpow similar to fsum >> vs sum. >> > > It's called math.pow. That on its own should be a strong indication > that it's designed to work with floats. So long as you know that the math module is provided to give access the C math.h functions. Barry > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From ssfirodia at gmail.com Fri Mar 31 04:33:49 2023 From: ssfirodia at gmail.com (Sumeet Firodia) Date: Fri, 31 Mar 2023 14:03:49 +0530 Subject: Python not showing correct version In-Reply-To: References: Message-ID: Thanks Barry. One more thing is that pip --version also refers to python 3.10 C:\Users\admin>pip --version pip 23.0.1 from C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip (python 3.10) The issue here is I am trying to use snowpark for which I need python 3.8 but because of this I am not able to proceed with next steps. Thanks Sumeet On Thu, 30 Mar 2023 at 22:45, Barry Scott wrote: > > > On 30 Mar 2023, at 15:17, Sumeet Firodia wrote: > > > Hi Team, > > I have installed Python 3.8 for Snowpark but when I check the version in > command prompt it shows me Python 3.10.10. > > C:\Users\admin>python --version > Python 3.10.10 > > > Try this: > > py -3.8 > > And this to list all version of python installed: > > py -0 > > > > Also when I try to uninstall 3.10 it says no such version is installed. > > C:\Users\admin>pip uninstall python 3.10.10 > WARNING: Skipping python as it is not installed. > WARNING: Skipping 3.10.10 as it is not installed. > > > PIP is for installing python modules not the python program. > The python program is installed by running the .exe that you get from > python.org, for example. > Use the standard Windows method to uninstall a program. > Search the web for "windows uninstall software" if you are not sure how to > do this. > > Barry > > > Can you please help me here as my snowpark assignment is stuck because of > this issue. > > Thanks > Sumeet > > > -- > https://mail.python.org/mailman/listinfo/python-list > > > From barry at barrys-emacs.org Fri Mar 31 04:48:55 2023 From: barry at barrys-emacs.org (Barry Scott) Date: Fri, 31 Mar 2023 09:48:55 +0100 Subject: Python not showing correct version In-Reply-To: References: Message-ID: > On 31 Mar 2023, at 09:33, Sumeet Firodia wrote: > > Thanks Barry. > > One more thing is that pip --version also refers to python 3.10 > > C:\Users\admin>pip --version > pip 23.0.1 from C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip (python 3.10) Use this command to ensure that pip matches the python you wish to use: py -3.8 -m pip --version Barry > > The issue here is I am trying to use snowpark for which I need python 3.8 but because of this I am not able to proceed with next steps. > > Thanks > Sumeet > > On Thu, 30 Mar 2023 at 22:45, Barry Scott > wrote: >> >> >>> On 30 Mar 2023, at 15:17, Sumeet Firodia > wrote: >>> >>>> >>>> Hi Team, >>>> >>>> I have installed Python 3.8 for Snowpark but when I check the version in >>>> command prompt it shows me Python 3.10.10. >>>> >>>> C:\Users\admin>python --version >>>> Python 3.10.10 >> >> Try this: >> >> py -3.8 >> >> And this to list all version of python installed: >> >> py -0 >> >> >>>> >>>> Also when I try to uninstall 3.10 it says no such version is installed. >>>> >>>> C:\Users\admin>pip uninstall python 3.10.10 >>>> WARNING: Skipping python as it is not installed. >>>> WARNING: Skipping 3.10.10 as it is not installed. >> >> PIP is for installing python modules not the python program. >> The python program is installed by running the .exe that you get from python.org , for example. >> Use the standard Windows method to uninstall a program. >> Search the web for "windows uninstall software" if you are not sure how to do this. >> >> Barry >> >>>> >>>> Can you please help me here as my snowpark assignment is stuck because of >>>> this issue. >>>> >>>> Thanks >>>> Sumeet >>>> >>>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list From jschwar at sbcglobal.net Fri Mar 31 08:00:03 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Fri, 31 Mar 2023 07:00:03 -0500 Subject: Windows installer from python source code without access to source code References: <01fd01d963c8$547e9090$fd7bb1b0$.ref@sbcglobal.net> Message-ID: <01fd01d963c8$547e9090$fd7bb1b0$@sbcglobal.net> I want a windows installer to install my application that's written in python, but I don't want the end user to have access to my source code. Is that possible using python? I was using cx-freeze, but that has the source code available. So does pyinstaller. I think gcc does, too. Does anyone know of a way to do this? From rosuav at gmail.com Fri Mar 31 08:08:39 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Mar 2023 23:08:39 +1100 Subject: Windows installer from python source code without access to source code In-Reply-To: <01fd01d963c8$547e9090$fd7bb1b0$@sbcglobal.net> References: <01fd01d963c8$547e9090$fd7bb1b0$.ref@sbcglobal.net> <01fd01d963c8$547e9090$fd7bb1b0$@sbcglobal.net> Message-ID: On Fri, 31 Mar 2023 at 23:01, Jim Schwartz wrote: > > I want a windows installer to install my application that's written in > python, but I don't want the end user to have access to my source code. > > > > Is that possible using python? I was using cx-freeze, but that has the > source code available. So does pyinstaller. I think gcc does, too. > > > > Does anyone know of a way to do this? > Fundamentally no, it's not. Python code will always be distributed as some form of bytecode. The only way to make it available without revealing anything is to put it on a server and let people access it without running it themselves. But why is that a problem? Copyright law protects you from people stealing your code and making unauthorized changes to it, and if you're not worried about them making changes, there's no reason to hide the source code (whatever you distribute would be just as copiable). Are you concerned that people will see your bugs? We all have them. ChrisA From ssfirodia at gmail.com Fri Mar 31 08:27:11 2023 From: ssfirodia at gmail.com (Sumeet Firodia) Date: Fri, 31 Mar 2023 17:57:11 +0530 Subject: Python not showing correct version In-Reply-To: References: Message-ID: Hi Barry, This is getting more complicated. As per the command you shared, below is the output C:\Users\admin>py -3.8 -m pip --version pip 19.2.3 from C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\site-packages\pip (python 3.8) For pip --version below is the output C:\Users\admin>pip --version pip 23.0.1 from C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip (python 3.10) Now if I want to upgrade the pip version it says requirement already met C:\Users\admin>python -m pip install --upgrade pip Requirement already satisfied: pip in c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (23.0.1) Please let me know how can I cleanup everything so that I dont see python 3.10.10 and can work with 3.8 Thanks Sumeet On Fri, 31 Mar 2023 at 14:21, Barry Scott wrote: > > > > On 31 Mar 2023, at 09:33, Sumeet Firodia wrote: > > > > Thanks Barry. > > > > One more thing is that pip --version also refers to python 3.10 > > > > C:\Users\admin>pip --version > > pip 23.0.1 from > C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip > (python 3.10) > > Use this command to ensure that pip matches the python you wish to use: > > py -3.8 -m pip --version > > Barry > > > > > The issue here is I am trying to use snowpark for which I need python > 3.8 but because of this I am not able to proceed with next steps. > > > > Thanks > > Sumeet > > > > On Thu, 30 Mar 2023 at 22:45, Barry Scott > wrote: > >> > >> > >>> On 30 Mar 2023, at 15:17, Sumeet Firodia ssfirodia at gmail.com>> wrote: > >>> > >>>> > >>>> Hi Team, > >>>> > >>>> I have installed Python 3.8 for Snowpark but when I check the version > in > >>>> command prompt it shows me Python 3.10.10. > >>>> > >>>> C:\Users\admin>python --version > >>>> Python 3.10.10 > >> > >> Try this: > >> > >> py -3.8 > >> > >> And this to list all version of python installed: > >> > >> py -0 > >> > >> > >>>> > >>>> Also when I try to uninstall 3.10 it says no such version is > installed. > >>>> > >>>> C:\Users\admin>pip uninstall python 3.10.10 > >>>> WARNING: Skipping python as it is not installed. > >>>> WARNING: Skipping 3.10.10 as it is not installed. > >> > >> PIP is for installing python modules not the python program. > >> The python program is installed by running the .exe that you get from > python.org , for example. > >> Use the standard Windows method to uninstall a program. > >> Search the web for "windows uninstall software" if you are not sure how > to do this. > >> > >> Barry > >> > >>>> > >>>> Can you please help me here as my snowpark assignment is stuck > because of > >>>> this issue. > >>>> > >>>> Thanks > >>>> Sumeet > >>>> > >>>> > >>> -- > >>> https://mail.python.org/mailman/listinfo/python-list > > -- > https://mail.python.org/mailman/listinfo/python-list > From list1 at tompassin.net Fri Mar 31 08:49:23 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 31 Mar 2023 08:49:23 -0400 Subject: Python not showing correct version In-Reply-To: References: Message-ID: <0601a6d3-9979-99df-29d1-ff120123fdd3@tompassin.net> On 3/31/2023 8:27 AM, Sumeet Firodia wrote: > Hi Barry, > > This is getting more complicated. > As per the command you shared, below is the output > > C:\Users\admin>py -3.8 -m pip --version > pip 19.2.3 from > C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\site-packages\pip > (python 3.8) > > For pip --version below is the output > > C:\Users\admin>pip --version > pip 23.0.1 from > C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip > (python 3.10) > > Now if I want to upgrade the pip version it says requirement already met > > C:\Users\admin>python -m pip install --upgrade pip > Requirement already satisfied: pip in > c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages > (23.0.1) > > Please let me know how can I cleanup everything so that I dont see python > 3.10.10 and can work with 3.8 > > Thanks > Sumeet > > On Fri, 31 Mar 2023 at 14:21, Barry Scott wrote: > >> >> >>> On 31 Mar 2023, at 09:33, Sumeet Firodia wrote: >>> >>> Thanks Barry. >>> >>> One more thing is that pip --version also refers to python 3.10 >>> >>> C:\Users\admin>pip --version >>> pip 23.0.1 from >> C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip >> (python 3.10) >> >> Use this command to ensure that pip matches the python you wish to use: >> >> py -3.8 -m pip --version >> >> Barry >> >>> >>> The issue here is I am trying to use snowpark for which I need python >> 3.8 but because of this I am not able to proceed with next steps. >>> >>> Thanks >>> Sumeet >>> >>> On Thu, 30 Mar 2023 at 22:45, Barry Scott > > wrote: >>>> >>>> >>>>> On 30 Mar 2023, at 15:17, Sumeet Firodia > ssfirodia at gmail.com>> wrote: >>>>> >>>>>> >>>>>> Hi Team, >>>>>> >>>>>> I have installed Python 3.8 for Snowpark but when I check the version >> in >>>>>> command prompt it shows me Python 3.10.10. >>>>>> >>>>>> C:\Users\admin>python --version >>>>>> Python 3.10.10 >>>> >>>> Try this: >>>> >>>> py -3.8 >>>> >>>> And this to list all version of python installed: >>>> >>>> py -0 >>>> >>>> >>>>>> >>>>>> Also when I try to uninstall 3.10 it says no such version is >> installed. >>>>>> >>>>>> C:\Users\admin>pip uninstall python 3.10.10 >>>>>> WARNING: Skipping python as it is not installed. >>>>>> WARNING: Skipping 3.10.10 as it is not installed. >>>> >>>> PIP is for installing python modules not the python program. >>>> The python program is installed by running the .exe that you get from >> python.org , for example. >>>> Use the standard Windows method to uninstall a program. >>>> Search the web for "windows uninstall software" if you are not sure how >> to do this. >>>> >>>> Barry >>>> >>>>>> >>>>>> Can you please help me here as my snowpark assignment is stuck >> because of >>>>>> this issue. We have been telling you to type "py -3.8" instead of typing "python". We have been telling you to type "py -3.8 -m pip" instead of "python -m pip". Now you complain that you did something else and got a wrong result. If you want to upgrade pip for Python 3.8, then follow the pattern and type "py -3.8 -m pip install --upgrade pip". Everywhere you would have typed "python" type "py -3.8" instead. From loris.bennett at fu-berlin.de Fri Mar 31 09:01:27 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Fri, 31 Mar 2023 15:01:27 +0200 Subject: When is logging.getLogger(__name__) needed? Message-ID: <877cux2hy0.fsf@hornfels.zedat.fu-berlin.de> Hi, In my top level program file, main.py, I have def main_function(): parser = argparse.ArgumentParser(description="my prog") ... args = parser.parse_args() config = configparser.ConfigParser() if args.config_file is None: config_file = DEFAULT_CONFIG_FILE else: config_file = args.config_file config.read(config_file) logging.config.fileConfig(fname=config_file) logger = logging.getLogger(__name__) do_some_stuff() my_class_instance = myprog.MyClass() def do_some_stuff(): logger.info("Doing stuff") This does not work, because 'logger' is not known in the function 'do_some_stuff'. However, if in 'my_prog/my_class.py' I have class MyClass: def __init__(self): logger.debug("created instance of MyClass") this 'just works'. I can add logger = logging.getLogger(__name__) to 'do_some_stuff', but why is this necessary in this case but not in the class? Or should I be doing this entirely differently? Cheers, Loris -- This signature is currently under constuction. From jkn_gg at nicorp.f9.co.uk Fri Mar 31 10:14:42 2023 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Fri, 31 Mar 2023 07:14:42 -0700 (PDT) Subject: Windows installer from python source code without access to source code In-Reply-To: References: <01fd01d963c8$547e9090$fd7bb1b0$.ref@sbcglobal.net> <01fd01d963c8$547e9090$fd7bb1b0$@sbcglobal.net> Message-ID: On Friday, March 31, 2023 at 1:09:12?PM UTC+1, Chris Angelico wrote: > On Fri, 31 Mar 2023 at 23:01, Jim Schwartz wrote: > > > > I want a windows installer to install my application that's written in > > python, but I don't want the end user to have access to my source code. > > > > > > > > Is that possible using python? I was using cx-freeze, but that has the > > source code available. So does pyinstaller. I think gcc does, too. > > > > > > > > Does anyone know of a way to do this? > > > Fundamentally no, it's not. Python code will always be distributed as > some form of bytecode. The only way to make it available without > revealing anything is to put it on a server and let people access it > without running it themselves. > > But why is that a problem? Copyright law protects you from people > stealing your code and making unauthorized changes to it, and if > you're not worried about them making changes, there's no reason to > hide the source code (whatever you distribute would be just as > copiable). Are you concerned that people will see your bugs? We all > have them. > > ChrisA The OP is asking for source code not to be available, not bytecode. There are obfuscating tools like PyArmor you might want to have a look at. From list1 at tompassin.net Fri Mar 31 10:53:16 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 31 Mar 2023 10:53:16 -0400 Subject: Windows installer from python source code without access to source code In-Reply-To: References: <01fd01d963c8$547e9090$fd7bb1b0$.ref@sbcglobal.net> <01fd01d963c8$547e9090$fd7bb1b0$@sbcglobal.net> Message-ID: On 3/31/2023 10:14 AM, jkn wrote: > On Friday, March 31, 2023 at 1:09:12?PM UTC+1, Chris Angelico wrote: >> On Fri, 31 Mar 2023 at 23:01, Jim Schwartz wrote: >>> >>> I want a windows installer to install my application that's written in >>> python, but I don't want the end user to have access to my source code. >>> >>> >>> >>> Is that possible using python? I was using cx-freeze, but that has the >>> source code available. So does pyinstaller. I think gcc does, too. >>> >>> >>> >>> Does anyone know of a way to do this? >>> >> Fundamentally no, it's not. Python code will always be distributed as >> some form of bytecode. The only way to make it available without >> revealing anything is to put it on a server and let people access it >> without running it themselves. >> >> But why is that a problem? Copyright law protects you from people >> stealing your code and making unauthorized changes to it, and if >> you're not worried about them making changes, there's no reason to >> hide the source code (whatever you distribute would be just as >> copiable). Are you concerned that people will see your bugs? We all >> have them. >> >> ChrisA > > The OP is asking for source code not to be available, not bytecode. > There are obfuscating tools like PyArmor you might want to have a look at. The byte code can be decompiled, though, so the attempt to hide the code won't be completely successful if someone wants to make the effort. The same is true, e.g., about Java. The class files don't include the source, but they can be decompiled. From __peter__ at web.de Fri Mar 31 11:34:31 2023 From: __peter__ at web.de (Peter Otten) Date: Fri, 31 Mar 2023 17:34:31 +0200 Subject: When is logging.getLogger(__name__) needed? In-Reply-To: <877cux2hy0.fsf@hornfels.zedat.fu-berlin.de> References: <877cux2hy0.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <3783122a-28d9-776d-b4d1-979cb1d3ac1d@web.de> On 31/03/2023 15:01, Loris Bennett wrote: > Hi, > > In my top level program file, main.py, I have > > def main_function(): > > parser = argparse.ArgumentParser(description="my prog") > > ... > > args = parser.parse_args() > config = configparser.ConfigParser() > > if args.config_file is None: > config_file = DEFAULT_CONFIG_FILE > else: > config_file = args.config_file > > config.read(config_file) > > logging.config.fileConfig(fname=config_file) > logger = logging.getLogger(__name__) > > do_some_stuff() > > my_class_instance = myprog.MyClass() > > def do_some_stuff(): > > logger.info("Doing stuff") > > This does not work, because 'logger' is not known in the function > 'do_some_stuff'. > > However, if in 'my_prog/my_class.py' I have > > class MyClass: > > def __init__(self): > > logger.debug("created instance of MyClass") > > this 'just works'. Take another look at your code -- you'll probably find > logger = logging.getLogger(__name__) on the module level in my_class.py. > to 'do_some_stuff', but why is this necessary in this case but not in > the class? Your problem has nothing to do with logging -- it's about visibility ("scope") of names: >>> def use_name(): print(name) >>> def define_name(): name = "Loris" >>> use_name() Traceback (most recent call last): File "", line 1, in use_name() File "", line 2, in use_name print(name) NameError: name 'name' is not defined Binding (=assigning to) a name inside a function makes it local to that function. If you want a global (module-level) name you have to say so: >>> def define_name(): global name name = "Peter" >>> define_name() >>> use_name() Peter From learn2program at gmail.com Fri Mar 31 12:31:40 2023 From: learn2program at gmail.com (Alan Gauld) Date: Fri, 31 Mar 2023 17:31:40 +0100 Subject: Windows installer from python source code without access to source code In-Reply-To: <01fd01d963c8$547e9090$fd7bb1b0$@sbcglobal.net> References: <01fd01d963c8$547e9090$fd7bb1b0$.ref@sbcglobal.net> <01fd01d963c8$547e9090$fd7bb1b0$@sbcglobal.net> Message-ID: On 31/03/2023 13:00, Jim Schwartz wrote: > I want a windows installer to install my application that's written in > python, but I don't want the end user to have access to my source code. Others have commented that at some level it will always be thre but on a more pragmatic level tools like py2exe bundle up a Python app as an exe file which might be all you need? I'm sure if a user dug deep enough they could still find the source (or something close) but to deter casual browsing it might be what you want. Caveat: I've never used py2exe in anger and my experiements were before Python3 so ive no idea what it does today! But a quick check suggests it still exists and works with python3 code - last major release was in Nov 2022. -- 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 eryksun at gmail.com Fri Mar 31 13:54:42 2023 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 31 Mar 2023 12:54:42 -0500 Subject: Windows installer from python source code without access to source code In-Reply-To: <01fd01d963c8$547e9090$fd7bb1b0$@sbcglobal.net> References: <01fd01d963c8$547e9090$fd7bb1b0$.ref@sbcglobal.net> <01fd01d963c8$547e9090$fd7bb1b0$@sbcglobal.net> Message-ID: On 3/31/23, Jim Schwartz wrote: > I want a windows installer to install my application that's written in > python, but I don't want the end user to have access to my source code. Cython can compile a script to C source code for a module or executable (--embed). The source can be compiled and linked normally. For example, the following builds a "hello.exe" executable based on a "hello.py" script. > cython -3 --embed hello.py > set "PYI=C:\Program Files\Python311\include" > set "PYL=C:\Program Files\Python311\libs" > cl /I"%PYI%" hello.c /link /libpath:"%PYL%" > copy hello.exe embed > embed\hello.exe Hello, World! I extracted the complete embeddable distribution of Python 3.11 into the "embed" directory. You can reduce the size of the installation, if needed, by minimizing the zipped standard library and removing pyd extensions and DLLs that your application doesn't use. The generated "hello.c" is large and not particularly easy to read, but here are some snippets [...]: [...] /* Implementation of 'hello' */ static PyObject *__pyx_builtin_print; static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_name[] = "__name__"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_print[] = "print"; static const char __pyx_k_Hello_World[] = "Hello, World!"; [...] /* "hello.py":1 * print("Hello, World!") # <<<<<<<<<<<<<< */ __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_Hello_World); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 1, __pyx_L1_error) [...] /* "hello.py":1 * print("Hello, World!") # <<<<<<<<<<<<<< */ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) [...] int wmain(int argc, wchar_t **argv) { [...] if (argc && argv) Py_SetProgramName(argv[0]); Py_Initialize(); if (argc && argv) PySys_SetArgv(argc, argv); [...] m = PyInit_hello(); [...] if (Py_FinalizeEx() < 0) return 2; [...] return 0; [...] From eryksun at gmail.com Fri Mar 31 14:18:17 2023 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 31 Mar 2023 13:18:17 -0500 Subject: Python not showing correct version In-Reply-To: References: Message-ID: On 3/31/23, Sumeet Firodia wrote: > > One more thing is that pip --version also refers to python 3.10 > > C:\Users\admin>pip --version > pip 23.0.1 from > C:\Users\admin\AppData\Local\Packages > \PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0 > \LocalCache\local-packages\Python310\site-packages\pip > (python 3.10) You're running pip from the store app distribution of Python 3.10. Your settings have the store app set as the default for the "python" and "pip" commands. To change this, open the system settings for "App execution aliases" and disable the "python.exe", "pythonw.exe", and "pip.exe" aliases. You might have to also disable the alias for "python3.exe" if it's causing problems (e.g. if you don't want a shebang like "#!/usr/bin/env python3" to run the store app). It shouldn't cause problems to leave the "python3.10.exe" and "pip3.10.exe" aliases enabled. From hjp-python at hjp.at Fri Mar 31 15:21:37 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 31 Mar 2023 21:21:37 +0200 Subject: built-in pow() vs. math.pow() In-Reply-To: References: Message-ID: <20230331192137.c5yh3bjtfzzde6wk@hjp.at> On 2023-03-31 07:39:25 +0100, Barry wrote: > On 30 Mar 2023, at 22:30, Chris Angelico wrote: > > It's called math.pow. That on its own should be a strong indication > > that it's designed to work with floats. > > So long as you know that the math module is provided to give access > the C math.h functions. > Well, that's the first line in the docs: | This module provides access to the mathematical functions defined by | the C standard. Of course a Python programmer may not necessarily know what mathematical functions the C standard defines or even what C is. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From list1 at tompassin.net Fri Mar 31 16:16:15 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 31 Mar 2023 16:16:15 -0400 Subject: Python not showing correct version In-Reply-To: References: Message-ID: <34dcfb4d-28ed-0d26-8816-826fd63c1848@tompassin.net> On 3/31/2023 2:18 PM, Eryk Sun wrote: > On 3/31/23, Sumeet Firodia wrote: >> >> One more thing is that pip --version also refers to python 3.10 >> >> C:\Users\admin>pip --version >> pip 23.0.1 from >> C:\Users\admin\AppData\Local\Packages >> \PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0 >> \LocalCache\local-packages\Python310\site-packages\pip >> (python 3.10) > > You're running pip from the store app distribution of Python 3.10. > Your settings have the store app set as the default for the "python" > and "pip" commands. To change this, open the system settings for "App > execution aliases" and disable the "python.exe", "pythonw.exe", and > "pip.exe" aliases. You might have to also disable the alias for > "python3.exe" if it's causing problems (e.g. if you don't want a > shebang like "#!/usr/bin/env python3" to run the store app). It > shouldn't cause problems to leave the "python3.10.exe" and > "pip3.10.exe" aliases enabled. Ha! The store app doesn't install py.exe, does it? I forgot about that as a possibility, because I've always stayed away from store apps. If it were me, I'd uninstall the store app and get an installer from python.org. From eryksun at gmail.com Fri Mar 31 17:02:35 2023 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 31 Mar 2023 16:02:35 -0500 Subject: Python not showing correct version In-Reply-To: <34dcfb4d-28ed-0d26-8816-826fd63c1848@tompassin.net> References: <34dcfb4d-28ed-0d26-8816-826fd63c1848@tompassin.net> Message-ID: On 3/31/23, Thomas Passin wrote: > > The store app doesn't install py.exe, does it? That's a significant downside of the store app. You can install Python 3.7-3.11 from the store, and run them explicitly as "python3.7.exe", "pip3.7.exe", "python3.11.exe", "pip3.11.exe", etc. But without the launcher there's no shebang support for scripts, so you can't easily associate a script with a particular Python version or a particular virtual environment. Shell shortcuts/links (.LNK files) can work around the lack of shebang support (add .LNK to the PATHEXT environment variable). But having to create a separate shell link is inconvenient, and it's not cross-platform. The OP installed the standard Python 3.8 distribution, which does install the launcher by default. The launcher can run all installed versions, including store app installations. By default it runs the highest available version, which will probably be the 3.10 store app in the OP's case. To make 3.8 the default without having to remove 3.10, set the environment variables "PY_PYTHON=3.8" and "PY_PYTHON3=3.8" in the user environment. From jschwar at sbcglobal.net Fri Mar 31 17:16:54 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Fri, 31 Mar 2023 16:16:54 -0500 Subject: Windows installer from python source code without access to source code In-Reply-To: References: <01fd01d963c8$547e9090$fd7bb1b0$.ref@sbcglobal.net> <01fd01d963c8$547e9090$fd7bb1b0$@sbcglobal.net> Message-ID: <025201d96416$1ee36f20$5caa4d60$@sbcglobal.net> What license do I have to choose so people can't use my code? I don't know this stuff. -----Original Message----- From: Python-list On Behalf Of Chris Angelico Sent: Friday, March 31, 2023 7:09 AM To: python-list at python.org Subject: Re: Windows installer from python source code without access to source code On Fri, 31 Mar 2023 at 23:01, Jim Schwartz wrote: > > I want a windows installer to install my application that's written in > python, but I don't want the end user to have access to my source code. > > > > Is that possible using python? I was using cx-freeze, but that has > the source code available. So does pyinstaller. I think gcc does, too. > > > > Does anyone know of a way to do this? > Fundamentally no, it's not. Python code will always be distributed as some form of bytecode. The only way to make it available without revealing anything is to put it on a server and let people access it without running it themselves. But why is that a problem? Copyright law protects you from people stealing your code and making unauthorized changes to it, and if you're not worried about them making changes, there's no reason to hide the source code (whatever you distribute would be just as copiable). Are you concerned that people will see your bugs? We all have them. ChrisA -- https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Fri Mar 31 18:01:24 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 31 Mar 2023 18:01:24 -0400 Subject: Windows installer from python source code without access to source code In-Reply-To: <025201d96416$1ee36f20$5caa4d60$@sbcglobal.net> References: <01fd01d963c8$547e9090$fd7bb1b0$.ref@sbcglobal.net> <01fd01d963c8$547e9090$fd7bb1b0$@sbcglobal.net> <025201d96416$1ee36f20$5caa4d60$@sbcglobal.net> Message-ID: <6b7e32a0-77a4-1d53-a7d3-0ca9887da30b@tompassin.net> On 3/31/2023 5:16 PM, Jim Schwartz wrote: > What license do I have to choose so people can't use my code? I don't know > this stuff. It would help if you would explain what you want to accomplish and why. Do you expect to make money off your software? If not, why do want so badly to protect it? The most basic answer is that your code is automatically protected by copyright law unless you say differently. But it is still a good idea to state outright what actions would be allowed and what would be forbidden. If you do expect to make money, you could look at what phone apps developers include with their apps. And it would be good to consult a lawyer who practices in this field. > -----Original Message----- > From: Python-list On > Behalf Of Chris Angelico > Sent: Friday, March 31, 2023 7:09 AM > To: python-list at python.org > Subject: Re: Windows installer from python source code without access to > source code > > On Fri, 31 Mar 2023 at 23:01, Jim Schwartz wrote: >> >> I want a windows installer to install my application that's written in >> python, but I don't want the end user to have access to my source code. >> >> >> >> Is that possible using python? I was using cx-freeze, but that has >> the source code available. So does pyinstaller. I think gcc does, too. >> >> >> >> Does anyone know of a way to do this? >> > > Fundamentally no, it's not. Python code will always be distributed as some > form of bytecode. The only way to make it available without revealing > anything is to put it on a server and let people access it without running > it themselves. > > But why is that a problem? Copyright law protects you from people stealing > your code and making unauthorized changes to it, and if you're not worried > about them making changes, there's no reason to hide the source code > (whatever you distribute would be just as copiable). Are you concerned that > people will see your bugs? We all have them. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From clint.olsen at gmail.com Fri Mar 31 16:34:14 2023 From: clint.olsen at gmail.com (Clint Olsen) Date: Fri, 31 Mar 2023 13:34:14 -0700 (PDT) Subject: Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError Message-ID: <3b8ed5cd-16f5-4205-a781-2c994e04f3e1n@googlegroups.com> I'm having some issues with task cancellation inside a signal handler. My tasks do get cancelled, but I see odd behavior: Traceback (most recent call last): File "/home/utils/release/sw/tools/python-3.9.7/lib/python3.9/site-packages/grpc/aio/_call.py", line 406, in _consume_request_iterator async for request in request_iterator: File "/home/foo/lib/python/rush/client.py", line 105, in send_status status = await sendq.get() File "/home/utils/Python/3.9/3.9.7-20211101/lib/python3.9/asyncio/queues.py", line 166, in get await getter asyncio.exceptions.CancelledError: Client killed with signal 2 Attempting to catch asyncio.CancelledError or asyncio.CancelledError does not work. The function in question looks like: 101 async def send_status(): 102 while True: 103 logging.info('Waiting for sendq') 104 try: 105 status = await sendq.get() 106 107 if not status: 108 break 109 110 logging.info(f'Sendq status {status}') 111 112 message = rush_pb2.Status(**status) 113 yield message 114 except asyncio.exceptions.CancelledError as err: 115 logging.error(f'Weird error {err}') 116 #raise asyncio.CancelledError 117 break If I use "except:" it does catch this exception. What's going on here? Thanks, -Clint From PythonList at DancesWithMice.info Fri Mar 31 18:20:26 2023 From: PythonList at DancesWithMice.info (dn) Date: Sat, 1 Apr 2023 11:20:26 +1300 Subject: When is logging.getLogger(__name__) needed? In-Reply-To: <877cux2hy0.fsf@hornfels.zedat.fu-berlin.de> References: <877cux2hy0.fsf@hornfels.zedat.fu-berlin.de> Message-ID: On 01/04/2023 02.01, Loris Bennett wrote: > Hi, > > In my top level program file, main.py, I have > > def main_function(): > > parser = argparse.ArgumentParser(description="my prog") > > ... > > args = parser.parse_args() > config = configparser.ConfigParser() > > if args.config_file is None: > config_file = DEFAULT_CONFIG_FILE > else: > config_file = args.config_file > > config.read(config_file) > > logging.config.fileConfig(fname=config_file) > logger = logging.getLogger(__name__) > > do_some_stuff() > > my_class_instance = myprog.MyClass() > > def do_some_stuff(): > > logger.info("Doing stuff") > > This does not work, because 'logger' is not known in the function > 'do_some_stuff'. > > However, if in 'my_prog/my_class.py' I have > > class MyClass: > > def __init__(self): > > logger.debug("created instance of MyClass") > > this 'just works'. > > I can add > > logger = logging.getLogger(__name__) > > to 'do_some_stuff', but why is this necessary in this case but not in > the class? > > Or should I be doing this entirely differently? Yes: differently. To complement @Peter's response, two items for consideration: 1 once main_function() has completed, have it return logger and other such values/constructs. The target-identifiers on the LHS of the function-call will thus be within the global scope. 2 if the purposes of main_function() are condensed-down to a few (English, or ..., language) phrases, the word "and" will feature, eg - configure env according to cmdLN args, - establish log(s), - do_some_stuff(), ** AND ** - instantiate MyClass. If these (and do_some_stuff(), like MyClass' methods) were split into separate functions* might you find it easier to see them as separate sub-solutions? Each sub-solution would be able to contribute to the whole - the earlier ones as creating (outputting) a description, constraint, or basis; which becomes input to a later function/method. * there is some debate amongst developers about whether "one function, one purpose" should be a rule, a convention, or tossed in the trash. YMMV! Personal view: SOLID's "Single" principle applies: there should be only one reason (hanging over the head of each method/function, like the Sword of Damocles) for it to change - or one 'user' who could demand a change to that function. In other words, an updated cmdLN option shouldn't affect a function which establishes logging, for example. Web.Refs: https://people.engr.tamu.edu/choe/choe/courses/20fall/315/lectures/slide23-solid.pdf https://www.hanselminutes.com/145/solid-principles-with-uncle-bob-robert-c-martin https://idioms.thefreedictionary.com/sword+of+Damocles https://en.wikipedia.org/wiki/Damocles -- Regards, =dn From PythonList at DancesWithMice.info Fri Mar 31 18:20:26 2023 From: PythonList at DancesWithMice.info (dn) Date: Sat, 1 Apr 2023 11:20:26 +1300 Subject: When is logging.getLogger(__name__) needed? In-Reply-To: <877cux2hy0.fsf@hornfels.zedat.fu-berlin.de> References: <877cux2hy0.fsf@hornfels.zedat.fu-berlin.de> Message-ID: On 01/04/2023 02.01, Loris Bennett wrote: > Hi, > > In my top level program file, main.py, I have > > def main_function(): > > parser = argparse.ArgumentParser(description="my prog") > > ... > > args = parser.parse_args() > config = configparser.ConfigParser() > > if args.config_file is None: > config_file = DEFAULT_CONFIG_FILE > else: > config_file = args.config_file > > config.read(config_file) > > logging.config.fileConfig(fname=config_file) > logger = logging.getLogger(__name__) > > do_some_stuff() > > my_class_instance = myprog.MyClass() > > def do_some_stuff(): > > logger.info("Doing stuff") > > This does not work, because 'logger' is not known in the function > 'do_some_stuff'. > > However, if in 'my_prog/my_class.py' I have > > class MyClass: > > def __init__(self): > > logger.debug("created instance of MyClass") > > this 'just works'. > > I can add > > logger = logging.getLogger(__name__) > > to 'do_some_stuff', but why is this necessary in this case but not in > the class? > > Or should I be doing this entirely differently? Yes: differently. To complement @Peter's response, two items for consideration: 1 once main_function() has completed, have it return logger and other such values/constructs. The target-identifiers on the LHS of the function-call will thus be within the global scope. 2 if the purposes of main_function() are condensed-down to a few (English, or ..., language) phrases, the word "and" will feature, eg - configure env according to cmdLN args, - establish log(s), - do_some_stuff(), ** AND ** - instantiate MyClass. If these (and do_some_stuff(), like MyClass' methods) were split into separate functions* might you find it easier to see them as separate sub-solutions? Each sub-solution would be able to contribute to the whole - the earlier ones as creating (outputting) a description, constraint, or basis; which becomes input to a later function/method. * there is some debate amongst developers about whether "one function, one purpose" should be a rule, a convention, or tossed in the trash. YMMV! Personal view: SOLID's "Single" principle applies: there should be only one reason (hanging over the head of each method/function, like the Sword of Damocles) for it to change - or one 'user' who could demand a change to that function. In other words, an updated cmdLN option shouldn't affect a function which establishes logging, for example. Web.Refs: https://people.engr.tamu.edu/choe/choe/courses/20fall/315/lectures/slide23-solid.pdf https://www.hanselminutes.com/145/solid-principles-with-uncle-bob-robert-c-martin https://idioms.thefreedictionary.com/sword+of+Damocles https://en.wikipedia.org/wiki/Damocles -- Regards, =dn From rosuav at gmail.com Fri Mar 31 18:22:52 2023 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Apr 2023 09:22:52 +1100 Subject: Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError In-Reply-To: <3b8ed5cd-16f5-4205-a781-2c994e04f3e1n@googlegroups.com> References: <3b8ed5cd-16f5-4205-a781-2c994e04f3e1n@googlegroups.com> Message-ID: On Sat, 1 Apr 2023 at 09:19, Clint Olsen wrote: > > I'm having some issues with task cancellation inside a signal handler. My tasks do get cancelled, but I see odd behavior: > > Traceback (most recent call last): > File "/home/utils/release/sw/tools/python-3.9.7/lib/python3.9/site-packages/grpc/aio/_call.py", line 406, in _consume_request_iterator > async for request in request_iterator: > File "/home/foo/lib/python/rush/client.py", line 105, in send_status > status = await sendq.get() > File "/home/utils/Python/3.9/3.9.7-20211101/lib/python3.9/asyncio/queues.py", line 166, in get > await getter > asyncio.exceptions.CancelledError: Client killed with signal 2 > > Attempting to catch asyncio.CancelledError or asyncio.CancelledError does not work. The function in question looks like: > > 101 async def send_status(): > 102 while True: > 103 logging.info('Waiting for sendq') > 104 try: > 105 status = await sendq.get() > 106 > 107 if not status: > 108 break > 109 > 110 logging.info(f'Sendq status {status}') > 111 > 112 message = rush_pb2.Status(**status) > 113 yield message > 114 except asyncio.exceptions.CancelledError as err: > 115 logging.error(f'Weird error {err}') > 116 #raise asyncio.CancelledError > 117 break > > If I use "except:" it does catch this exception. > > What's going on here? > >>> asyncio.exceptions.CancelledError is asyncio.CancelledError True Does that answer the question? ChrisA From clint.olsen at gmail.com Fri Mar 31 18:54:55 2023 From: clint.olsen at gmail.com (Clint Olsen) Date: Fri, 31 Mar 2023 15:54:55 -0700 (PDT) Subject: Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError In-Reply-To: References: <3b8ed5cd-16f5-4205-a781-2c994e04f3e1n@googlegroups.com> Message-ID: On Friday, March 31, 2023 at 3:23:24?PM UTC-7, Chris Angelico wrote: > On Sat, 1 Apr 2023 at 09:19, Clint Olsen wrote: > > Attempting to catch asyncio.CancelledError or asyncio.CancelledError does not work. The function in question looks like: > >>> asyncio.exceptions.CancelledError is asyncio.CancelledError > True > > Does that answer the question? No, I couldn't catch either exception even though they are the same. -Clint From rosuav at gmail.com Fri Mar 31 19:14:18 2023 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Apr 2023 10:14:18 +1100 Subject: Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError In-Reply-To: References: <3b8ed5cd-16f5-4205-a781-2c994e04f3e1n@googlegroups.com> Message-ID: On Sat, 1 Apr 2023 at 10:05, Clint Olsen wrote: > > On Friday, March 31, 2023 at 3:23:24?PM UTC-7, Chris Angelico wrote: > > On Sat, 1 Apr 2023 at 09:19, Clint Olsen wrote: > > > Attempting to catch asyncio.CancelledError or asyncio.CancelledError does not work. The function in question looks like: > > >>> asyncio.exceptions.CancelledError is asyncio.CancelledError > > True > > > > Does that answer the question? > > No, I couldn't catch either exception even though they are the same. > Okay, so that deals with the part from the subject line, leaving a slightly different problem: The caught exception is not of the same type as you were expecting. First question: Can you reproduce the issue on command? If so, I would recommend trying this: except BaseException as e: print("Got an exception!", type(e)) print(id(type(e))) print(id(asyncio.CancelledError) except: print("Weird things are happening") import sys print(sys.exc_info()) print(id(sys.exc_info()[0])) print(id(asyncio.CancelledError)) Basically, I want to know whether (a) BaseException has changed, which would be a nightmare; and (b) whether asyncio.CancelledError has changed. This is the kind of bizarre behaviour that can happen if a module is reloaded, or if there are multiple versions loaded for some reason. But if that ISN'T what's happening, there'll have to be some other explanation. ChrisA From jschwar at sbcglobal.net Fri Mar 31 19:32:18 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Fri, 31 Mar 2023 18:32:18 -0500 Subject: Windows installer from python source code without access to source code In-Reply-To: <6b7e32a0-77a4-1d53-a7d3-0ca9887da30b@tompassin.net> References: <6b7e32a0-77a4-1d53-a7d3-0ca9887da30b@tompassin.net> Message-ID: Yea. You?re right. I probably need a lawyer someday. Thanks. Sent from my iPhone > On Mar 31, 2023, at 5:12 PM, Thomas Passin wrote: > > ?On 3/31/2023 5:16 PM, Jim Schwartz wrote: >> What license do I have to choose so people can't use my code? I don't know >> this stuff. > > It would help if you would explain what you want to accomplish and why. Do you expect to make money off your software? If not, why do want so badly to protect it? > > The most basic answer is that your code is automatically protected by copyright law unless you say differently. But it is still a good idea to state outright what actions would be allowed and what would be forbidden. > > If you do expect to make money, you could look at what phone apps developers include with their apps. And it would be good to consult a lawyer who practices in this field. > > >> -----Original Message----- >> From: Python-list On >> Behalf Of Chris Angelico >> Sent: Friday, March 31, 2023 7:09 AM >> To: python-list at python.org >> Subject: Re: Windows installer from python source code without access to >> source code >>> On Fri, 31 Mar 2023 at 23:01, Jim Schwartz wrote: >>> >>> I want a windows installer to install my application that's written in >>> python, but I don't want the end user to have access to my source code. >>> >>> >>> >>> Is that possible using python? I was using cx-freeze, but that has >>> the source code available. So does pyinstaller. I think gcc does, too. >>> >>> >>> >>> Does anyone know of a way to do this? >>> >> Fundamentally no, it's not. Python code will always be distributed as some >> form of bytecode. The only way to make it available without revealing >> anything is to put it on a server and let people access it without running >> it themselves. >> But why is that a problem? Copyright law protects you from people stealing >> your code and making unauthorized changes to it, and if you're not worried >> about them making changes, there's no reason to hide the source code >> (whatever you distribute would be just as copiable). Are you concerned that >> people will see your bugs? We all have them. >> ChrisA >> -- >> https://mail.python.org/mailman/listinfo/python-list > > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Fri Mar 31 19:49:18 2023 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Apr 2023 10:49:18 +1100 Subject: Windows installer from python source code without access to source code In-Reply-To: References: <6b7e32a0-77a4-1d53-a7d3-0ca9887da30b@tompassin.net> Message-ID: On Sat, 1 Apr 2023 at 10:34, Jim Schwartz wrote: > > Yea. You?re right. I probably need a lawyer someday. Thanks. > If your needs are basic, you shouldn't need a lawyer. Copyright law and treaties DO protect you. But it's important to be aware that no amount of legal protection - whether you hire a lawyer or not, and whether you identify copyright and license or not - will stop people from copying your code. NOTHING will stop people from copying your code if they have access to it. All you can do is discourage them. So that brings us back to the original question: Why protect your *source code* specifically? There are two extremes available to everyone: 1) Distribute the source code. Let everyone see it. Stick a license on it that permits them to use it, modify it, distribute modified versions. Set your code free and let it be used. 2) Don't distribute the program *at all*. Don't distribute the source OR the binary. Instead, permit people to *access* the program - which, in today's world, usually means a web service. Both of these are very popular and work well. I don't have access to the Gmail source code but I'm using the service. I don't have access to the Twitch.tv source code but I'm using the service. Meanwhile, I have Python programs running on a Debian system using the Linux kernel, invoked using bash, served from an ext4 mass storage device, etc, etc. I have the binary code for all of these, and I'm legally guaranteed access to the source if I want it, so there's no incentive to steal it. The middle ground of "distribute binaries but stop people from accessing the source" is a much narrower use-case, and I would say that it's not actually a single use-case but a family of them, each with different needs and requirements. So it's essential to know what you're actually trying to protect, and why. ChrisA From clint.olsen at gmail.com Fri Mar 31 20:22:06 2023 From: clint.olsen at gmail.com (Clint Olsen) Date: Fri, 31 Mar 2023 17:22:06 -0700 (PDT) Subject: Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError In-Reply-To: References: <3b8ed5cd-16f5-4205-a781-2c994e04f3e1n@googlegroups.com> Message-ID: <34d0fff9-816e-4cad-89df-ca681edef86fn@googlegroups.com> On Friday, March 31, 2023 at 4:14:51?PM UTC-7, Chris Angelico wrote: > Okay, so that deals with the part from the subject line, leaving a > slightly different problem: The caught exception is not of the same > type as you were expecting. First question: Can you reproduce the > issue on command? If so, I would recommend trying this: > > except BaseException as e: > print("Got an exception!", type(e)) > print(id(type(e))) > print(id(asyncio.CancelledError) > except: > print("Weird things are happening") > import sys > print(sys.exc_info()) > print(id(sys.exc_info()[0])) > print(id(asyncio.CancelledError)) > > Basically, I want to know whether (a) BaseException has changed, which > would be a nightmare; and (b) whether asyncio.CancelledError has > changed. > > This is the kind of bizarre behaviour that can happen if a module is > reloaded, or if there are multiple versions loaded for some reason. > But if that ISN'T what's happening, there'll have to be some other > explanation. Here's what I see: Got an exception! 8204064 8204064 Thanks, -Clint From oscar.j.benjamin at gmail.com Fri Mar 31 20:50:54 2023 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 1 Apr 2023 01:50:54 +0100 Subject: built-in pow() vs. math.pow() In-Reply-To: <20230331192137.c5yh3bjtfzzde6wk@hjp.at> References: <20230331192137.c5yh3bjtfzzde6wk@hjp.at> Message-ID: On Fri, 31 Mar 2023 at 20:24, Peter J. Holzer wrote: > > On 2023-03-31 07:39:25 +0100, Barry wrote: > > On 30 Mar 2023, at 22:30, Chris Angelico wrote: > > > It's called math.pow. That on its own should be a strong indication > > > that it's designed to work with floats. > > > > So long as you know that the math module is provided to give access > > the C math.h functions. > > > > Well, that's the first line in the docs: > > | This module provides access to the mathematical functions defined by > | the C standard. > > Of course a Python programmer may not necessarily know what mathematical > functions the C standard defines or even what C is. Or they might know that and might also realise that it is not really an accurate description of Python's math module e.g. math.factorial, math.gcd, math.isqrt which are all integer functions. How many of these 60 names are defined by the C standard: In [6]: dir(math) Out[6]: ['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc'] -- Oscar From rosuav at gmail.com Fri Mar 31 20:51:02 2023 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Apr 2023 11:51:02 +1100 Subject: Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError In-Reply-To: <34d0fff9-816e-4cad-89df-ca681edef86fn@googlegroups.com> References: <3b8ed5cd-16f5-4205-a781-2c994e04f3e1n@googlegroups.com> <34d0fff9-816e-4cad-89df-ca681edef86fn@googlegroups.com> Message-ID: On Sat, 1 Apr 2023 at 11:42, Clint Olsen wrote: > > On Friday, March 31, 2023 at 4:14:51?PM UTC-7, Chris Angelico wrote: > > Okay, so that deals with the part from the subject line, leaving a > > slightly different problem: The caught exception is not of the same > > type as you were expecting. First question: Can you reproduce the > > issue on command? If so, I would recommend trying this: > > > > except BaseException as e: > > print("Got an exception!", type(e)) > > print(id(type(e))) > > print(id(asyncio.CancelledError) > > except: > > print("Weird things are happening") > > import sys > > print(sys.exc_info()) > > print(id(sys.exc_info()[0])) > > print(id(asyncio.CancelledError)) > > > > Basically, I want to know whether (a) BaseException has changed, which > > would be a nightmare; and (b) whether asyncio.CancelledError has > > changed. > > > > This is the kind of bizarre behaviour that can happen if a module is > > reloaded, or if there are multiple versions loaded for some reason. > > But if that ISN'T what's happening, there'll have to be some other > > explanation. > > Here's what I see: > > Got an exception! > 8204064 > 8204064 > Can you confirm that it is indeed failing to catch the exception? Try this: except asyncio.CancelledError: print("Cancelled correctly") followed by the same type checking from above. Since the ID is the same, I would expect it to match! Can you post a full runnable example that exhibits the problem? ChrisA From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Mar 31 22:14:34 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Fri, 31 Mar 2023 22:14:34 -0400 Subject: Windows installer from python source code without access to source code In-Reply-To: References: <6b7e32a0-77a4-1d53-a7d3-0ca9887da30b@tompassin.net> Message-ID: On 2023-04-01 at 10:49:18 +1100, Chris Angelico wrote: > [...] I don't have access to the Gmail source code but I'm using the > service [...] You have access to Gmail's front end source code. Your web browser runs it every time you use the service (and probably while you aren't using the service, too). My educated guess is that Google expended some effort to hinder you from looking at and/or analyzing (or do you say analysing?) that code, and that their lawyers will come knocking at your metaphorical door if they so much as think you are using that code in some way other than running it inside your web browser. If only this situation were a cruel April Fool's Day joke. You don't have access to Gmail's back end source code. Many/Most web apps follow this pattern to varying degrees. I do not know whether this setup meets the OP's requirements. From clint.olsen at gmail.com Fri Mar 31 22:40:50 2023 From: clint.olsen at gmail.com (Clint Olsen) Date: Fri, 31 Mar 2023 19:40:50 -0700 (PDT) Subject: Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError In-Reply-To: References: <3b8ed5cd-16f5-4205-a781-2c994e04f3e1n@googlegroups.com> <34d0fff9-816e-4cad-89df-ca681edef86fn@googlegroups.com> Message-ID: On Friday, March 31, 2023 at 5:51:33?PM UTC-7, Chris Angelico wrote: > Can you confirm that it is indeed failing to catch the exception? Try this: > > except asyncio.CancelledError: > print("Cancelled correctly") > > followed by the same type checking from above. Since the ID is the > same, I would expect it to match! Well, now this works, so it's difficult to say how that was happening. If I can reproduce it I'll update this conversation. Thanks for the help! -Clint