RE: How to escape strings for re.finditer?

2023-02-28 Thread avi.e.gross
Peter, Nobody here would appreciate it if I tested it by sending out multiple copies of each email to see if the same message wraps differently. I am using a fairly standard mailer in Outlook that interfaces with gmail and I could try mailing directly from gmail but apparently there are systemic

Re: Is there a more efficient threading lock?

2023-02-28 Thread Chris Angelico
On Wed, 1 Mar 2023 at 10:04, Barry wrote: > > > Though it's still probably not as useful as you might hope. In C, if I > > can do "int id = counter++;" atomically, it would guarantee me a new > > ID that no other thread could ever have. > > C does not have to do that atomically. In fact it is

Re: How to escape strings for re.finditer?

2023-02-28 Thread Weatherby,Gerard
Regex is fine if it works for you. The critiques – “difficult to read” –are subjective. Unless the code is in a section that has been profiled to be a bottleneck, I don’t sweat performance at this level. For me, using code that has already been written and vetted is the preferred approach to

Re: How to escape strings for re.finditer?

2023-02-28 Thread Peter J. Holzer
On 2023-03-01 01:01:42 +0100, Peter J. Holzer wrote: > On 2023-02-28 15:25:05 -0500, avi.e.gr...@gmail.com wrote: > > It happens to be easy for me to fix but I sometimes see garbled code I > > then simply ignore. > > Truth to be told, that's one reason why I rarely read your mails to the > end.

Cryptic software announcements (was: ANN: DIPY 1.6.0)

