[Python-ideas] Deprecating rarely used str methods
Terry Reedy
tjreedy at udel.edu
Mon Aug 12 00:50:45 CEST 2013
On 8/11/2013 5:48 PM, Alexander Belopolsky wrote:
>
>
>
> On Sun, Aug 11, 2013 at 5:14 PM,
> <random832 at fastmail.us
> <mailto:random832 at fastmail.us>> wrote:
>
> ..
>
> What exactly was the sufficient grounds for adding str.format, and for
> giving it its own minilanguage instead of using the one % already uses
> [with extensions like being able to use both positional arguments and
> %(keyword)s, and maybe something like %1$s for explicit positional
> arguments]?
>
>
> http://www.python.org/dev/peps/pep-3101/
To add to that, the special treatment of tuples and sometimes dicts lead
to bugs or unexpected exceptions.
>>> '%s' % [1,]
'[1]'
>>> '%s' % (1,)
'1'
>>> '%s' % [1,2,3]
'[1, 2, 3]'
>>> '%s' % (1,2,3)
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
'%s' % (1,2,3)
TypeError: not all arguments converted during string formatting
--
Terry Jan Reedy
More information about the Python-ideas
mailing list