Optimization of an RE substitution

Sean Holdsworth sh at hob.cx
Wed Dec 19 13:55:10 CET 2001


On Wed, 19 Dec 2001 11:13:46, Duncan Booth <duncan at NOSPAMrcp.co.uk> wrote:
>sh at hob.cx (Sean Holdsworth) wrote in news:slrna20tbt.2o4.sh at elf.hob.cx:
>
>> Then I remembered that I'm supposed to be handling 8 bit clean data...
>> I realise that even if I come up with a more efficient method of
>> doing this I'll still have to use a modified version of smtplib but
>> I'd be interested to hear people's suggestions and comments.
>
>Doesn't this have the effect you want:
>    	msg = string.replace(msg, '\r\n', '\n')
>    	msg = string.replace(msg, '\r', '\n')
>    	msg = string.replace(msg, '\n', '\r\n')

Hi Duncan,

Er... yes! Now why didn't I spot that earlier? I guess I was too
fixated on the idea of converting all line breaks into some sort
of token and then converting back, to realise what the obvious token
should be. I'll do some more timing but I think that might solve the
problem.

Thanks, Sean



More information about the Python-list mailing list