Is Perl *that* good?

Paramjit Oberoi p_s_oberoi at hotmail.com
Tue Apr 27 23:18:23 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:
> 
> Hmm.  The reason this hasn't been done is that it makes the match
> method non-reentrant.  For example, suppose you call some functions in
> between the matching and use of the matched object, like this:

I agree that that's a good reason...

So: to make regular expressions convenient, it should be possible to use
them without necessarily declaring a variable for the regular expression
object or the match objects.  The former is fairly easy; the latter is
not.

The match object needs to have local scope; but, a function cannot access
the caller's locals without mucking around with sys._getframe().  Is there
any other way of injecting objects into the caller's namespace?  Are there
any objects that exist per-frame that could be co-opted for this purpose?

I suppose a convenience module that uses sys._getframe() could be written,
but I don't think it would be suitable for the standard library.  Of
course, once we get decorators, it would be possible to munge functions to
make them more amenable to regexes... but then, we don't want such hackery
in the standard library either.

Question about decorators: are they only going to be for methods, or for
all functions?



More information about the Python-list mailing list