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: Material_Part1_PEP/README.md
+42-55
Original file line number
Diff line number
Diff line change
@@ -12,35 +12,31 @@ You can find a list of PEPs [here](https://peps.python.org/).
12
12
13
13
## PEP 8 summary
14
14
15
-
1. Line length
15
+
1. Line length
16
16
Don't write lines that are very long. Reason: Often you would use multiple windows next to each other and that makes it hard to read code (and possibly lead to introduction of bugs).
17
17
PEP 8 recommends lines no longer than 79 characters, but 90 is also a good number.
18
18
19
19
1. Alignment of code
20
20
Make use of indentation when using continuation lines:
21
21
22
-
foo = long_function_name(var_one, var_two,
23
-
var_three, var_four)
24
-
22
+
foo = long_function_name(var_one, var_two,
23
+
var_three, var_four)
25
24
instead of
26
25
27
26
foo = long_function_name(var_one, var_two,
28
27
var_three, var_four)
29
-
30
28
You may also use hanging indents
31
29
32
30
foo = long_function_name(
33
31
var_one, var_two,
34
32
var_three, var_four)
35
-
36
33
1. Break line before binary operator
37
34
38
35
income = (gross_wages
39
36
+ taxable_interest
40
37
+ (dividends - qualified_dividends)
41
38
- ira_deduction
42
39
- student_loan_interest)
43
-
44
40
instead of
45
41
46
42
income = (gross_wages +
@@ -50,69 +46,61 @@ Make use of indentation when using continuation lines:
50
46
student_loan_interest)
51
47
52
48
1. Blank lines:
53
-
- two blank lines after `import` statements
54
-
- two blank lines between functions and classes
55
-
- one blank line between methods of classes
49
+
- two blank lines after `import` statements
50
+
- two blank lines between functions and classes
51
+
- one blank line between methods of classes
56
52
57
-
import os
53
+
import os
58
54
59
55
60
-
def greeting():
61
-
print("Hello world!")
56
+
def greeting():
57
+
print("Hello world!")
62
58
63
59
64
-
def goodbye():
65
-
print("See ya!")
66
-
67
-
instead of
60
+
def goodbye():
61
+
print("See ya!")
62
+
instead of
68
63
69
-
import os
70
-
71
-
def greeting():
72
-
print("Hello world!")
64
+
import os
73
65
74
-
def goodbye():
75
-
print("See ya!")
66
+
def greeting():
67
+
print("Hello world!")
76
68
77
-
and
69
+
def goodbye():
70
+
print("See ya!")
71
+
and
78
72
79
-
def something():
80
-
pass
73
+
def something():
74
+
pass
81
75
82
76
83
-
class MyClass:
77
+
class MyClass:
84
78
85
-
def my_method():
86
-
pass
87
-
88
-
def some_other():
89
-
pass
79
+
def my_method():
80
+
pass
90
81
82
+
def some_other():
83
+
pass
91
84
instead of
92
85
93
-
def something():
94
-
pass
95
-
96
-
class MyClass:
97
-
def my_method():
86
+
def something():
98
87
pass
99
-
def some_other():
100
-
pass
101
-
102
88
89
+
class MyClass:
90
+
def my_method():
91
+
pass
92
+
def some_other():
93
+
pass
103
94
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.).
104
-
105
95
1. Imports should be on separate lines:
106
96
107
97
import os
108
98
import sys
109
-
110
99
and not
111
100
112
101
import os, sys
113
102
114
103
1. String quotes: Do either use `'` or `"` throughout your project - do not mix. For triple-quoted strings, always use `"`, so `"""` instead of `'''`.
115
-
116
104
1. Whitespaces:
117
105
- no whitespace in parantheses - do `{item: 1}`, don't ```{ item: 1 }```
118
106
- whitespace after comma - do `a, b`, don't `a,b`, but not if followed by a parenthesis - do `(a, b,)` don't `(a, b, )`
@@ -122,19 +110,18 @@ Make use of indentation when using continuation lines:
122
110
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.
123
111
1. Include docstrings - see below (PEP 257).
124
112
1. Naming conventions:
125
-
- package and module names: short all-lowercase, preferably no underscores (do `analysis.py`, don't `Analysis.py`; do `mypackage`, don't `my_package`)
126
-
- class names: use CamelCase (do `MyClass`, don't `myclass`, `Myclass`, `MYCLASS`)
127
-
- 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`)
128
-
- constants: all capital with separating underscore (do `MIN_THRESHOLD`, don't `Min_Threshold`)
129
-
- never use `l, O, I` letter names because of their similarity with `1` and `0`
130
-
113
+
- package and module names: short all-lowercase, preferably no underscores (do `analysis.py`, don't `Analysis.py`; do `mypackage`, don't `my_package`)
114
+
- class names: use CamelCase (do `MyClass`, don't `myclass`, `Myclass`, `MYCLASS`)
115
+
- 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`)
116
+
- constants: all capital with separating underscore (do `MIN_THRESHOLD`, don't `Min_Threshold`)
117
+
- never use `l, O, I` letter names because of their similarity with `1` and `0`
131
118
1. Underscores:
132
-
- avoid name clashes using a trailing underscore or synonym (`class_`)
133
-
- single leading underscore for methods that should only be used "internally" (should not be made available to the package or class interface)
134
-
- use two leading underscores to invoke name mangling for attributes that should not be used in subclasses of the parent class (`__only_parent`)
135
-
- double leading and trailing underscores for "magic" objects (dunder methods) - `__init__`, `__str__`
119
+
- avoid name clashes using a trailing underscore or synonym (`class_`)
120
+
- single leading underscore for methods that should only be used "internally" (should not be made available to the package or class interface)
121
+
- use two leading underscores to invoke name mangling for attributes that should not be used in subclasses of the parent class (`__only_parent`)
122
+
- double leading and trailing underscores for "magic" objects (dunder methods) - `__init__`, `__str__`
136
123
137
-
**Task 1: Let's take a look at some [examples](./PEP_right_or_wrong).**
124
+
**Task 1: Let's take a look at some [examples](./PEP_right_or_wrong.md).**
138
125
139
126
**Task 2: Work through the examples [in this folder](.). Correct the issues and (i) stage, commit and push the changes to your fork of the course repo, then open a pull request with respect to the original repository - then I can see the changes. (ii) Send me your changed files via email.**
140
127
@@ -146,4 +133,4 @@ Make use of indentation when using continuation lines:
146
133
147
134
## PEP 20
148
135
149
-
The Zen of Python. Type `import this` in your Python console.
136
+
The Zen of Python. Type `import this` in your Python console.
0 commit comments