[docs] Suggestion for improving {} vs {:s} in Format Specification Mini-Language

Horshack Horshack horshack at live.com
Mon Oct 5 21:23:02 CEST 2015

In the 3.x documentation for the format string specification https://docs.python.org/3/library/string.html#formatspec, the string representation table indicates that 's' and None are the same - {} vs {:s} for example. In practice the two are different with respect to how the argument is converted, which is especially important for objects that have no __format__ method defined. In 2.7x an object's __str__ method is called if there is no __format__ method, even if a format string like {:s} is specified. In 3.x if there is no __format__ method and any format string is specified, including just {:s}, a TypeError exception is thrown for a "non-empty format string passed to object.__format__". This difference may be documented elsewhere since it's not a format-string specific behavior pe-se but it would very helpful for those learning Python to reference this difference in the 3.x format string documentation as well, esp since the existing documentation's statement that the two are the same may be confusing to readers who see the different behavior between {} and {:s} on 2.7 vs 3.x, the latter causing an exception on 3.x



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20151005/6044850c/attachment.html>

More information about the docs mailing list