[Python-Dev] deprecating string module?
Fredrik Lundh
fredrik@pythonware.com
Fri, 31 May 2002 10:19:18 +0200
Guido van Rossum wrote:
> IOW, if I write a function that calls s.lower() for an argument s, I
> can write a custom string type (e.g. UserString) that will work with
> f. If I wrote the same function using string.lower(s), I have no hope
> (short of modifying the string module).
unless the functions in the string module delegate everything
to the object (just like len(), getattr(), and others), and you
make sure that your type behaves well when mixed with basic
strings.
something like, say:
def lower(s):
return s.lower()
or
def capwords(s, sep=3DNone):
return join(map(capitalize, s.split(sep)), sep or ' ')
Cheers /F