Questions on 1.6a2's string methods

Michael Hudson mwh21 at cam.ac.uk
Fri Apr 14 04:22:56 EDT 2000


I think weve had all these discussions recently.

Manus Hand <mjhand at concentric.net> writes:

> 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?

Start here:

http://x28.deja.com/[ST_rn=ps]/viewthread.xp?AN=586654400&recnum=%3cm3snysor7o.fsf at atrus.jesus.cam.ac.uk%3e%231/1

Conclusion: the "missing methods" might get implemented, if someone
gets round to it.  THe unicode string type has more methods (it has
center, ljust, rjust).

> 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?

Start here:

http://x29.deja.com/[ST_rn=ps]/viewthread.xp?AN=588318989

Conclusion: nothing obvious, but the status quo seems the most likely
(& best - to me) winner.

> 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??)

No, but they ways that always worked still work <wink>:

>>> dir('')
['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']
>>> dir(u'')
['capitalize', 'center', 'count', 'encode', 'endswith', 'expandtabs',
'find', 'index', 'isdecimal', 'isdigit', 'islower', 'isnumeric',
'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip',
'replace', 'rfind', 'rindex', 'rjust', 'rstrip', 'split',
'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate',
'upper']
>>> ''.__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']

No, no capwords.

HTH,
M.

-- 
  languages shape the way we think, or don't.
                                      -- Erik Naggum, comp.lang.lisp



More information about the Python-list mailing list