Questions on 1.6a2's string methods

Gary Herron gherron at aw.sgi.com
Fri Apr 14 13:46:54 EDT 2000


Manus Hand wrote:
> 
> 1.  I see that string objects now support (as methods) most of the
>     functions from the string module.  Among these are:
>         upper, lower, split, strip, find
>     and surely others.  My question is, why is capwords (which seems
>     to be in the same genre as upper and lower) not a method?
> 
> 2.  Along these same lines, since split() became a method of the
>     string type, wouldn't it make sense to make join() a method of
>     the list type?
> 
> 3.  Are the classlike standard types (list, dictionary, and now
>     string) equipped with a __dict__ attribute?  I can see the names
>     of all functions supported by a user-defined class by saying
>     className.__dict__.keys(), but I cannot see the list of methods
>     for the string type (at least not in the same way).  Thus my
>     need to ask silly questions like #1 above (maybe capwords is
>     there by some other name??)
> 
 
It looks like `capwords' has changed name to `title' with a slight
change in functionality.

>>> '  This    is   a test'.title()
'  This    Is   A Test'

This capitalizes words, but does not change white space as `capwords'
did.

Take a look at the other functions:

>>> ''.__methods__
['capitalize', 'center', 'count', 'endswith', 'expandtabs', 'find',
'index', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join',
'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust',
'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase',
'title', 'translate', 'upper']

Most are familiar.   I'm happy to see 'startswith' and 'endswith'.

-- 
Dr. Gary Herron <gherron at aw.sgi.com>
206-287-5616
Alias | Wavefront
1218 3rd Ave, Suite 800, Seattle WA 98101




More information about the Python-list mailing list