C has built-in classes such as str , so you cannot control them. Instead, you can extend the str class:
>>> class my_str(str): ... def strip_inner(self): ... return re.sub(r'\s{2,}', ' ', s) ... >>> s = my_str("A string with extra whitespace") >>> print s.strip_inner() A string with extra whitespace
marcog
source share