Raw Strings with Variables
Albert Hopkins
marduk at letterboxes.org
Tue Aug 18 19:39:54 EDT 2009
On Tue, 2009-08-18 at 16:16 -0700, WilsonOfCanada wrote:
> Hellos,
>
> I know that if you have:
>
> happy = r"C:\moo"
> print happy
>
> you get C:\moo instead of C:\\moo
>
> The thing is that I want to do this a variable instead.
>
> ex. testline = fileName.readline()
> rawtestline = r testline
I'm not sure what you are hoping for... Raw strings apply to string
literals. If you are reading from a file, as above, you need not worry
about it:
$ cat test.txt
C:\moo
$ python -c 'r = open("test.txt").readline() ; print r'
C:\moo
More information about the Python-list
mailing list