[Python-ideas] Deprecating rarely used str methods

M.-A. Lemburg mal at egenix.com
Thu Aug 8 21:16:27 CEST 2013


On 08.08.2013 20: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.
> 
> 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)
>
> str(n).zfill(width) == '{:0={}}'.format(n, width) == '%0*.f' % (width,n)

I don't think any of the .format() alternatives you listed is
anywhere near as obvious as the methods :-)

> str.swapcase() is just not needed.

If you have you ever typed on a keyboard with shift lock enabled,
you'd know what it's needed for ;-)

Seriously, that one could get deprecated, provided that a helper
function with the same functionality is provided elsewhere.

> str.expandtabs([tabsize]) is rarely used and can be moved to the textwrap module.

TABs still exist in lots of files, so I'd rather not get rid
of this method.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Aug 08 2013)
>>> Python Projects, Consulting and Support ...   http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ...       http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


More information about the Python-ideas mailing list