Removing some string methods?
![](https://secure.gravatar.com/avatar/e2cb0083d4d61cebb1325281f88f3843.jpg?s=120&d=mm&r=g)
Has any consideration been given to removing some of the lesser-used string methods in 3.0? e.g. .center, .ljust/rjust, .zfill, .swapcase? --amk
![](https://secure.gravatar.com/avatar/e8600d16ba667cc8d7f00ddc9f254340.jpg?s=120&d=mm&r=g)
On Tue, May 13, 2008 at 10:05 AM, A.M. Kuchling <amk@amk.ca> wrote:
Has any consideration been given to removing some of the lesser-used string methods in 3.0? e.g. .center, .ljust/rjust, .zfill, .swapcase?
Don't remember any specifically coming up. But are you sure those are really lesser-used? I can remember using ljust, rjust, and zfill on multiple occasions. Have you tried looking at the stdlib or something to get usage stats? -Brett
![](https://secure.gravatar.com/avatar/bc2071afd499daef001e75e14d7f9cce.jpg?s=120&d=mm&r=g)
[AMK]
Has any consideration been given to removing some of the lesser-used string methods in 3.0? e.g. .center, .ljust/rjust, .zfill, .swapcase?
I don't think we gain anything by taking justification and centering methods away. It just makes life difficult for people like me who use those methods for formatting text. Also, these methods have nearly zero mental overhead -- they are self-explanatory and have no learning curve. The swapcase() method is more use case challenged and could probably be zapped without anyone caring. The zfill() method is no longer necessary because rjust() takes an optional fillchar argument: '123'.zfill(10) == '123'.rjust(10, '0') Raymond
![](https://secure.gravatar.com/avatar/e2cb0083d4d61cebb1325281f88f3843.jpg?s=120&d=mm&r=g)
On Fri, May 16, 2008 at 12:36:17PM -0700, Raymond Hettinger wrote:
I don't think we gain anything by taking justification and centering methods away. It just makes life difficult for people like me who use those methods for formatting text. Also, these methods have nearly zero mental overhead -- they are self-explanatory and have no learning curve.
Fair enough.
The swapcase() method is more use case challenged and could probably be zapped without anyone caring.
I did a Google code search, and outside of Python test suites and the other implementations, I found exactly two uses of swapcase. --amk
![](https://secure.gravatar.com/avatar/e8600d16ba667cc8d7f00ddc9f254340.jpg?s=120&d=mm&r=g)
On Fri, May 16, 2008 at 12:36 PM, Raymond Hettinger <python@rcn.com> wrote:
[AMK]
Has any consideration been given to removing some of the lesser-used string methods in 3.0? e.g. .center, .ljust/rjust, .zfill, .swapcase?
I don't think we gain anything by taking justification and centering methods away. It just makes life difficult for people like me who use those methods for formatting text. Also, these methods have nearly zero mental overhead -- they are self-explanatory and have no learning curve.
The swapcase() method is more use case challenged and could probably be zapped without anyone caring.
The zfill() method is no longer necessary because rjust() takes an optional fillchar argument:
'123'.zfill(10) == '123'.rjust(10, '0')
Ah cool! I don't think I knew about that because I always knew about zfill(). Probably would have found it if I zfill() didn't exist. So for Python 3.1 we can probably safely ditch the two methods (and probably review the methods on the other types as well). -Brett
![](https://secure.gravatar.com/avatar/7f37d34f3bb0e91890c01450f8321524.jpg?s=120&d=mm&r=g)
On Fri, May 16, 2008 at 10:16 PM, Brett Cannon <brett@python.org> wrote:
On Fri, May 16, 2008 at 12:36 PM, Raymond Hettinger <python@rcn.com> wrote:
[AMK]
Has any consideration been given to removing some of the lesser-used string methods in 3.0? e.g. .center, .ljust/rjust, .zfill, .swapcase?
I don't think we gain anything by taking justification and centering methods away. It just makes life difficult for people like me who use those methods for formatting text. Also, these methods have nearly zero mental overhead -- they are self-explanatory and have no learning curve.
The swapcase() method is more use case challenged and could probably be zapped without anyone caring.
The zfill() method is no longer necessary because rjust() takes an optional fillchar argument:
'123'.zfill(10) == '123'.rjust(10, '0')
Ah cool! I don't think I knew about that because I always knew about zfill(). Probably would have found it if I zfill() didn't exist.
So for Python 3.1 we can probably safely ditch the two methods (and probably review the methods on the other types as well).
-Brett
zfill and rjust are not the same. zfill treats it as a number and moves the sign.
e = b'-33' e.zfill(7) b'-000033' e.rjust(7, '0') b'0000-33'
participants (4)
-
A.M. Kuchling
-
Brett Cannon
-
Gregory P. Smith
-
Raymond Hettinger