You can use the python formatting capabilities to print a string in raw form:
print "%r" % s
You can also create a string in raw form, for example:
s = r'This string has \n\r whitespace'
and Python will handle the escape backslash, so this is exactly what you get:
print s
source share