Re: one Liner: Lisprint(x) --> (a, b, c) instead of ['a', 'b', 'c']

2023-02-27 Thread Greg Ewing via Python-list
On 28/02/23 4:24 pm, Hen Hanna wrote: is it poss. to peek at the Python-list's messages without joining ? It's mirrored to the comp.lang.python usenet group, or you can read it through gmane with a news client. -- Greg --

RE: How to escape strings for re.finditer?

2023-02-27 Thread avi.e.gross
I think by now we have given all that is needed by the OP but Dave's answer strikes me as being able to be a tad faster as a while loop if you are searching larger corpus such as an entire ebook or all books as you can do on books.google.com I think I mentioned earlier that some assumptions need

Re: How to escape strings for re.finditer?

2023-02-27 Thread 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 + 1') , example): ... print(match.start(),

RE: XXX XXX should stop sending me rude email messages.

2023-02-27 Thread avi.e.gross
Michael, Although I appreciate much of what you say, I ask humbly and politely that we change the Subject line for messages like this one. HH is out of range for now, albeit I think he can still read what we say. But keeping the name Michael Torrie in the subject line, should be sort of XXX

RE: How to escape strings for re.finditer?

2023-02-27 Thread avi.e.gross
Jen, Can you see what SOME OF US see as ASCII text? We can help you better if we get code that can be copied and run as-is. What you sent is not terse. It is wrong. It will not run on any python interpreter because you somehow lost a carriage return and indent. This is what you sent:

Re: Rob Cliffe should stop sending me rude email messages.

2023-02-27 Thread Michael Torrie
On 2/27/23 09:17, Grant Edwards wrote: > On 2023-02-27, Michael Torrie wrote: > >> I've been putting off sending this message for days, but the list noise >> level is now to the point that it has to be said. > > Ah, I've finially realized why some of those threads have seemed so > disjointed to

RE: How to escape strings for re.finditer?

2023-02-27 Thread avi.e.gross
Jen, What you just described is why that tool is not the right tool for the job, albeit it may help you confirm if whatever method you choose does work correctly and finds the same number of matches. Sometimes you simply do some searching and roll your own. Consider this code using a sort of

Re: How to escape strings for re.finditer?

2023-02-27 Thread Jen Kris via Python-list
I haven't tested it either but it looks like it would work.  But for this case I prefer the relative simplicity of: example = 'X - abc_degree + 1 + qq + abc_degree + 1' find_string = re.escape('abc_degree + 1') for match in re.finditer(find_string, example):     print(match.start(),

How to fix this issue

2023-02-27 Thread Arslan Mehmood
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. >>> --

Re: How to escape strings for re.finditer?

2023-02-27 Thread Cameron Simpson
On 28Feb2023 00:57, Jen Kris wrote: Yes, that's it.  I don't know how long it would have taken to find that detail with research through the voluminous re documentation.  Thanks very much.  You find things like this by printing out the strings you're actually working with. Not the original

Re: How to escape strings for re.finditer?

