[Python-3000] More wishful thinking

Giovanni Bajo rasky at develer.com
Sun Apr 16 00:31:12 CEST 2006


Talin <talin at acm.org> wrote:
> 6) Although I would not want to propose that Python adopt C's
> 'assignment is an expression' behavior, I find myself constantly
> wanting to combine the following two statements into one:
>> m = re.match( ... )
> if m:
> # do something with m

I'm sure you were talking more generically, but as for this specific case
(which is indeed very common), I always wondered why re couldn't export
wrappers around bound methods of the last match object, so to allow:
if re.match(...):
 x,y = re.group(1), re.group(2)
elif re.match(..):
 ...
There are many other modules in standard library which exposes a function-based
interface where the functions are actually bound methods of a static object
(logging, for instance). If "re" gained this, it'd be great. In fact, this
could probably be done in 2.x as well.
Giovanni Bajo


More information about the Python-3000 mailing list

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