

Kamon Ayeva ๐
1.2K posts

@kamon
Developer | ๐ Mastering Python Design Patterns, 3rd Edition ๐ https://t.co/oBBQEIo6tA | Building Together https://t.co/PxCaA5zeOK



Day 9 slice shipped: Minimal UX with Gradio โ To test: - Install/update dependencies in your virtual environment. - Run: python app.py - Visit http://127.0.0.1:7860 Currently, you can generate the result by providing the prompt and the list of columns. Repo: github.com/TeamEnable/pocโฆ Branch: ux-with-gradio Next up: Ability to specify the schema of the data returned by providing a JSON string or a "template" CSV. Do you see another option?








Day 8 slice shipped: CLI for prompt and other input โ file out โ It is possible to test with: python main.py "Produce the list of currencies with the countries" --col "currency_name" --col "ticker" --col "country" --rows 20 --output "out/currencies.csv" It does some validation of the data after parsing the response, and then writes the file. Repo: github.com/TeamEnable/pocโฆ Branch: cli-with-typer My current thinking is generating a CSV, and then make it possible to move the data from the CSV to other databases / formats / storages, using existing techniques/tools. What do you think?





๐ Python Tip of the Day: Simplifying Resource Management with `contextlib.contextmanager` Decorator Python's `contextlib.contextmanager` decorator is a handy tool for creating simple and readable context managers without the need for a class that implements `__enter__` and `__exit__` methods. This decorator is ideal for managing resources like files, network connections, or locks that need to be set up and cleaned up reliably, no matter what happens during their use. Example use case: Create a temporary file and ensure it gets deleted after use. Benefits: 1๏ธโฃ Reduced boilerplate: Eliminates the need to write an entire class with `__enter__` and `__exit__` methods, reducing boilerplate and overhead. 2๏ธโฃ Exception handling: Automatically handles exceptions within the `with` block, ensuring that the cleanup code is executed. 3๏ธโฃ Flexibility in resource handling: Allows more flexible handling of how resources are passed to the block enclosed by the `with` statement.

๐ Python Tip of the Day: Utilizing the classmethod Decorator for State Management In object-oriented programming with Python, the `classmethod` decorator allows you to define methods bound to the class rather than its instances. This capability is crucial for managing state or behavior that is common to all instances of the class, rather than individual objects. When to Use It? 1๏ธโฃ Managing shared state: Use it to manage data that is shared among all instances of a class. For example, keeping a count of all instances ever created. 2๏ธโฃ Factory methods: Excellent for defining alternative constructors. You can create class methods that return instances of the class, configured in different ways. 3๏ธโฃ Accessing class attributes: They provide a way to access or modify class state that applies across all instances, like modifying a configuration setting that affects all instances.