31 May
2002
31 May
'02
8:19 a.m.
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=None): return join(map(capitalize, s.split(sep)), sep or ' ') Cheers /F