[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: affectation in if statement

Paul Rubin

3/16/2010 7:40:00 AM

samb <sam.bancal@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)
...