How to replace a comma

Hendrik van Rooyen mail at microcorp.co.za
Mon Dec 18 08:29:33 EST 2006


From: "Lad" <python at hope.cz> wrote:


> In a text I need to
> add a blank(space) after a comma but only if there was no blank(space)
> after the comman
> If there was a blank(space), no change is made.
> 
> I think it could be a task for regular expression but can not figure
> out the correct regular expression.

re's are a pain.  Do this instead:

>>> s = "hello, goodbye,boo"
>>> s.replace(', ',',')
'hello,goodbye,boo'
>>> _.replace(',',', ')
'hello, goodbye, boo'
>>> 

Hope this helps - Hendrik




More information about the Python-list mailing list