casting raw strings python
Posted
by dave
on Stack Overflow
See other posts from Stack Overflow
or by dave
Published on 2010-03-11T19:44:30Z
Indexed on
2010/03/11
19:49 UTC
Read the original article
Hit count: 448
in python, given a variable which holds a string is there a quick way to cast that into another raw string variable?
the following code should illustrate what im after...
def checkEqual(x, y):
print True if x==y else False
line1 = "hurr..\n..durr"
line2 = r"hurr..\n..durr"
line3 = "%r"%line1
print "%s \n\n%s \n\n%s \n" % (line1, line2, line3)
checkEqual(line2, line3) #outputs False
checkEqual(line2, line3[1:-1]) #outputs True
The closest I have found so far is the %r formatting flag which seems to return a raw string albeit within single quote marks. Is there any easier way to do this like a line3 = raw(line1)
kind of thing?
© Stack Overflow or respective owner