[Python-ideas] String formatting and namedtuple

Jim Jewett jimjjewett at gmail.com
Wed Feb 18 01:38:16 CET 2009

On 2/17/09, Eric Smith <eric at trueblade.com> wrote:

> The one issue that's causing me problems is what to do with format
> specifiers that themselves need expanding.

>  >>> '{0:>{1}}'.format('foo', 5)
> '  foo'

> Should:
>  >>> '{:{}}'.format('foo', 5)

> produce the same output, or should it be an error? I think it should
> probably work, but it complicates the implementation sufficiently that I
> probably won't be able to finish it up for a couple of weeks.

> I know this is a not-so-useful corner case, but the implementation has
> to do something here. I could easily throw an exception, but I don't see
> how that's more desirable than just making it work.

Then go ahead and throw an exception; it can always be made legal later.

In 2.4, the original decorator patch applied to classes as well as
functions.  The restriction to only functions was made because the use
case for classes wasn't as clear-cut, and it is much easier (from a
policy standpoint) to add functionality than to take it away.  (The
restriction was removed in 2.6.)

Those extra .format extensions would *probably* be useful, but there
is little harm in waiting another month (or even another two releases)
before adding them.


More information about the Python-ideas mailing list