[Tutor] can you turn strings from a file into raw strings?
Alan Gauld
alan.gauld at blueyonder.co.uk
Thu Apr 8 16:58:09 EDT 2004
> I am wondering if there is anyway to force the output of
> somefile.readline() to be a raw string?
I'm not sure what you mean, it is a raw string.
> 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.
No the '\' will be read as a '\' character and when you print
the file Python will corrctly display it with double \\
The \ is a specific ascii character that is written to the file.
Whether you write
r'foo\t'
or
'foo\\t'
is immaterial in termns of what actually gets written to the
file(and hence read back), its the same 5 ascii characters.
The only difference is in the representation on the screen.
Can you show us an example of what you are doing that seems broken?
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list