Buğra Coşkun Buğra Coşkun - 3 months ago 9
Python Question

Can't use \s as an escape character?

I can use other escape characters without any problem but my atom text editor and python itself doesn't see it as an escape character but as a normal character.

print '\s', test_line


just writes

\stesting_bot1


How can I make it so that the editor and python will see this as an escape character and as space ?

Answer

\s isn't an escape sequence in Python. \t, \n, \r etc are (see the Python lexical analysis docs) but non-special characters will not be interpreted as anything special, hence your \s appearing literally.

However, \s does means space in regular expression syntax of course...

Comments