Is Perl *that* good?
Skip Montanaro
skip at pobox.com
Wed Apr 28 07:48:07 EDT 2004
> If only compiled regular expression objects allowed easy access to the
> last match object, python regxes would become significantly more
> convenient. For example, today you have to write:
>
> m = myregex.match(line)
> if (m):
> xyz = m.group('xyz')
>
> It would be much easier to do:
>
> if myregex.match(line):
> xyz = myregex.lastm.group('xyz')
>
> Having to introduce a new variable name for a match object just
> muddles the code unnecessarily in common regex usage scenarios.
Sure, it's more convenient but it's not thread-safe. The old regex package
used to do this. When Perl-compatible regular expressions were introduced
into Python it was removed precisely because of that limitation. As Peter
Hansen pointed out, if you want that behavior you can write it on a
per-application basis.
Skip
More information about the Python-list
mailing list