On Mon, 07 Mar 2005 19:24:43 -0500, "Grant Olson" <[EMAIL PROTECTED]> wrote:
>I have a data file that has lines like "foo\n\0" where the \n\0 is acutally
>backslash+n+backslash+0. I.E. a repr of the string from python would be
>"foo\\n\\0". I'm trying to convert this string into one that contain
There is very likely a more reasonable solution than this, but it was
the first one that came to mind:
IDLE 1.0.3
>>> string = "foo\\n\\0"
>>> string = string.replace( "\\n" , "\n" )
>>> string = string.replace( "\\0" , "\0" )
>>> string
'foo\n\x00'
>>> print string
foo
Hope this helps.
-
Grant Olson wrote:
I have a data file that has lines like "foo\n\0" where the \n\0 is acutally
backslash+n+backslash+0. I.E. a repr of the string from python would be
"foo\\n\\0". I'm trying to convert this string into one that contains
actual newlines and whatnot.
r"foo\n\0".decode("string_escap
I have a data file that has lines like "foo\n\0" where the \n\0 is acutally
backslash+n+backslash+0. I.E. a repr of the string from python would be
"foo\\n\\0". I'm trying to convert this string into one that contains
actual newlines and whatnot. I feel like there has to be a better and safer
wa