Re: That horrible regexp idiom

2005-02-11 Thread Fredrik Lundh
Stephen Thorne wrote: > but it occured to me today, that it is possible to do it in python > without the extra line. > ' > '>>> def xsearch(pattern, subject): > '>>> yield pattern.search(subject) > > '>>> for m in xsearch(foo_pattern, subject): > '>>> pass > '>>> else: > '>>> pass > >

Re: That horrible regexp idiom

2005-02-10 Thread Johann C. Rocholl
Hi, > import re > foo_pattern = re.compile('foo') > > '>>> m = foo_pattern.search(subject) > '>>> if m: > '>>>pass > '>>> else: > '>>>pass I agree that is horrible. This is one of my favorite problems with python syntax. > but it occured to me today, that it is possible to do it in pyth

Re: That horrible regexp idiom

2005-02-10 Thread Duncan Booth
Nick Coghlan wrote: > I knew if/elif was a much better argument in favour of embedded > assignment than while loops are. > I know I'm going to regret posting this, but here is an alternative, very hackish way to do all those things people keep asking for, like setting variables in outer scopes

Re: That horrible regexp idiom

2005-02-10 Thread Nick Coghlan
Stephen Thorne wrote: Hi, import re foo_pattern = re.compile('foo') '>>> m = foo_pattern.search(subject) '>>> if m: '>>>pass '>>> else: '>>>pass Heh. Did you see Ray Gibbons's 'Testing Conditions' post before you sent this? I knew if/elif was a much better argument in favour of embedded as

Re: That horrible regexp idiom

2005-02-10 Thread Ville Vainio
> "Stephen" == Stephen Thorne <[EMAIL PROTECTED]> writes: Stephen> We've all seen it before. Its a horrible idiom that you Stephen> would achieve in another language by doing: Stephen> if (m = foo_pattern.search(subject)) Stephen> { } Stephen> else Stephen> { } S

Re: That horrible regexp idiom

2005-02-10 Thread alex23
Stephen Thorne wrote: > We've all seen it before. Its a horrible idiom that you would achieve > in another language by doing: > > if (m = foo_pattern.search(subject)) > { } > else > { } > > but it occured to me today, that it is possible to do it in python > without the extra line. > > '>>> for m i

That horrible regexp idiom

2005-02-09 Thread Stephen Thorne
Hi, import re foo_pattern = re.compile('foo') '>>> m = foo_pattern.search(subject) '>>> if m: '>>>pass '>>> else: '>>>pass We've all seen it before. Its a horrible idiom that you would achieve in another language by doing: if (m = foo_pattern.search(subject)) { } else { } but it occu