[Tutor] can you turn strings from a file into raw strings?

Karl Pflästerer sigurd at 12move.de
Thu Apr 8 12:32:10 EDT 2004


On  8 Apr 2004, Brian van den Broek <- bvande at po-box.mcgill.ca wrote:

[...]
> Why I care:
> I am wanting to store a series of directory names in a plain text
> config file. I can read the file just fine and have can do all I've
> tried with the output of the readline() method so far. But, since I am
> on a Windows machine, I would prefer to turn the readline() output
> into a raw string. Otherwise, the directory separator '\' gets read as
> an escape character. I know I can solve it by using '/' in place of

Did you actually try that?  Here's a small example:

$ cat > raw_string
c:\foo\bar\test\new\end

$ python
Python 2.3.3 (#1, Dec 30 2003, 08:29:25) 
[GCC 3.3.1 (cygming special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> f = file('raw_string')
>>> f.readline()
'c:\\foo\\bar\\test\\new\\end\r\n'
>>> f = file('raw_string')
>>> print f.readline()
c:\foo\bar\test\new\end

No interpolation happens (\t is tab and \n newline).



   Karl
-- 
Please do *not* send copies of replies to me.
I read the list




More information about the Tutor mailing list