RE strings (was: Variable Interpolation - status of PEP 215)
Daniel Dittmar
daniel.dittmar at sap.com
Fri Jun 21 04:58:39 EDT 2002
> Cimarron Taylor wrote:
>> m = re'^EMP:([^,]*),([^,]*),([^,]*),([^,]*)$'.match(line)
>> if m:
>> ...
>>
>> is much clearer and more maintainable than
Peter Hansen replied:
> Given that the only real difference is you skip an import, and
> at the cost of modifying the language definition in an unusual
> manner, is there any point to this at all?
The implementation could choose to cache the result of re.compile at module
level, thus
- speeding up the 'naive' re usage
- freeing the programmer from doing the caching in code
I'm still against it, the road to Perl is paved with syntax extensions.
But as this thread started with Variable Interpolation: maybe someone could
come up with a general way of extendable string literals? Something which
would transform re"..." to re.compile ("...") and pass this to the parser,
something which would transform v'value of x: $x' to 'value of x' % x and
pass this to the parser, ...
Daniel
More information about the Python-list
mailing list