Short circuting

Ed Connell edwinconnell at gmail.com
Fri Jan 21 18:33:59 EST 2011


Hi,
Consider the following please: (re_section, re_name, etc are previously
compiled patterns)
 result1 = re_section.search(line);
 result2 = re_name.search(line);
 result3 = re_data1.search(line);
 result4 = re_data2.search(line);
 if result1:
 last_section = result1.group()[18:-5]
 elif result2:
 last_name = result2.group(0)[6:-1]
 elif result3:
 data[last_section] = {last_name:
result3.group()[13:-5]}
 elif result4:
 data[last_section] = {last_name:
result4.group()[17:-5]}
It gets my goat to have to obtain all resultx when I just want the first
that is not None. (In theory, the number of results can be much longer.) I
can think of alternatives (raising exceptions), but they all use deep
indenting.
Ideas?
Ed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110121/ed3799f8/attachment.html>


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /