[Python-Dev] transitioning from % to {} formatting (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Wed Sep 30 18:48:16 CEST 2009


There's a lot of code already out there (in the standard library and other places) that uses %-style formatting, when in Python 3.0 we should be encouraging {}-style formatting.

I don't agree that we should do that. I see nothing wrong with using % substitution. It's a maintenance burden.

Well - that's the cost of keeping it in the language. It's not a problem with using it while it is in the language.

So if a decision was made to eventually remove % formatting, it would be reasonable to start migrating code to PEP 3101. However, no such decision has been made (and hopefully won't be throughout 3.x), so as the mechanism is available, there is no need to start changing existing code (except the for actual issue Steven discusses, namely libraries that expect strings in % template form).

I'd note that PEP 3101 calls str.format() a replacement for %-formatting, not an alternate mechanism to achieve the same end.

I think this is a mis-wording; the intent of the PEP apparently is to propose this mechanism as an option, not as an actual replacement. This becomes clear when reading the "Backwards Compatibility" section:

Backwards compatibility can be maintained by leaving the existing

mechanisms in place. The new system does not collide with any of

the method names of the existing string formatting techniques, so

both systems can co-exist until it comes time to deprecate the

older system.

Regards, Martin



More information about the Python-Dev mailing list