[Tutor] convert '\\t' to '\t'

Magnus Lycka magnus@thinkware.se
Thu Jan 16 02:16:00 2003


At 05:40 2003-01-16 +0000, Hy Python wrote:
>Could anyone please give me some tips on converting things like '\\t' into 
>'\t'?

 >>> "hello\\tworld".replace('\\t','\t')
'hello\tworld'

Note that \ is used as an indicator for certain special symbols.
'\\' is thus used to indicate that the string actually contains
a literal \. '\\t' means that the string contains a \ followed
by a t. '\t' is the indicator for a tab character, and it's needed
to make it explicit that we have a tab, and not just some space
characters in the string.

Thus replacing '\\' with '\' will never work. '\' is an incomplete
control sequence. You can't use that out of context like that.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se