[issue25034] string.Formatter accepts empty fields but displays wrong when nested
Anthon van der Neut
report at bugs.python.org
Tue Sep 8 21:23:13 CEST 2015
New submission from Anthon van der Neut:
Since 3.4.1, string.Formatter() accepts empty keys {}. If these are nested they give different results from explicitly numbered, where the same arguments applied "".format() give the expected results:
from string import Formatter
f = Formatter()
fmt0 = "X {:<{}} {} X"
fmt1 = "X {0:<{1}} {2} X"
for fmt in [fmt0, fmt1]:
x = f.format(fmt, 'ab', 5, 1)
y = fmt.format( 'ab', 5, 1)
print(x)
print(y)
gives:
X ab 5 X
X ab 1 X
X ab 1 X
X ab 1 X
of which the first line is incorrect.
----------
components: Library (Lib)
messages: 250253
nosy: anthon
priority: normal
severity: normal
status: open
title: string.Formatter accepts empty fields but displays wrong when nested
type: behavior
versions: Python 3.4, Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25034>
_______________________________________
More information about the Python-bugs-list
mailing list