I have a string variable which is not printing properly, I guess because it contains escape characters. How to escape these escape-characters?
>>> print "[p{Aa}\\P{InBasic_Latin}\r\t\n]"
>>> ]
such that it prints this [p{Aa}\\P{InBasic_Latin}\r\t\n]
instead of what's currently printing ]
To solve your problem you will need to use Backslash characters. Backslash ( \ ) characters are used to escape characters
In your question \, \r, \t, \n are the characters you want to escape from your print statement.
Answer is : print "[p{Aa}\\\P{InBasic_Latin}\\r\\t\\n]"
The use of backslash is it will escape the very first character after it.
In the case where you want to print "\P", here you need to add one slash at the start "\" so that it escapes the first backslash then afterward it will print \P. As P is not a special character you don't need to add one more backslash to escape it.