non-function members of string-module.
Michael Hudson
mwh at python.net
Wed Oct 24 04:44:49 EDT 2001
Don O'Donnell <donod at home.com> writes:
> 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.
It does seem to be pain for no huge reason.
> 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.
It's not a lot slower in 2.1.1, and seems to be a bit faster in 2.2b1+
(different machins, different OS's, though).
The iteration protocol is getting a bit faster in 2.2, so this isn't a
total shock.
> 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.
Nope!
> 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?
In Python 2.2,
map(str.strip, lines)
is the fastest of the lot. Hmm, I feel a patch coming on...
Cheers,
M.
--
Academic politics is the most vicious and bitter form of politics,
because the stakes are so low. -- Wallace Sayre
More information about the Python-list
mailing list