%-style formatting method

Yes, please. I would fully support this.

I personally will want to use %-placeholders for a very long time (til the day I die, perhaps?!), no matter what anyone else says - but I will be the first to say I never liked the %-operator.

Introducing the str.pformat() method, and immediately updating docs exactly as you suggest, would certainly make me happy, and in the long term it might even allow for str.__mod__ to be outright removed, solving the original problem raised in Deprecate str % format operator.

It does solve the “single tuple argument” problem, but putting together what has already been expressed in several separate posts above:

  • it has to be added to everyone’s codebase;
  • it’s inconsistent with str.format being a method; and
  • it doesn’t provide a nice clear visual separator between format-string and args.

IMO the last reason here is why I don’t already use this solution. I’d prefer str.pformat over str.__mod__, but I’d prefer sticking with str.__mod__ over adding this function everywhere.

1 Like