[issue9139] Add examples for str.format()
Éric Araujo mer...@netwok.org added the comment: The examples seem good to me after a quick reading. There’s not too much but still enough. I find the phrasing of the versionchanged not easily understandable: “The position of the arguments can now be omitted.” Clearer and probably too verbose: “When using numeric placeholders that follow the order of the positional arguments, you can omit the numbers: '{} {!s}' is equivalent to '{0} {1!s}'” -- nosy: +merwok ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9139 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9139] Add examples for str.format()
Eric Smith e...@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 rep...@bugs.python.org http://bugs.python.org/issue9139 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9139] Add examples for str.format()
Eric Smith e...@trueblade.com added the comment: Instead of named types, I meant named arguments, of course. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9139 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9139] Add examples for str.format()
Ezio Melotti ezio.melo...@gmail.com added the comment: Here is a new patch. I fixed the typos, removed the examples from the first section and added a link to the examples section. I also added the examples suggested by Eric plus an example about {:%}, and followed the suggestion of Éric and clarified the versionchanged message. -- Added file: http://bugs.python.org/file17840/issue9139v2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9139 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9139] Add examples for str.format()
Changes by Mark Dickinson dicki...@gmail.com: -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9139 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9139] Add examples for str.format()
Eric Smith e...@trueblade.com added the comment: This looks like a definite improvement to me. When you merge to py3k, don't forget to change the versionchanged tag to 3.1. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9139 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9139] Add examples for str.format()
Éric Araujo mer...@netwok.org added the comment: I’m not sure it’s good style to say “now” twice (in the versionchanged block). I almost feel bad pointing that there is one line with bad whitespace: +for align,text in ... (Space after comma) Otherwise great patch :) -- resolution: - accepted ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9139 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9139] Add examples for str.format()
Eric Smith e...@trueblade.com added the comment: I think I'd just delete both instances of now. And now that I read it more critically, position should be positional. How's this rewording: .. versionchanged:: 2.7 The positional argument specifiers can be omitted, so ``'{} {}'`` is equivalent to ``'{0} {1}'``. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9139 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9139] Add examples for str.format()
Ezio Melotti ezio.melo...@gmail.com added the comment: Here is another patch. I also added another example that uses the fillchar. -- Added file: http://bugs.python.org/file17843/issue9139v3.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9139 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9139] Add examples for str.format()
Eric Smith e...@trueblade.com added the comment: Looks good. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9139 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9139] Add examples for str.format()
Ezio Melotti ezio.melo...@gmail.com added the comment: Committed in r82457 and r82459 (trunk), r82460 (release26-maint), r82462 (py3k), r82463 (release31-maint). Thanks for the reviews! -- resolution: accepted - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9139 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9139] Add examples for str.format()
New submission from Ezio Melotti ezio.melo...@gmail.com: The attached patch adds a section with examples about str.format() after http://docs.python.org/library/string.html#format-specification-mini-language . The patch needs some small improvements: 1) the examples in the previous sections could be removed and/or a link to the new section could be added; 2) the last example could be improved; 3) another example using custom formats (e.g. for datetime) should be added; I'd like to have this in 2.7 (Benjamin said it's OK), please review. -- assignee: ezio.melotti components: Documentation files: issue9139.diff keywords: patch messages: 109087 nosy: benjamin.peterson, eric.smith, ezio.melotti priority: high severity: normal stage: patch review status: open title: Add examples for str.format() versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2 Added file: http://bugs.python.org/file17833/issue9139.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9139 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com