Skip to content

Commit 693aade

Browse files
author
Kenneth Reitz
committed
Merge pull request realpython#29 from kisielk/style
Wrote up the idioms section
2 parents 357d3a0 + 422ba2e commit 693aade

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

docs/writing/code-style.rst

Lines changed: 0 additions & 14 deletions
This file was deleted.

docs/writing/style.rst

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,50 @@ Code Style
55
Idioms
66
::::::
77

8+
Idiomatic Python code is often referred to as being *pythonic*.
9+
810

911
Zen of Python
1012
-------------
1113

14+
Also known as PEP 20, the guiding principles for Python's design.
15+
16+
::
17+
18+
>>> import this
19+
20+
See `<http://stackoverflow.com/questions/228181/the-zen-of-python>`_ for some
21+
examples.
22+
23+
PEP 8
24+
-----
25+
26+
PEP 8 is the de-facto code style guide for Python.
27+
28+
`PEP 8 <http://www.python.org/dev/peps/pep-0008/>`_
29+
30+
There exists a command-line program, `pep8` that can check your code for
31+
conformance.
32+
33+
::
34+
35+
pip install pep8
36+
37+
38+
Simply run it on a file or series of files and get a report of any
39+
violations
40+
41+
::
42+
43+
$ pep8 optparse.py
44+
optparse.py:69:11: E401 multiple imports on one line
45+
optparse.py:77:1: E302 expected 2 blank lines, found 1
46+
optparse.py:88:5: E301 expected 1 blank line, found 0
47+
optparse.py:222:34: W602 deprecated form of raising exception
48+
optparse.py:347:31: E211 whitespace before '('
49+
optparse.py:357:17: E201 whitespace after '{'
50+
optparse.py:472:29: E221 multiple spaces before operator
51+
optparse.py:544:21: W601 .has_key() is deprecated, use 'in'
1252

13-
PEP-8
14-
-----
53+
Conforming your style to PEP 8 is generally a good idea and helps make code a lot
54+
more consistent when working on projects with other developers.

0 commit comments

Comments
 (0)