Movatterモバイル変換
[0]ホーム
How best to write this if-else?
gzeljkogzeljko at sezampro.yu
Sat Apr 21 18:03:24 EDT 2001
From: Mick <vsl6 at paradise.net.nz>> for i in all:> ma = i[0].match(str)> if ma:> i[1](ma)>for r,f in all: ma = r.mach(str) if ma: f(ma)ly-y'rs-gzeljko>> Mick>>> -----Original Message-----> From:python-list-admin at python.org> [mailto:python-list-admin at python.org]On Behalf Of Roy Smith> Sent: Sunday, April 22, 2001 9:02 AM> To:python-list at python.org> Subject: Re: How best to write this if-else?>>> "Ingo Wilken" <Ingo.Wilken at Informatik.Uni-Oldenburg.DE> wrote:> > for e in [e1, e2, e3]:> > m = e.match(line)> > if m:> > text = m.group(1)> > break> > else:> > no match found>> OK, that's pretty neat, but I realize now that my example was> unintentionally misleading. The problem is not quite as regular as I made> it out to be.>> What if I want to execute different code depending on which expression I> matched? Something along the lines of (pseudocode):>> if (m = e1.match(line)):> text1 = m.group(1)> do_complicated_processing (text1)> elif (m = e2.match(line)):> text1 = m.group(1)> text2 = m.group(2)> print text1, text2> elif (m = e3.match(line)):> return> -->http://mail.python.org/mailman/listinfo/python-list>>> -->http://mail.python.org/mailman/listinfo/python-list>
More information about the Python-listmailing list
[8]ページ先頭