Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32104
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: while expression feature proposal |
| Date | 2012-10-25 11:44 +0200 |
| Organization | A newly installed InterNetNews server |
| Message-ID | <k6b1m6$krl$1@r03.glglgl.gl> (permalink) |
| References | <50886398.5050301@tim.thechases.com> <mailman.2800.1351117627.27098.python-list@python.org> |
Am 25.10.2012 00:26 schrieb Cameron Simpson:
> If I could write this as:
>
> if re_FUNKYPATTERN.match(test_string) as m:
> do stuff with the results of the match, using "m"
>
> then some cascading parse decisions would feel a bit cleaner. Where I
> current have this:
>
> m = re_CONSTRUCT1.match(line)
> if m:
> ... handle construct 1 ...
> else:
> m = re_CONSTRUCT2.match(line)
> if m:
> ... handle construct 2 ...
> else:
> m = re_CONSTRUCT3.match(line)
>
> I could have this:
>
> if re_CONSTRUCT1.match(line) as m:
> ... handle construct 1 ...
> elif re_CONSTRUCT2.match(line) as m:
> ... handle construct 2 ...
> elif re_CONSTRUCT3.match(line) as m:
I would do
for r in re_CONSTRUCT1, re_CONSTRUCT2, re_CONSTRUCT3:
m = r.match(line)
if m: handle_construct
or maybe
actions = {re_CONSTRUCT1: action1, ...}
def matching(line, *rr):
for r in rr:
m = r.match(line)
if m: yield r; return
for r in matching(line, *actions.keys()):
actions[r]()
break
else:
raise NoActionMatched() # or something like that
Thomas
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: while expression feature proposal Cameron Simpson <cs@zip.com.au> - 2012-10-25 09:26 +1100
Re: while expression feature proposal Paul Rubin <no.email@nospam.invalid> - 2012-10-24 15:37 -0700
Re: while expression feature proposal Paul Rubin <no.email@nospam.invalid> - 2012-10-24 15:47 -0700
Re: while expression feature proposal Cameron Simpson <cs@zip.com.au> - 2012-10-25 09:58 +1100
Re: while expression feature proposal Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-25 11:44 +0200
Re: while expression feature proposal Grant Edwards <invalid@invalid.invalid> - 2012-10-25 14:15 +0000
Re: while expression feature proposal Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-25 18:15 +0200
csiph-web