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: Cleanup sample code spacing and block arrangement in tutorial.
Type: Stage:
Components: Documentation Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eric.araujo, georg.brandl, methane, rhettinger
Priority: normal Keywords: patch

Created on 2011-03-07 05:44 by methane, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cleanup_tutorial_codes.patch methane, 2011-03-07 05:44 review
Messages (5)
msg130225 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2011-03-07 05:44
* Insert spaces around operators and after commas.
* Split one liner blocks (ex. def foo(x, y): return x + y) to
  multi-line blocks.
* Insert empty line after def block for scripts (not interactive mode).
* Use new-style raise (s/ralse KeyboardInterrupt/raise KeyboardInterrupt()/)
* Use x ** 3 instead of x * x * x.

Attached patch is for Python 2.6.
I'll make same changes for Python 3.1 if this patch is accepted.
msg130227 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2011-03-07 06:16
This patch inserts spaces around ** operator but I prefer no spaces around **.
Any thoughts?
msg130230 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-03-07 07:14
Sorry, but I think many of these changes should not be made.

Sometime the tight spacing is used for visual grouping.  The following look fine and should not be changed because adding spaces around the + or * operator makes the whole sentence harder to mentally parse correctly:

   sum(x*y for x,y in zip(xvec, yvec))
   a, b = b, a+b

Also, it is perfectly correct to use:
   raise StopIteration
We use the parentheses when there is an argument:
   raise KeyError('key not found: {!r}'.format(k))

Sometimes one-liners are okay in the interactive mode for quick filter functions and whatnot.  Spreading them out with '...' lines makes the example harder to follow and expands the set-up part of the example rather than the part being explained.

It's perfectly valid to use x * x * x instead of x**3 in an example of how to use map.  We want the example to be as simple as possible.  

Also, the interactive prompt examples should be left as-is.  They communicate the free-form nature of experimentation at the prompt.
msg130234 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-03-07 07:33
I made the c -> cls change in 88fe1ac48460. Some other fixes have already been made in py3k (like removing the duplicate index keyword), and for the others I completely agree with Raymond.
msg130248 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-03-07 10:59
Just two notes: The operations like “7205759403792794 * 10**30 / 2**56” in floatimport could use some parens; the patch removed a duplicate “statement: for” entry.
History
Date User Action Args
2022-04-11 14:57:14adminsetgithub: 55634
2020-05-14 05:51:20Chas Belovsettitle: Cleanup sample codes in tutorial. -> Cleanup sample code spacing and block arrangement in tutorial.
2011-03-07 10:59:32eric.araujosetnosy: + eric.araujo
messages: + msg130248
2011-03-07 07:33:27georg.brandlsetresolution: rejected -> fixed

messages: + msg130234
nosy: + georg.brandl
2011-03-07 07:14:07rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg130230

resolution: rejected
2011-03-07 06:16:24methanesetnosy: methane, docs@python
messages: + msg130227
2011-03-07 05:44:52methanecreate