[Python-Dev] replace on empty strings

Greg Ewing greg.ewing at canterbury.ac.nz
Thu May 25 02:53:03 CEST 2006


Fredrik Lundh wrote:
> so, which one is correct ?
> 
> Python 2.4.3
>  >>> "".replace("", "a")
> ''
>  >>> u"".replace(u"", u"a")
> u'a'

Probably there shouldn't be any "correct" in this case,
i.e. the result of replacing an empty string should be
undefined (because any string contains infinitely many
empty substrings).

+0 on raising an exception if you try.

--
Greg



More information about the Python-Dev mailing list