<skip <at> pobox.com> writes: > Giovanni> I'm sure you were talking more generically, but as for this > Giovanni> specific case (which is indeed very common), I always wondered > Giovanni> why re couldn't export wrappers around bound methods of the > Giovanni> last match object, so to allow: > > Giovanni> if re.match(...): > Giovanni> x,y = re.group(1), re.group(2) > Giovanni> elif re.match(..): > Giovanni> ... > > Because then the re module wouldn't be thread safe. > > Skip
True, although I suppose that you could add a "last match" to regular expression objects: re_pattern = re.compile( ... ) if re_pattern.match( string ): text = re_pattern.lastmatch.group( 1 ) This violates the stateless nature of regular expression objects, which is a minor wart. But other than that, the code seems cleaner to me - in other words, we concern ourselves only test part of the match first, and only after we've determined that there is a match, we start to look at the specific attributes of the match. -- Talin _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com