I've a normal string, that I like to send to a program, which only eats my string as "\"text\"", exactly like that. But in Python I can print it like that but I can't assign it like that. See the following:
My text:
In [12]:
i = fieldList[0]
print str(i.name)
Y03M01D01
Which I can print as "\"text\""
In [13]:
field_new = '"\\"'+str(i.name)+'\\""'
print field_new
"\"Y03M01D01\""
But this is how it is eaten by the program
In [14]:
field_new
Out[14]:
'"\\"Y03M01D01\\""'
Which is not equal to "\"text\"" and so my code fails.
Any suggestions how to resolve this?
Using the
rprefix for the string in your comparison will have python treat the string as raw (all backslashes are unescaped).