affectation in if statement
Chris Rebert
clp2 at rebertia.com
Tue Mar 16 04:53:33 EDT 2010
On Tue, Mar 16, 2010 at 1:37 AM, samb <sam.bancal at gmail.com> wrote:
> Thanks for all those suggestions.
> They are good!
<snip>
> 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...
>
> It means that I'll do all the checks, even if the first one did match
> and I know that the next will not...
Note how I split it out into a separate function and used `return
m.group(1)` to avoid that exact situation.
Cheers,
Chris
--
http://blog.rebertia.com
More information about the Python-list
mailing list