[Python-3000] Please don't kill the % operator...
barry at python.org
Thu Aug 16 15:43:29 CEST 2007
-----BEGIN PGP SIGNED MESSAGE-----
On Aug 16, 2007, at 8:29 AM, skip at pobox.com wrote:
> Alex> The PEP abstract says this proposal will replace the '%'
> I hope this really doesn't happen. printf-style formatting has a long
> history both in C and Python and is well-understood. Its few
> are mostly due to the binary nature of the % operator, not to the
> power or
> flexibility of the format strings themselves. In contrast, the new
> "language" seems to have no history (is it based on features in other
> languages? does anyone know if it will actually be usable in common
> practice?) and at least to the casual observer of recent threads on
> topic seems extremely baroque.
> Python has a tradition of incorporating the best ideas from other
> String formatting is so common that it doesn't seem to me we should
> need to
> invent a new, unproven mechanism to do this.
There are two parts to this, one is the language you use to define
formatting and the other is the syntax you use to invoke it. I've
been mostly ignoring the PEP 3101 discussions because every time I
see examples of an advanced format string I shudder and resign myself
to never remembering how to use it. It certainly doesn't feel like
it's going to fit /my/ brain.
OTOH, I'm not saying that a super whizzy all-encompassing inscrutable-
but-powerful format language is a bad thing for Python, but it may
not be the best /default/ language for formatting. OTOH, I don't
think the three different formatting languages need three different
syntaxes to invoke them.
The three formatting languages are, in order of decreasing simplicity
and familiarity, but increasing power:
- - PEP 292 $-strings
- - Python 2 style % substitutions
- - PEP 3101 format specifiers
I think all three languages have their place, but I would like to see
if there's some way to make spelling their use more consistent. Not
that I have any great ideas on that front, but I think the proposals
in PEP 3101 (which I've only skimmed) are tied too closely to the
latter format language.
While I agree with Skip's sentiment, I'd say that it's not the %-
operator I care as much about as it is the middle road that the
formatting language it uses takes. For example, the logging package
uses the same language but exposes a better (IMO) way to spell its use:
>>> log.info('User %s ate %s', user, food)
So the question is, is there some way to unify the use of format
strings in the three different formatting languages, giving equal
weight to each under the acknowledgment that all three use cases are
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
-----END PGP SIGNATURE-----
More information about the Python-3000