"Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote:
> From: "Lad" <[EMAIL PROTECTED]> 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'
>>>>
>
Personally I'd go one step further and regularise the whitespace around the
commas completely (otherwise what if you have spaces before commas, or
multiple spaces after them:
>>> s = "hello, goodbye , boo"
>>> print ', '.join(t.strip() for t in s.split(','))
hello, goodbye, boo
--
http://mail.python.org/mailman/listinfo/python-list