Skip to content

Commit 9d42bc6

Browse files
committed
finish up pep8
1 parent bbe0572 commit 9d42bc6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Diff for: PEP_recommendations/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,40 @@ Make use of indentation when using continuation lines:
9999
def some_other():
100100
pass
101101

102+
1. Encoding: The source file should always use UTF-8 encoding, and preferably without non-ASCII characters. It also makes your code more general if you use English words for identifiers (function names etc.).
103+
104+
1. Imports should be on separate lines:
105+
106+
import os
107+
import sys
108+
109+
and not
110+
111+
import os, sys
112+
113+
1. String quotes: Do either use `'` or `"` throughout your project - do not mix. For triple-quoted strings, always use `"`, so `"""` instead of `'''`.
114+
115+
1. Whitespaces:
116+
- no whitespace in parantheses - do `{item: 1}`, don't ```{ item: 1 }```
117+
- whitespace after comma - do `a, b`, don't `a,b`, but not if followed by a parenthesis - do `(a, b,)` don't `(a, b, )`
118+
- no whitespace before parenthesis - do `calc_this(x)` don't `calc_this (x)`
119+
- no trailing whitespaces
120+
- whitespace around operators (ie. `=, +, +=, ==, is, and`) except for keywords - do `(x=circle)`, don't `(x = circle)`
121+
1. Keep comments up-to-date when changing the code. Comments should be complete sentences with a capitalized first word (unless it is an identifier). Use English language preferably.
122+
1. Include docstrings - see below (PEP 257).
123+
1. Naming conventions:
124+
- package and module names: short all-lowercase, preferably no underscores (do `analysis.py`, don't `Analysis.py`; do `mypackage`, don't `my_package`)
125+
- class names: use CamelCase (do `MyClass`, don't `myclass`, `Myclass`, `MYCLASS`)
126+
- functions and variable names: use lowercase with underscore to increase readibility (do `my_function()`, don't `myfunction()`, `MyFunction()`; do `accuracy_param`, don't `accuracyparam`, `accuracy_PARAM`)
127+
- constants: all capital with separating underscore (do `MIN_THRESHOLD`, don't `Min_Threshold`)
128+
- never use `l, O, I` letter names because of their similarity with `1` and `0`
129+
130+
1. Underscores:
131+
- avoid name clashes using a trailing underscore or synonym (`class_`)
132+
- single leading underscore for methods that should only be used "internally" (should not be made available to the package or class interface)
133+
- use two leading underscores to invoke name mangling for attributes that should not be used in subclasses of the parent class (`__only_parent`)
134+
- double leading and trailing underscores for "magic" objects (dunder methods) - `__init__`, `__str__`
135+
102136

103137
## What is PEP 257?
104138

0 commit comments

Comments
 (0)