Buğra Coşkun Buğra Coşkun - 1 year ago 68
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


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

Answer Source

\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...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download