Safe string escaping?

Grant Olson olsongt at verizon.net
Mon Mar 7 19:24:43 EST 2005


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
way to do this than eval("'%s'" % "foo\\n\\0") but I'm not finding it.

Any tips would be appreciated,

Grant




More information about the Python-list mailing list