Playground repository for Python exercises.
Create a virtual environment with virtualenv
virtualenv .python
source .python/bin/activate
or
. python/bin/activate
You can confirm you’re in the virtual environment by checking the location of your Python interpreter
which python
Install the required dependencies
pip install -r requirements.txt
Let's say there is an example.py
module within the exercises
folder that defines a hello
function.
Open the Python interpreter
python
import the function you want to run from its module
from exercises.example import hello
execute the function
hello()
Modules don't have any "main" execution. If you were to run a file directly, you would need to add the following to it
if __name__ == '__main__':
hello()
and then run
python exercises/example.py
To test every *_test.py
module
pytest
To format every file in the exercises
folder
black src
If you want to generate a new "requirements" file or add/remove dependencies and update the existing one
pip freeze > requirements.txt
Replace all ==
symbols in the requirements.txt
file with >=
, then run
pip install -r requirements.txt --upgrade
then run
pip freeze > requirements.txt
To list all the installed libraries in site-packages
pip list
To "show" the details of a specific library
pip show requests
If you want to switch to another project or generally speaing leave your current virtual environment
deactivate