Re: [Tutor] Regex not working as desired

2018-03-06 Thread Alan Gauld via Tutor
On 06/03/18 22:17, Albert-Jan Roskam wrote: > But the way you wrote it, the generator expression just "floats" Any expression can be used where a value is expected provided that e3xpression produces a value of the required type. A generator expression effectively produces a sequence and the type

Re: [Tutor] Regex not working as desired

2018-03-06 Thread Steven D'Aprano
On Tue, Mar 06, 2018 at 10:17:20PM +, Albert-Jan Roskam wrote: > > >>> all(c.isdigit() for c in '12c4') > > False > > I never understood why this is syntactically correct. It's like two > parentheses are missing. > > This I understand: > all((c.isdigit() for c in '12c4')) > Or this: > all([

Re: [Tutor] Regex not working as desired

2018-03-06 Thread Albert-Jan Roskam
On Feb 27, 2018 09:50, Alan Gauld via Tutor wrote: > > On 27/02/18 05:13, Cameron Simpson wrote: > > > hard to debug when you do. That's not to say you shouldn't use them, but > > many > > people use them for far too much. > > > > Finally, you could also consider not using a regexp for this part

Re: [Tutor] Regex not working as desired

2018-02-27 Thread Alan Gauld via Tutor
On 27/02/18 09:50, Peter Otten wrote: >> def all_digits(s): >> return all(c.isdigit() for c in s) > > Note that isdigit() already checks all characters in the string: Ah! I should have known that but forgot. I think the singular name confused me. > The only difference to your suggestion is

Re: [Tutor] Regex not working as desired

2018-02-27 Thread Peter Otten
Alan Gauld via Tutor wrote: > On 27/02/18 05:13, Cameron Simpson wrote: > >> hard to debug when you do. That's not to say you shouldn't use them, but >> many people use them for far too much. > > >> Finally, you could also consider not using a regexp for this particular >> task. Python's "int"

Re: [Tutor] Regex not working as desired

2018-02-27 Thread Alan Gauld via Tutor
On 27/02/18 05:13, Cameron Simpson wrote: > hard to debug when you do. That's not to say you shouldn't use them, but many > people use them for far too much. > Finally, you could also consider not using a regexp for this particular task. > > Python's "int" class can be called with a string,

Re: [Tutor] Regex not working as desired

2018-02-27 Thread Steven D'Aprano
On Mon, Feb 26, 2018 at 11:01:49AM -0800, Roger Lea Scherer wrote: > The first step is to input data and then I want to check to make sure > there are only digits and no other type of characters. I thought regex > would be great for this. I'm going to quote Jamie Zawinski: Some people, when

Re: [Tutor] Regex not working as desired

2018-02-27 Thread Terry Carroll
On Mon, 26 Feb 2018, Terry Carroll wrote: Instead of looking fo re xcaprions.. Wow. That should read "Instead of looking for exceptions..." Something really got away from me there. -- Terry Carroll carr...@tjc.com ___ Tutor maillist - Tutor@pyth

Re: [Tutor] Regex not working as desired

2018-02-27 Thread Terry Carroll
On Mon, 26 Feb 2018, Roger Lea Scherer wrote: """ ensure input is no other characters than digits sudocode: if the input has anything other than digits return digits """ p = re.compile(r'[^\D]') I'm not so great at regular expressions, but this regex appears to be searching for a str

Re: [Tutor] Regex not working as desired

2018-02-26 Thread Cameron Simpson
On 26Feb2018 11:01, Roger Lea Scherer wrote: The first step is to input data and then I want to check to make sure there are only digits and no other type of characters. I thought regex would be great for this. Many people do :-) They are a reasonable tool for an assortment of text matching

[Tutor] Regex not working as desired

2018-02-26 Thread Roger Lea Scherer
The first step is to input data and then I want to check to make sure there are only digits and no other type of characters. I thought regex would be great for this. The program works great, but no matter what I enter, the regex part does the same thing. By same thing I mean this: RESTA