Why is it that str.replace doesn't work sometimes?

unayok unayok at gmail.com
Wed Jun 24 12:28:34 EDT 2009


On Jun 24, 12:11 pm, humn <xelothat... at gmail.com> wrote:
> but this doesn't:
>
> if '\title' in line:
>         line = line.replace('\title{', '[size=150][b]')
>         line = line.replace('}', '[/b][/size]')

\t is an escaped <tab> character. so, '\title' will look for
'<tab>itle'

Two ways to fix this:

1. use r'\title'

2. use '\\title'

\c does not represent a known escape sequence so it remains two
characters.




More information about the Python-list mailing list