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

Brett Cannon brett at python.org
Thu Aug 16 21:05:57 CEST 2007


[Tonight, the role of old, cranky python-dev'er will be played by
Brett Cannon.  Don't take this personally, Christian, your email just
happened to be last.  =)]

On 8/16/07, Christian Heimes <lists at cheimes.de> wrote:
> skip at pobox.com wrote:
> >     Alex> The PEP abstract says this proposal will replace the '%' operator,
>
> [...]
>
> I agree with Skip, too. The % printf operator is a very useful and
> powerful feature. I'm doing newbie support at my university and in
> #python. Newbies are often astonished how easy and powerful printf() is
> in Python. I like the % format operator, too. It's easy and fast to type
> for small jobs.
>

But how is::

  "{0} is happy to see {1}".format('Brett', 'Christian')

that less easier to read than::

  "%s is happy to see %s" % ('Brett', 'Christian')

?  Yes, PEP 3101 style is more to type but it isn't grievous; we have
just been spoiled by the overloading of the % operator.  And I don't
know how newbies think these days, but I know I find the numeric
markers much easier to follow then the '%s', especially if the string
ends up becoming long.

And if it is the use of a method instead of an operator that the
newbies might have issues with, well methods and functions come up
quick so they probably won't go long without knowing what is going on.

> I beg you to keep the feature. I agree that the new PEP 3101 style
> format is useful and required for more complex string formating. But
> please keep a simple one for simple jobs.

This is where the cranky python-dev'er comes in: PEP 3101 was
published in April 2006 which is over a year ago!  This is not a new
PEP or a new plan.  I personally stayed out of the discussions on this
subject as I knew reasonable people were keeping an eye on it and I
didn't feel I had anything to contribute.  That means I just go with
what they decide whether I like it or not.

I understand the feeling of catching up on a thread and going, "oh no,
I don't like that!", but that is the nature of the beast.  In my view,
if you just don't have the time or energy (which I completely
understand not having, don't get me wrong) for a thread, you basically
have to defer to the people who do and trust that the proper things
were discussed and that the group as a whole (or Guido in those cases
where his gut tells him to ignore everyone) is going to make a sound
decision.

At this point the discussion has gone long enough with Guido
participating and agreeing with key decisions, that the only way to
get this course of action changed is to come up with really good
examples of how the % format is hugely better than PEP 3101 and
convince the people involved.  But just saying you like %s over {0} is
like saying you don't like the decorator syntax: that's nice and all,
but that is not a compelling reason to change the decision being made.

-Brett


More information about the Python-3000 mailing list