-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path250109 Python Coding Conventions.txt
44 lines (34 loc) · 1.55 KB
/
250109 Python Coding Conventions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
1. Code Layout:
• Indentation: Use 4 spaces per indentation level.
• Maximum Line Length: 115 characters
• Blank Lines: Use blank lines to separate functions, classes, and blocks of code within functions.
• Using Black (Hotkey ^K^D) to beautify the code.
2. Naming Conventions:
• Variables and Functions: snake_case.
• Classes: PascalCase (CamelCase).
• Enums and their members: PascalCase (CamelCase).
• Constants: UPPER_CASE_WITH_UNDERSCORES.
• Abstract classes start with an I as Interface.
• class-internal (local) methods start with an underscore.
3. Imports:
• Place imports at the top of the file.
• Group imports into three categories:
1. Standard library imports.
2. Third-party library imports.
3. Local application/library imports.
4. Whitespace:
• Avoid extraneous whitespace in expressions and statements.
• Use a single space around operators and after commas but not inside parentheses.
5. Comments:
• Write comments that are clear, concise, and relevant.
• Use docstrings for documenting public modules, classes, and functions.
6. String Quotes:
• Use double quotes consistently within a project.
7. Exceptions:
• Use try-except blocks for handling exceptions.
8. Miscellaneous:
• Use descriptive variable names.
• Avoid mutable default arguments in functions.
• Type checking in Visual Studio must be set to "strict" (Options/Python/Analysis)
9. Use a Python virtual environment named "env" and use the requirements.txt file to install the required packages.
"env" is git-ignored.