Remove all spaces EXCLUDING tab… here is a solution to the problem.
Remove all spaces EXCLUDING tab
Just a (hopefully) simple question.
Messing with Python, I just want to know how to remove all spaces to the left and right of the string except tabs, or rather \t
I
know I can replace the recursive loop, but it’s a hassle. There must be an easier way.
Basically just remove \n, ,\r,
… etc., except \t
.
Cheers.
Solution
You can also use:
s = " \t a string example\t "
s = s.strip(' \n\r')
This removes any spaces, \n, or \r characters from the left, right, or sides of the string.