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
- Write your custom error only when your error is not described or fulfilled by [internal exceptions](https://docs.python.org/3/library/exceptions.html).
14
14
- Create custom `Exception` class primarily suffixing it with `Error` such as `MyCustomError(Exception)` and use it.
15
15
- Always use `Exception` as your parent class for user defined exceptions. Donot use `BaseException`.
16
-
* Add traceback to you mitigation. i.e. either `logging` or mails. Donot `pass`.
16
+
* Add traceback to your mitigation. i.e. either `logging` or mails. Donot `pass`.
17
17
* The `try` block should be specific to desired exception. Donot use huge code chunk in `try`. Use `else` if needed.
Copy file name to clipboardExpand all lines: docs/python/general.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,7 @@ sidebar_label: General Coding Guidelines
37
37
- i.e. `with` statement when supported.
38
38
- Always remember to close on exit. i.e. if you open the file `close` on `finally` or better use `with` or `contextlib.closing`.
39
39
* While `python` is an OOP, you can always choose `functions` and `modules` over `class` if there is only one `object` to be created.
40
+
* Use `property` setter when writing OOP and you need readonly attributes.
40
41
* Use `pdb` as debugger whenever required.
41
42
* Multi-threading can be especially used when we have io bound and network bound multiple operation. Multiprocessing can be used to use multiple cores.
42
43
- Recommended module is `concurrent.futures` in most cases. If lower level API is needed there is always `threading` and `multiprocessing` module.
-**CRITICAL**: blocking issues or immediate attention issues.
16
16
***ERROR and CRITICAL** levels should be mitigated and informed.
17
-
*`logger` is used for naming single logger. Use `NAME_logger` name for more than one logger when required.
17
+
*`logger` is used for naming single logger object. Use `NAME_logger` name for more than one logger when required.
18
18
* It is singleton and single threaded by default for given name of the logger. Can be [non-blocking](https://docs.python.org/3/howto/logging-cookbook.html#dealing-with-handlers-that-block) if required.
19
19
*[Logging Cookbook](https://docs.python.org/3/howto/logging-cookbook.html) for reference.
20
20
* Always use `exception` method rather than `error` method of `logger` object to log traceback when catching exceptions.
0 commit comments