affectation in if statement

Paul Rubin no.email at nospam.invalid
Tue Mar 16 03:39:55 EDT 2010


samb <sam.bancal at gmail.com> 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 match
> tests and I wouldn't like to have 20 indentations.

for pat in [r'define\s+(\S+)\s*{$', r'include\s+(\S+)$', ...]:
   m = re.match(pat, line)
   ...



More information about the Python-list mailing list