[Python-3000] Please don't kill the % operator...

Steven Bethard steven.bethard at gmail.com
Thu Aug 16 22:29:31 CEST 2007


On 8/16/07, skip at pobox.com <skip at pobox.com> wrote:
>
>     STeVe> I honestly can't see the point of keeping this::
>
>     >>>> '%-10s bought %02i apples for %3.2f' % ('John', 8, 3.78)
>     STeVe>     'John       bought 08 apples for 3.78'
>
>     STeVe> alongside this::
>
>     >>>> '{0:-10} bought {1:02i} apples for {2:3.2f}'.format('John', 8, 3.78)
>     STeVe>     'John       bought 08 apples for 3.78'
>
>     STeVe> They're so similar I don't see why you think the latter is no
>     STeVe> longer "easy and powerful".
>
> You mean other than:
>
>    * the new is more verbose than the old
>    * the curly braces and [012]: prefixes are just syntactic sugar when
>      converting old to new
>    * in situations where the format string isn't a literal that mechanical
>      translation from old to new won't be possible
>    * lots of people are familiar with the old format, few with the new
>
> ?

As I understand it, it's already been decided that {}-style formatting
will be present in Python 3.  So the question is not about the merits
of {}-style formatting vs. %-style formatting.  That debate's already
been had.  The question is whether it makes sense to keep %-style
formatting around when {}-style formatting is so similar.

Since %-style formatting saves at most a couple of characters per
specifier, that doesn't seem to justify the massive duplication to me.

STeVe
-- 
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
        --- Bucky Katt, Get Fuzzy


More information about the Python-3000 mailing list