tomasz <[EMAIL PROTECTED]> writes: > here is a piece of pseudo-code (taken from Ruby) that illustrates the > problem I'd like to solve in Python: [...]
I asked the very same question in http://groups.google.com/group/comp.lang.python/browse_frm/thread/3e8da954ff2265e/4deb5631ade8b393 It seems that people either write more elaborate constructs or learn to tolerate the nesting. > Is there an alternative to it? A simple workaround is to write a trivial function that returns a boolean, and also stores the match object in either a global storage or an object. It's not really elegant, especially in smaller scripts, but it works: def search(pattern, s, store): match = re.search(pattern, s) store.match = match return match is not None class MatchStore(object): pass # irrelevant, any object with a 'match' attr would do where = MatchStore() if search(pattern1, s, where): pattern1 matched, matchobj in where.match elif search(pattern2, s, where): pattern2 matched, matchobj in where.match ... -- http://mail.python.org/mailman/listinfo/python-list