The Guide Style Guide

https://d33wubrfki0l68.cloudfront.net/a7189f408d8a30ded6f6203120a926ed5d088478/4a254/_images/33573755856_7f43d43adf_k_d.jpg
As with all documentation, having a consistent format helps make thedocument more understandable. In order to make The Guide easier to digest,all contributions should fit within the rules of this style guide whereappropriate.

The Guide is written as reStructuredText.

Note

Parts of The Guide may not yet match this style guide. Feel freeto update those parts to be in sync with The Guide Style Guide

Note

On any page of the rendered HTML you can click “Show Source” tosee how authors have styled the page.

Relevancy

Strive to keep any contributions relevant to the purpose of The Guide.

  • Avoid including too much information on subjects that don’t directlyrelate to Python development.
  • Prefer to link to other sources if the information is already out there.Be sure to describe what and why you are linking.
  • Citereferences where needed.
  • If a subject isn’t directly relevant to Python, but useful in conjunctionwith Python (e.g., Git, GitHub, Databases), reference by linking to usefulresources, and describe why it’s useful to Python.
  • When in doubt, ask.

Headings

Use the following styles for headings.

Chapter title:

  1. #########
  2. Chapter 1
  3. #########

Page title:

  1. *******************
  2. Time is an Illusion
  3. *******************

Section headings:

  1. Lunchtime Doubly So
  2. ===================

Sub section headings:

  1. Very Deep
  2. ---------

Prose

Wrap text lines at 78 characters. Where necessary, lines may exceed 78characters, especially if wrapping would make the source text more difficultto read.

Use Standard American English, not British English.

Use of the serial comma(also known as the Oxford comma) is 100% non-optional. Any attempt tosubmit content with a missing serial comma will result in permanent banishmentfrom this project, due to complete and total lack of taste.

Banishment? Is this a joke? Hopefully we will never have to find out.

Code Examples

Wrap all code examples at 70 characters to avoid horizontal scrollbars.

Command line examples:

  1. .. code-block:: console
  2.  
  3. $ run command --help
  4. $ ls ..

Be sure to include the $ prefix before each line.

Python interpreter examples:

  1. Label the example::
  2.  
  3. .. code-block:: python
  4.  
  5. >>> import this

Python examples:

  1. Descriptive title::
  2.  
  3. .. code-block:: python
  4.  
  5. def get_answer():
  6. return 42

Externally Linking

  • Prefer labels for well known subjects (e.g. proper nouns) when linking:
  1. Sphinx_ is used to document Python.
  2.  
  3. .. _Sphinx: http://sphinx.pocoo.org
  • Prefer to use descriptive labels with inline links instead of leaving barelinks:
  1. Read the `Sphinx Tutorial <http://sphinx.pocoo.org/tutorial.html>`_
  • Avoid using labels such as “click here”, “this”, etc., preferringdescriptive labels (SEO worthy) instead.

Linking to Sections in The Guide

To cross-reference other parts of this documentation, use the :ref:keyword and labels.

To make reference labels more clear and unique, always add a -ref suffix:

  1. .. _some-section-ref:
  2.  
  3. Some Section
  4. ------------

Notes and Warnings

Make use of the appropriate admonitions directives when making notes.

Notes:

  1. .. note::
  2. The Hitchhikers Guide to the Galaxy has a few things to say
  3. on the subject of towels. A towel, it says, is about the most
  4. massively useful thing an interstellar hitch hiker can have.

Warnings:

  1. .. warning:: DON'T PANIC

TODOs

Please mark any incomplete areas of The Guide with a todo directive. Toavoid cluttering the Todo List, use a single todo for stubdocuments or large incomplete sections.

  1. .. todo::
  2. Learn the Ultimate Answer to the Ultimate Question
  3. of Life, The Universe, and Everything

原文: https://docs.python-guide.org/notes/styleguide/