Looks like you also want to remove spaces. You can do something like this,
>>> import re >>> s = "abc \n \t \t\t \t \nefg" >>> s = re.sub('\s+', '', s) >>> s 'abcefg'
Another way would be to do
>>> s = "abc \n \t \t\t \t \nefg" >>> s = s.translate(None, '\t\n ') >>> s 'abcefg'
source share