Monday, March 9, 2020

Effective Python Exercise: Virtual Environments and Modules

This week we covered the last chapter of the Effective Python book, chapter 10: Collaboration. There are two specific points from the chapter that I'd like to focus on for the exercises, which are virtual environments and modules. We'll go over the problem in two steps:

Exercise: Virtual Environments and Modules


Step 1: Virtual Environments


Within a folder called projects, use venv to create a folder called myproject with it's own virtual environment. Install Flask and PyTest into the environment. Use pip to create a requirements.txt file that reflects this environment setup. To verify that the requirements.txt file works as expected, back out and use venv to create an otherproject folder with its own virtual environment. Use the requirements.txt file previously created to set up the otherproject folder so that it has the exact same environment as the myproject folder.

Step 2: Modules


Returning back to the original myproject, set it up via modules to have a controllers module and a repositories module. In both the controllers module and the repositories module create a todo.py. Create a main.py, and have it call a function in the todo controller, which in turn calls a function in the todo repository.

The answer to this exercise can be found here.