[issue9139] Add examples for str.format()

Eric Smith report at bugs.python.org
Fri Jul 2 16:23:42 CEST 2010


Eric Smith <eric at trueblade.com> added the comment:

Thanks for taking the lead on this.

In this sentence:
+The new format syntax also supports new and different options, showed in the
+follow examples.
"showed" should be "shown".

I like to use an example showing attribute access on named types. Barry Warsaw suggested using "self", which is a great tip. It's hard to come up with a complete example, but something that ends up like:
  "x is {self.x}, y is {self.y}".format(self=self)

I think it would be a good idea to show comma formatting (even with its limitations), since there's not another easy way to do that in Python:
>>> '{:,}'.format(1234567890)
'1,234,567,890'

For datetime, something like:
>>> import datetime
>>> d = datetime.datetime(2010, 7, 4, 12, 15, 58)
>>> '{:%Y-%m-%d %H:%M:%S}'.format(d)
'2010-07-04 12:15:58'

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9139>
_______________________________________


More information about the Python-bugs-list mailing list