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

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: > >

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

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 :