2023-02-27 Thread Cameron Simpson
On 28Feb2023 01:13, Jen Kris wrote: I went to the re module because the specified string may appear more than once in the string (in the code I'm writing). Sure, but writing a `finditer` for plain `str` is pretty easy (untested): pos = 0 while True: found =

Re: How to escape strings for re.finditer?

2023-02-27 Thread Jen Kris via Python-list
string.count() only tells me there are N instances of the string; it does not say where they begin and end, as does re.finditer.  Feb 27, 2023, 16:20 by bobmellow...@gmail.com: > Would string.count() work for you then? > > On Mon, Feb 27, 2023 at 5:16 PM Jen Kris via Python-list <> >

RE: How to escape strings for re.finditer?

2023-02-27 Thread avi.e.gross
Just FYI, Jen, there are times a sledgehammer works but perhaps is not the only way. These days people worry less about efficiency and more about programmer time and education and that can be fine. But it you looked at methods available in strings or in some other modules, your situation is

Re: How to escape strings for re.finditer?

2023-02-27 Thread Jen Kris via Python-list
I went to the re module because the specified string may appear more than once in the string (in the code I'm writing).  For example:  a = "X - abc_degree + 1 + qq + abc_degree + 1"  b = "abc_degree + 1"  q = a.find(b) print(q) 4 So it correctly finds the start of the first instance, but not

RE: it seems like a few weeks ago... but actually it was more like 30 years ago that i was programming in C, and

2023-02-27 Thread avi.e.gross
Yes, Greg, you are correct. After I posted, I encountered a later message that suggested it was list comprehensions that had accidentally left a variable behind in a context when theoretically you got ALL you asked for in the resulting list, so it fixed eventually. You live and learn till you

RE: How to escape strings for re.finditer?

2023-02-27 Thread avi.e.gross
MRAB makes a valid point. The regular expression compiled is only done on the pattern you are looking for and it it contains anything that might be a command, such as an ^ at the start or [12] in middle, you want that converted so NONE OF THAT is one. It will be compiled to something that looks

Re: How to escape strings for re.finditer?

2023-02-27 Thread Jen Kris via Python-list
Yes, that's it.  I don't know how long it would have taken to find that detail with research through the voluminous re documentation.  Thanks very much.  Feb 27, 2023, 15:47 by pyt...@mrabarnett.plus.com: > On 2023-02-27 23:11, Jen Kris via Python-list wrote: > >> When matching a string

Re: Python 3.10 Fizzbuzz

2023-02-27 Thread Rob Cliffe via Python-list
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 nagging about formatting. You will save time and mental >

Re: Python 3.10 Fizzbuzz

2023-02-27 Thread Greg Ewing via Python-list
On 28/02/23 5:08 am, Thomas Passin wrote: On 2/27/2023 11:01 AM, Mats Wichmann wrote: If you intend to run Black on your code to ensure consistent formatting, you may as well learn to prefer double quotes, because it's going to convert single to double I prefer single quotes because they are

Re: How to escape strings for re.finditer?

2023-02-27 Thread Cameron Simpson
On 28Feb2023 00:11, Jen Kris wrote: When matching a string against a longer string, where both strings have spaces in them, we need to escape the spaces.  This works (no spaces): import re example = 'abcdefabcdefabcdefg' find_string = "abc" for match in re.finditer(find_string, example):    

Re: it seems like a few weeks ago... but actually it was more like 30 years ago that i was programming in C, and

2023-02-27 Thread Greg Ewing via Python-list
On 28/02/23 7:40 am, avi.e.gr...@gmail.com wrote: inhahe made the point that this may not have been the original intent for python and may be a sort of bug that it is too late to fix. Guido has publically stated that it was a deliberate design choice. The merits of that design choice can be

Re: How to escape strings for re.finditer?

2023-02-27 Thread MRAB
On 2023-02-27 23:11, Jen Kris via Python-list wrote: When matching a string against a longer string, where both strings have spaces in them, we need to escape the spaces. This works (no spaces): import re example = 'abcdefabcdefabcdefg' find_string = "abc" for match in

Re: Python 3.10 Fizzbuzz

2023-02-27 Thread Oscar Benjamin
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 nagging about formatting. You will save

How to escape strings for re.finditer?

2023-02-27 Thread Jen Kris via Python-list
When matching a string against a longer string, where both strings have spaces in them, we need to escape the spaces.  This works (no spaces): import re example = 'abcdefabcdefabcdefg' find_string = "abc" for match in re.finditer(find_string, example):     print(match.start(), match.end())

[Python-announce] REMINDER - Call for Proposals for SciPy 2023!

2023-02-27 Thread Arliss Collins
[image: image.png] Hello Folks, [image: :mega:] *Call for Proposals for SciPy 2023 closes March 1st* [image: :mega:] *Call for Proposals* for the 22nd annual Scientific Computing with Python Conference — also known as SciPy 2023

Re: Python 3.10 Fizzbuzz

2023-02-27 Thread Ethan Furman
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 nagging about formatting. You will save time and mental > energy for more important matters." > >

Re: Python 3.10 Fizzbuzz

2023-02-27 Thread rbowman
On Mon, 27 Feb 2023 11:08:22 -0500, Thomas Passin wrote: > I prefer single quotes because they are easier to type. There is that. JavaScript makes me lazy and C# slaps my knuckles with a steel edged ruler. -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 3.10 Fizzbuzz

2023-02-27 Thread rbowman
On Mon, 27 Feb 2023 09:01:26 -0700, Mats Wichmann wrote: > If you intend to run Black on your code to ensure consistent formatting, > you may as well learn to prefer double quotes, because it's going to > convert single to double (or: don't learn, and set your IDE to "convert > on save" and

Re: TypeError: can only concatenate str (not "int") to str

2023-02-27 Thread Thomas Passin
On 2/27/2023 2:15 PM, avi.e.gr...@gmail.com wrote: Karsten, There are limits to the disruption a group should tolerate even from people who may need some leeway. I wonder if Hen Hanna has any idea that some of the people he is saying this to lost most of their family in the Holocaust and had

RE: TypeError: can only concatenate str (not "int") to str

2023-02-27 Thread avi.e.gross
Karsten, There are limits to the disruption a group should tolerate even from people who may need some leeway. I wonder if Hen Hanna has any idea that some of the people he is saying this to lost most of their family in the Holocaust and had parents who barely survived passing through multiple

RE: it seems like a few weeks ago... but actually it was more like 30 years ago that i was programming in C, and

2023-02-27 Thread avi.e.gross
I am not a big fan of religions or philosophies that say a road to salvation is for the "I" to disappear. But on a more serious note, as Roel said, there is NO RULE being violated unless the documentation of the language says it is supposed to do something different. There are many excellent

Re: Python type system

2023-02-27 Thread Chris Angelico
On Tue, 28 Feb 2023 at 03:29, Weatherby,Gerard wrote: > Beyond Python, I’ve also found duck typing useful in real life. If it walks > like a troll, quacks like a troll … > ... regenerates limbs like a troll... ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Hen Hanna & google groups

2023-02-27 Thread Thomas Passin
On 2/27/2023 12:35 PM, Ethan Furman wrote: Greetings, all! As has been stated, Hen Hanna is posting through Google Groups, over which the Python List moderators have zero control. The only thing we can do, and which has now been done, is not allow those posts in to the Python List. --

Hen Hanna & google groups

2023-02-27 Thread Ethan Furman
Greetings, all! As has been stated, Hen Hanna is posting through Google Groups, over which the Python List moderators have zero control. The only thing we can do, and which has now been done, is not allow those posts in to the Python List. -- ~Ethan~ Moderator --

Python type system

2023-02-27 Thread Weatherby,Gerard
When I first started transitioning to Python as a Perl replacement, with my Java/C++ baggage, I thought Pythnon had some loosey-goosey type system. I thought int() and str() were casts, not constructors. I now realize Python has a great strong type system. Duck typing. If it walks like a duck,

Re: Line continuation and comments

2023-02-27 Thread Robert Latest via Python-list
Robert Latest wrote: > Paul Bryan wrote: >> Adding to this, there should be no reason now in recent versions of >> Python to ever use line continuation. Black goes so far as to state >> "backslashes are bad and should never be used": >> >>

Re: Line continuation and comments

2023-02-27 Thread Robert Latest via Python-list
Paul Bryan wrote: > Adding to this, there should be no reason now in recent versions of > Python to ever use line continuation. Black goes so far as to state > "backslashes are bad and should never be used": > > https://black.readthedocs.io/en/stable/the_black_code_style/

Re: Line continuation and comments

2023-02-27 Thread Robert Latest via Python-list
Edmondo Giovannozzi wrote: > Il giorno mercoledì 22 febbraio 2023 alle 09:50:14 UTC+1 Robert Latest ha > scritto: >> I found myself building a complicated logical condition with many ands and >> ors which I made more manageable by putting the various terms on individual >> lines and breaking them

Re: Rob Cliffe should stop sending me rude email messages.

2023-02-27 Thread Grant Edwards
On 2023-02-27, Michael Torrie wrote: > I've been putting off sending this message for days, but the list noise > level is now to the point that it has to be said. Ah, I've finially realized why some of those threads have seemed so disjointed to me. Years ago, I plonked all posts which are (like

Re: Python 3.10 Fizzbuzz

2023-02-27 Thread Thomas Passin
On 2/27/2023 11:01 AM, Mats Wichmann wrote: On 2/26/23 14:07, Hen Hanna wrote: On Monday, August 29, 2022 at 7:18:22 PM UTC-7, Paul Rubin wrote: Just because. from math import gcd def fizz(n: int) -> str:     match gcd(n, 15):    case 3: return "Fizz"    case 5:

Re: Python 3.10 Fizzbuzz

2023-02-27 Thread Mats Wichmann
On 2/26/23 14:07, Hen Hanna wrote: On Monday, August 29, 2022 at 7:18:22 PM UTC-7, Paul Rubin wrote: Just because. from math import gcd def fizz(n: int) -> str: match gcd(n, 15): case 3: return "Fizz" case 5: return "Buzz" case 15: return

Re: Rob Cliffe should stop sending me rude email messages.

2023-02-27 Thread Michael Torrie
I've been putting off sending this message for days, but the list noise level is now to the point that it has to be said. Often it is better to contact someone directly and privately rather than publicly embarrass them by calling them out. You've made it clear, however, that publicly calling you

Re: it seems like a few weeks ago... but actually it was more like 30 years ago that i was programming in C, and

2023-02-27 Thread Greg Ewing via Python-list
On 27/02/23 10:07 pm, Roel Schroeven wrote: I'm guessing you're thinking about variables leaking out of list comprehensions. I seem to remember (but I could be wrong) it was a design mistake rather than a bug in the code, but in any case it's been fixed now (in the 2 to 3 transition, I think).

Re: TypeError: can only concatenate str (not "int") to str

2023-02-27 Thread Karsten Hilbert
Am Sun, Feb 26, 2023 at 08:56:28AM -0800 schrieb Hen Hanna: > so far, i think Paul Rubin's post (in another thread) was > esp. concise, informative, --- but he's also made a comment > about 'shunting' beginners (questions) to a > concentration camp, and sounded a bit like a

Re: it seems like a few weeks ago... but actually it was more like 30 years ago that i was programming in C, and

2023-02-27 Thread Roel Schroeven
Op 27/02/2023 om 9:56 schreef inhahe: On Mon, Feb 27, 2023 at 3:52 AM Roel Schroeven wrote: > Op 26/02/2023 om 6:53 schreef Hen Hanna: > > > There are some similarities between Python and Lisp-family > > > languages, but really Python is its own thing. > > > > > > Scope (and extent ?) of

Re: it seems like a few weeks ago... but actually it was more like 30 years ago that i was programming in C, and

2023-02-27 Thread inhahe
On Mon, Feb 27, 2023 at 3:56 AM inhahe wrote: > > > On Mon, Feb 27, 2023 at 3:52 AM Roel Schroeven > wrote: > >> Op 26/02/2023 om 6:53 schreef Hen Hanna: >> > > There are some similarities between Python and Lisp-family >> > > languages, but really Python is its own thing. >> > >> > >> >

Re: it seems like a few weeks ago... but actually it was more like 30 years ago that i was programming in C, and

2023-02-27 Thread inhahe
On Mon, Feb 27, 2023 at 3:52 AM Roel Schroeven wrote: > Op 26/02/2023 om 6:53 schreef Hen Hanna: > > > There are some similarities between Python and Lisp-family > > > languages, but really Python is its own thing. > > > > > > Scope (and extent ?) of variables is one reminder that Python

Re: it seems like a few weeks ago... but actually it was more like 30 years ago that i was programming in C, and

2023-02-27 Thread Roel Schroeven
Op 26/02/2023 om 6:53 schreef Hen Hanna: > There are some similarities between Python and Lisp-family > languages, but really Python is its own thing. Scope (and extent ?) of variables is one reminder that Python is not Lisp  fori in range(5):  print( i )