non-function members of string-module.

Don O'Donnell donod at home.com
Tue Oct 23 20:47:04 EDT 2001


Steven Cummings wrote:
> 
> I'm not sure if this has already been discussed in public, but if we
> want to phase out the use of the string module, then what is the plan
> for its members, like letter, uppercase, etc.?
> 
> /S

I really hope the string module is never phased out.

The string module functions are useful as arguments to the map function,
as in:

lines = map(string.strip, lines)

and for other functional programming uses, where one wants to pass a
function as an argument.

Granted, a list comprehension could be used in place of the map
function:

lines = [line.strip() for line in lines]

But it is slower than the map function since the loop is done in Python
byte code rather than C.

If, for whatever reason, the string module _is_ eliminated, perhaps the
string module functions could be replaced by static methods of the str
class.  Then we could continue to use these static methods as though
they were functions.  Unfortunately, I guess the names would have to be
changed since they are already being used as instance methods.  How
about just capitalizing the first letter of the name.  

Just replace:
lines = map(string.strip, lines)

with:
lines = map(str.Strip, lines)    # Strip is a static method of class str

and it should continue to function as before.  No?

Cheers,
Don



More information about the Python-list mailing list