# Video ![5 Good Python Habits](https://www.youtube.com/watch?v=9tC7-jY6ZJk) # Notas 1. **Using Pathlib for file paths** (0:18): - Pathlib is recommended over raw strings or `os.path` for file path operations because it's **cross-platform by default, more readable, object-oriented, less error-prone, and has better IDE support**. - It allows for cleaner creation of path objects and provides methods to check existence, get parent directories, file names, and suffixes. - It also simplifies creating directories and writing to files. 2. **Using Dataclasses for simple data containers** (3:33): - Dataclasses are a cleaner and less error-prone alternative to traditional classes for simple data containers, as they **automatically generate common methods** like `__init__`, `__repr__`, and `__eq__`. - They require less boilerplate code and support type hints, making code more concise and robust. 3. **Using the Logging module instead of print statements** (5:31): - For any serious or production-level code, the `logging` module offers **greater control over output levels, formatting, and destination** compared to simple `print` statements. - It allows for different levels of messages (debug, info, warning, error, critical) and can be configured to write logs to files or the console, making debugging and monitoring more efficient. 4. **Using Guard Clauses instead of deeply nested if-else statements** (10:09): - Guard clauses improve code readability by **reducing nesting and making the "happy path" clearer**. - They involve using early returns for validation and error checking, which leads to a flatter, easier-to-understand code structure with less cognitive load. 5. **Avoiding Name Shadowing** (11:26): - Name shadowing occurs when a variable name in an inner scope reuses a name from an outer scope, especially built-in functions (like `sum`, `list`, `str`), which can lead to **unpredictable behavior and `TypeError` bugs**. - It's crucial to use **descriptive names** for variables to prevent overwriting built-in functionalities.