This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: format library documentation error
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Arthur-Milchior, docs@python, eric.smith, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2021-12-15 17:48 by Arthur-Milchior, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30126 closed Arthur-Milchior, 2021-12-15 17:55
Messages (4)
msg408624 - (view) Author: Arthur Milchior (Arthur-Milchior) * Date: 2021-12-15 17:48
I don't have permission to assign the issue, but I intend to post the change in a few minutes as a PR

Copied from Richard Hyde's email to doc mailing list.

One of the examples of string formatting doesn't work. This applies to prior versions of Python as well.

The last set of the examples headed: 'Nesting arguments and more complex examples:' starts with the following code:

>>> for align, text in zip('<^>', ['left', 'center', 'right']):
...     '{0:{fill}{align}16}'.format(text, fill=align, align=align)
...

This omits print()
The correct code would be:

>>> for align, text in zip('<^>', ['left', 'center', 'right']):
...     print('{0:{fill}{align}16}'.format(text, fill=align, align=align))
...



-----------------------------------------------

I agree with Richard here that there is a problem. Most example don't use print, but since there is no returned expression, that's the most relevant way to express the meaning of the example. Adding an expression would just make things more complex.

Bug introducde in 28fbea412819f90698527c1997ece5aeddf8e9a7 in 2010.
msg408628 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-12-15 18:03
Since it is a REPL example, no print() is needed. In REPL any expression statement prints the repr of its result. For example:

>>> for x in range(1, 5):
...     f'{x}**2 = {x**2}'
... 
'1**2 = 1'
'2**2 = 4'
'3**2 = 9'
'4**2 = 16'

There are many such examples in the documentation, and I do not think that this particular example needs a change.
msg408630 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-12-15 18:09
Good point, Serhiy. I also don't see how the proposed change is related to any zip documentation (which is in the title of this issue).

I suggest closing this.
msg408631 - (view) Author: Arthur Milchior (Arthur-Milchior) * Date: 2021-12-15 18:10
ipypthon3 does not print the loop content. python3 does. I only tested with ipython. I beg your pardon. I didn't know about this difference in behavior
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90245
2021-12-15 18:15:25serhiy.storchakasetstatus: open -> closed
nosy: + eric.smith

resolution: not a bug
stage: patch review -> resolved
2021-12-15 18:10:32Arthur-Milchiorsetnosy: - eric.smith

messages: + msg408631
title: Zip library documentation error -> format library documentation error
2021-12-15 18:09:12eric.smithsetnosy: + eric.smith
messages: + msg408630
2021-12-15 18:05:36eric.smithsetversions: - Python 3.6, Python 3.7, Python 3.8
2021-12-15 18:03:17serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg408628
2021-12-15 17:55:20Arthur-Milchiorsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28345
2021-12-15 17:48:58Arthur-Milchiorcreate