Disclaimer: This is an independently created repository for educational purposes. It is not affiliated with, * endorsed by*, or officially associated with the author or publisher.
This repository is inspired by the book Effective Python: 90 Specific Ways to Write Better Python by Brett Slatkin.
The code examples and structure are based on concepts and ideas from the book, but do not copy the original content verbatim. It aims to help others understand and internalize the material by presenting re-implemented examples, interpretations, and explanations.
- To serve as a personal learning log and reference.
- To help others reinforce their understanding of Python best practices.
- To encourage support for the author and promote the original work.
If you find this helpful, please consider buying the book to support the author:
- Python version Know your python version. Migrate legacy v2 code to v3 using available tools. Use version 3 in new projects.
- PEP-8 Apply best practices in python code style. Use linters to support your cause.
- Bytes and Strings They may look the same on the output, but the internal handling in memory and on filesystems can be quite different. Respect encodings. Bytes are 8-bit values, instances of str are arrays of Unicode chars. Reading and writing from / to filesystems has to account for binary data streams and respect encodings.
- String formatting Python offers many (legacy) means to format strings, i.a., C-strings, format
function and Python F-strings. Each with pros and cons. Be aware on when to use which method, e.g., in logging,
terminal output, file operations. F-strings are available since
python>=3.6. - Readable functions Follow DRY principle (don't repeat yourself). Prefer explicit and readable statements over crafty obfuscated one-liners. Use of if/else can improve readability compared to boolean operators and/or.
- List unpacking Apply unpacking techniques to prevent excessive use of indices which can hurt readability. Some risk exists in confusing unpacking with assignment due to identical operator symbol.
This project is released under the MIT License. See LICENSE.md for details.
See COPYRIGHT.md for copyright and attribution information.