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

Hy Python pythonpython@hotmail.com
Thu Jan 16 02:52:03 2003


I understand this.
But what I really want to do is
convert things like "\\n","\\r","\\s", "\\x" to "\n", "\r", "\s", "\x"
So,  is there a universal way to convert "\\" to "\"

Thanks a lot.

Hy




>From: Magnus Lycka <magnus@thinkware.se>
>To: "Hy Python" <pythonpython@hotmail.com>, tutor@python.org
>Subject: Re: [Tutor] convert '\\t'   to  '\t'
>Date: Thu, 16 Jan 2003 08:15:40 +0100
>
>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
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor


_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* 
http://join.msn.com/?page=features/virus