2023-02-28 Thread Peter J. Holzer
[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

Re: How to escape strings for re.finditer?

2023-02-28 Thread Peter J. Holzer
On 2023-02-28 15:25:05 -0500, avi.e.gr...@gmail.com wrote: > Jen, > > > > 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

Re: Is there a more efficient threading lock?

2023-02-28 Thread Barry
> Though it's still probably not as useful as you might hope. In C, if I > can do "int id = counter++;" atomically, it would guarantee me a new > ID that no other thread could ever have. C does not have to do that atomically. In fact it is free to use lots of instructions to build the int value.

Re: How to escape strings for re.finditer?

2023-02-28 Thread Cameron Simpson
On 28Feb2023 18:57, Jen Kris wrote: One question:  several people have made suggestions other than regex (not your terser example with regex you shown below).  Is there a reason why regex is not preferred to, for example, a list comp?  These are different things; I'm not sure a comparison

Re: Python 3.10 Fizzbuzz

2023-02-28 Thread Oscar Benjamin
On Tue, 28 Feb 2023 at 20:55, Mats Wichmann wrote: > > On 2/27/23 16:42, Oscar Benjamin wrote: > > On Mon, 27 Feb 2023 at 21:06, Ethan Furman wrote: > >> > >> On 2/27/23 12:20, rbowman wrote: > >> > >> > "By using Black, you agree to cede control over minutiae of hand- > >> > formatting. In

Re: How to escape strings for re.finditer?

2023-02-28 Thread Thomas Passin
On 2/28/2023 2:40 PM, David Raymond wrote: With a slight tweak to the simple loop code using .find() it becomes a third faster than the RE version though. def using_simple_loop2(key, text): matches = [] keyLen = len(key) start = 0 while (foundSpot := text.find(key, start))

RE: Re: Python 3.10 Fizzbuzz

2023-02-28 Thread avi.e.gross
Karsten, Would it be OK if we paused this discussion a day till February is History? Sarcasm aside, I repeat, the word black has many unrelated meanings as presumably this case includes. And for those who do not keep close track of the local US nonsense, February has for some reason been

RE: How to escape strings for re.finditer?

2023-02-28 Thread avi.e.gross
David, Your results suggest we need to be reminded that lots depends on other factors. There are multiple versions/implementations of python out there including some written in C but also other underpinnings. Each can often have sections of pure python code replaced carefully with libraries of

RE: Python 3.10 Fizzbuzz

2023-02-28 Thread avi.e.gross
Dave, 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

Re: Python 3.10 Fizzbuzz

2023-02-28 Thread Mats Wichmann
On 2/27/23 16:42, Oscar Benjamin wrote: On Mon, 27 Feb 2023 at 21:06, Ethan Furman wrote: On 2/27/23 12:20, rbowman wrote: > "By using Black, you agree to cede control over minutiae of hand- > formatting. In return, Black gives you speed, determinism, and freedom > from pycodestyle

RE: How to escape strings for re.finditer?

2023-02-28 Thread avi.e.gross
This message is more for Thomas than Jen, You made me think of what happens in fairly large cases. What happens if I ask you to search a thousand pages looking for your name? One solution might be to break the problem into parts that can be run in independent threads or processes and perhaps

RE: How to escape strings for re.finditer?

2023-02-28 Thread avi.e.gross
Jen, 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. It happens to be easy for me to fix but I sometimes see garbled code

Aw: Re: Python 3.10 Fizzbuzz

2023-02-28 Thread Karsten Hilbert
> > I've never tried Black or any other code formatter, but I'm sure we > > wouldn't get on. > > Does this suggest, that because Black doesn't respect other people's > opinions and feelings, that it wouldn't meet the PSF's Code of Conduct? That much depends on The Measure Of A Man. Karsten --

RE: How to escape strings for re.finditer?

2023-02-28 Thread David Raymond
> I wrote my previous message before reading this.  Thank you for the test you > ran -- it answers the question of performance.  You show that re.finditer is > 30x faster, so that certainly recommends that over a simple loop, which > introduces looping overhead.  >>     def

Re: Python 3.10 Fizzbuzz

2023-02-28 Thread Chris Angelico
On Wed, 1 Mar 2023 at 06:25, dn via Python-list wrote: > > On 28/02/2023 12.55, Rob Cliffe via Python-list wrote: > > > > > > On 27/02/2023 21:04, Ethan Furman wrote: > >> On 2/27/23 12:20, rbowman wrote: > >> > >> > "By using Black, you agree to cede control over minutiae of hand- > >> >

Re: Python 3.10 Fizzbuzz

2023-02-28 Thread dn via Python-list
On 28/02/2023 12.55, Rob Cliffe via Python-list wrote: On 27/02/2023 21:04, Ethan Furman wrote: On 2/27/23 12:20, rbowman wrote: > "By using Black, you agree to cede control over minutiae of hand- > formatting. In return, Black gives you speed, determinism, and freedom > from pycodestyle

Re: How to escape strings for re.finditer?

2023-02-28 Thread Thomas Passin
On 2/28/2023 11:48 AM, Jon Ribbens via Python-list wrote: On 2023-02-28, Thomas Passin wrote: ... It is interesting, though, how pre-processing the search pattern can improve search times if you can afford the pre-processing. Here's a paper on rapidly finding matches when there may be up to

ANN: DIPY 1.6.0

2023-02-28 Thread Eleftherios Garyfallidis
Hello all, We are excited to announce a new release of DIPY: DIPY 1.6.0 is out from the oven! 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

Re: How to escape strings for re.finditer?

2023-02-28 Thread Thomas Passin
On 2/28/2023 12:57 PM, Jen Kris via Python-list wrote: The code I sent is correct, and it runs here.  Maybe you received it with a carriage return removed, but on my copy after posting, it is correct: example = 'X - abc_degree + 1 + qq + abc_degree + 1'  find_string = re.escape('abc_degree +

RE: How to escape strings for re.finditer?

2023-02-28 Thread avi.e.gross
Roel, You make some good points. One to consider is that when you ask a regular expression matcher to search using something that uses NO regular expression features, much of the complexity disappears and what it creates is probably similar enough to what you get with a string search except

Re: How to escape strings for re.finditer?

2023-02-28 Thread Thomas Passin
On 2/28/2023 1:07 PM, Jen Kris wrote: Using str.startswith is a cool idea in this case.  But is it better than regex for performance or reliability?  Regex syntax is not a model of simplicity, but in my simple case it's not too difficult. The trouble is that we don't know what your case

Re: How to escape strings for re.finditer?

2023-02-28 Thread Jon Ribbens via Python-list
On 2023-02-28, Thomas Passin wrote: > On 2/28/2023 10:05 AM, Roel Schroeven wrote: >> Op 28/02/2023 om 14:35 schreef Thomas Passin: >>> On 2/28/2023 4:33 AM, Roel Schroeven wrote: [...] (2) Searching for a string in another string, in a performant way, is not as simple as it first

Re: How to escape strings for re.finditer?

2023-02-28 Thread Jen Kris via Python-list
I wrote my previous message before reading this.  Thank you for the test you ran -- it answers the question of performance.  You show that re.finditer is 30x faster, so that certainly recommends that over a simple loop, which introduces looping overhead.  Feb 28, 2023, 05:44 by

Re: How to escape strings for re.finditer?

2023-02-28 Thread Jen Kris via Python-list
Using str.startswith is a cool idea in this case.  But is it better than regex for performance or reliability?  Regex syntax is not a model of simplicity, but in my simple case it's not too difficult.  Feb 27, 2023, 18:52 by li...@tompassin.net: > On 2/27/2023 9:16 PM, avi.e.gr...@gmail.com

RE: How to escape strings for re.finditer?

2023-02-28 Thread Jen Kris via Python-list
The code I sent is correct, and it runs here.  Maybe you received it with a carriage return removed, but on my copy after posting, it is correct: example = 'X - abc_degree + 1 + qq + abc_degree + 1'  find_string = re.escape('abc_degree + 1')  for match in re.finditer(find_string, example):

Re: How to escape strings for re.finditer?

2023-02-28 Thread Thomas Passin
On 2/28/2023 10:05 AM, Roel Schroeven wrote: Op 28/02/2023 om 14:35 schreef Thomas Passin: On 2/28/2023 4:33 AM, Roel Schroeven wrote: [...] (2) Searching for a string in another string, in a performant way, is not as simple as it first appears. Your version works correctly, but slowly. In

Re: How to escape strings for re.finditer?

2023-02-28 Thread Roel Schroeven
Op 28/02/2023 om 14:35 schreef Thomas Passin: On 2/28/2023 4:33 AM, Roel Schroeven wrote: [...] (2) Searching for a string in another string, in a performant way, is not as simple as it first appears. Your version works correctly, but slowly. In some situations it doesn't matter, but in other

Re: How to escape strings for re.finditer?

2023-02-28 Thread Thomas Passin
On 2/28/2023 4:33 AM, Roel Schroeven wrote: Op 28/02/2023 om 3:44 schreef Thomas Passin: On 2/27/2023 9:16 PM, avi.e.gr...@gmail.com wrote: And, just for fun, since there is nothing wrong with your code, this minor change is terser: example = 'X - abc_degree + 1 + qq + abc_degree + 1' for

Re: How to escape strings for re.finditer?

2023-02-28 Thread Roel Schroeven
Op 28/02/2023 om 3:44 schreef Thomas Passin: On 2/27/2023 9:16 PM, avi.e.gr...@gmail.com wrote: And, just for fun, since there is nothing wrong with your code, this minor change is terser: example = 'X - abc_degree + 1 + qq + abc_degree + 1' for match in re.finditer(re.escape('abc_degree +