[Python-Dev] String methods... finally

Barry A. Warsaw bwarsaw at cnri.reston.va.us
Fri Jun 11 01:32:26 CEST 1999


I've finally checked my string methods changes into the source tree,
albeit on a CVS branch (see below).  These changes are outgrowths of
discussions we've had on the string-sig, with I think Greg Stein
giving lots of very useful early feedback.  I'll call these changes
controversial (hence the branch) because Guido hasn't had much
opportunity to play with them.  Now that he -- and you -- can check
them out, I'm sure I'll get lots more feedback!

First, to check them out you need to switch to the string_methods CVS
branch.  On Un*x:

    cvs update -r string_methods

You might want to do this in a separate tree because this will sticky
tag your tree to this branch.  If so, try

    cvs checkout -r string_methods python

Here's a brief summary of the changes (as best I can restore the state 
-- its been a while since I actually made all these changes ;)

Strings now have as methods most of the functions that were previously 
only in the string module.  If you've played with JPython, you've
already had this feature for a while.  So you can do:

Python 1.5.2+ (#1, Jun 10 1999, 18:22:14)  [GCC 2.8.1] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> s = 'Hello There Devheads'
>>> s.lower()
'hello there devheads'
>>> s.upper()
'HELLO THERE DEVHEADS'
>>> s.split()
['Hello', 'There', 'Devheads']
>>> 'hello'.upper()
'HELLO'

that sort of thing.  Some of the string module functions don't make
sense as string methods, like join, and others never had a C
implementation so weren't added, like center.

Two new methods startswith and endswith act like their Java cousins.

The string module has been rewritten to be completely (I hope)
backwards compatible.  No code should break, though they could be
slower.  Guido and I decided that was acceptable.

What else?  Some cleaning up of the internals based on Greg's
suggestions.  A couple of new C API additions.  Builtin int(), long(),
and float() have grown a few new features.  I believe they are
essentially interchangable with string.atoi(), string.atol(), and
string.float() now.

After you guys get to toast me (in either sense of the word) for a
while and these changes settle down, I'll make a wider announcement.

Enjoy,
-Barry




More information about the Python-Dev mailing list