[Python-ideas] Deprecating rarely used str methods
Joshua Landau
joshua at landau.ws
Thu Aug 8 21:17:16 CEST 2013
On 8 August 2013 19:58, MRAB <python at mrabarnett.plus.com> wrote:
> On 08/08/2013 19:32, Serhiy Storchaka wrote:
>>
>> The str class have some very rarely used methods. When was the last time
>> you used swapcase() (not counting the time of apprenticeship)? These
>> methods take place in a source code, documentation and a memory of
>> developers. Due to the large number of methods, some of the really
>> necessary methods can be neglected. I propose to deprecate rarely used
>> methods (especially that for most of them there is another, more obvious
>> way) and remove them in 4.0.
Planning all the way to 4.0?
>> s.ljust(width) == '{:<{}}'.format(s, width) == '%-*s' % (width, s)
>> s.ljust(width, fillchar) == '{:{}<{}}'.format(s, fillchar, width)
>> s.rjust(width) == '{:>{}}'.format(s, width) == '%*s' % (width, s)
>> s.rjust(width, fillchar) == '{:{}>{}}'.format(s, fillchar, width)
>> s.center(width) == '{:^{}}'.format(s, width)
>> s.center(width, fillchar) == '{:{}^{}}'.format(s, fillchar, width)
>>
> You could apply the same kind of reasoning that's used with regex: why
> use .format when .ljust, etc, is shorter and faster?
Because .format (or modulo) is the standard way to format? Honestly
when first scanning this post I had no idea what "ljust" was until I
saw that equivalents were given.
>> str(n).zfill(width) == '{:0={}}'.format(n, width) == '%0*.f' % (width,n)
>>
>> str.swapcase() is just not needed.
>>
> I've never used .swapcase, and I doubt I ever will.
Same
>> str.expandtabs([tabsize]) is rarely used and can be moved to the
>> textwrap module.
>>
> I use it to ensure that indentation is always 4 spaces and never tabs
> in the regex release in case I've missed a setting in an editor
> somewhere, so it _is_ an important method! :-)
Would you be fine with it in textwrap? I don't use this (but I would
use a .reindent method...).
More information about the Python-ideas
mailing list