You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: PEP_recommendations/README.md
+34
Original file line number
Diff line number
Diff line change
@@ -99,6 +99,40 @@ Make use of indentation when using continuation lines:
99
99
def some_other():
100
100
pass
101
101
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__`
0 commit comments