Monday, August 24, 2009

how to strip trailing characters in Python

Oddly enough, you use the rstrip command. :)

Simply import the string module:

import string

Suppose you have a variable oldstring that has trailing spaces, then do this to the string:

newstring = string.rstrip( oldstring, ' ' )

Done.

No comments: