Re: affectation in if statement

2010-03-16 Thread samb
On Mar 16, 11:56 am, Jean-Michel Pichavant wrote: > samb wrote: > > Hi, > > > I've found a work around, inspired from Rob Williscroft : > > > class ReMatch(object): > >     """ > >         Object to be called : > >         1st time : do a regexp.match and return the answer (args: > > regexp, line)

Re: affectation in if statement

2010-03-16 Thread Jean-Michel Pichavant
samb wrote: Hi, I've found a work around, inspired from Rob Williscroft : class ReMatch(object): """ Object to be called : 1st time : do a regexp.match and return the answer (args: regexp, line) 2nd time : return the previous result (args: prev) """ def __cal

Re: affectation in if statement

2010-03-16 Thread Bruno Desthuilliers
samb a écrit : Hi, I've found a work around, inspired from Rob Williscroft : class ReMatch(object): """ Object to be called : 1st time : do a regexp.match and return the answer (args: regexp, line) 2nd time : return the previous result (args: prev) """ def __

Re: affectation in if statement

2010-03-16 Thread Peter Otten
samb wrote: > I've found a work around, inspired from Rob Williscroft : > > class ReMatch(object): > """ > Object to be called : > 1st time : do a regexp.match and return the answer (args: > regexp, line) > 2nd time : return the previous result (args: prev) > """ >

Re: affectation in if statement

2010-03-16 Thread samb
Hi, I've found a work around, inspired from Rob Williscroft : class ReMatch(object): """ Object to be called : 1st time : do a regexp.match and return the answer (args: regexp, line) 2nd time : return the previous result (args: prev) """ def __call__(self, rege

Re: affectation in if statement

2010-03-16 Thread samb
On Mar 16, 9:53 am, Chris Rebert wrote: > On Tue, Mar 16, 2010 at 1:37 AM, samb wrote: > > Thanks for all those suggestions. > > They are good! > > > 2) Concerning the suggestion : > > m = re.match(r'define\s+(\S+)\s*{$', line) > > if m: > >    thing = m.group(1) > > > m = re.match(r'include\s+(

Re: affectation in if statement

2010-03-16 Thread Rob Williscroft
samb wrote in news:5c361012-1f7b-487f-915b-0f564b238be3 @e1g2000yqh.googlegroups.com in comp.lang.python: > Thanks for all those suggestions. > They are good! > > 1) Let's suppose now that instead of just affecting "thing = > m.group(1)", I need to do a piece of logic depending on which match I >

Re: affectation in if statement

2010-03-16 Thread Chris Rebert
On Tue, Mar 16, 2010 at 1:37 AM, samb wrote: > Thanks for all those suggestions. > They are good! > 2) Concerning the suggestion : > m = re.match(r'define\s+(\S+)\s*{$', line) > if m: >    thing = m.group(1) > > m = re.match(r'include\s+(\S+)$', line) > if m: >    thing = m.group(1) > > #etc... >

Re: affectation in if statement

2010-03-16 Thread samb
Thanks for all those suggestions. They are good! 1) Let's suppose now that instead of just affecting "thing = m.group(1)", I need to do a piece of logic depending on which match I entered... 2) Concerning the suggestion : m = re.match(r'define\s+(\S+)\s*{$', line) if m: thing = m.group(1) m

Re: affectation in if statement

2010-03-16 Thread Gary Herron
samb wrote: Hi, I'm trying to do something like : if m = re.match(r'define\s+(\S+)\s*{$', line): thing = m.group(1) elif m = re.match(r'include\s+(\S+)$', line): thing = m.group(1) else thing = "" But in fact I'm not allowed to affect a variable in "if" statement. My code should th

Re: affectation in if statement

2010-03-16 Thread Paul Rubin
samb writes: > or like : > > m = re.match(r'define\s+(\S+)\s*{$', line) > if m: > thing = m.group(1) > else: > m = re.match(r'include\s+(\S+)$', line) > if m: > thing = m.group(1) > else > thing = "" > > Which isn't nice neither because I'm going to have maybe 20 ma

Re: affectation in if statement

2010-03-16 Thread Chris Rebert
On Tue, Mar 16, 2010 at 12:45 AM, samb wrote: > Hi, > > I'm trying to do something like : > > if m = re.match(r'define\s+(\S+)\s*{$', line): >    thing = m.group(1) > elif m = re.match(r'include\s+(\S+)$', line): >    thing = m.group(1) > else >    thing = "" > > But in fact I'm not allowed to aff

affectation in if statement

2010-03-16 Thread samb
Hi, I'm trying to do something like : if m = re.match(r'define\s+(\S+)\s*{$', line): thing = m.group(1) elif m = re.match(r'include\s+(\S+)$', line): thing = m.group(1) else thing = "" But in fact I'm not allowed to affect a variable in "if" statement. My code should then look like :