Python 3

The use of __name__ == '__main__'

Adding this to a python file script will ensure that everything inside this condition will be only ran, if the script file was runned directly.

This happens because when you import functions from other files, python runs the entire file. So if you have code executing there, it will execute it on the import.

To avoid this you put this code inside this condition.

Installing Python

Install python with pyenv.

List available versions to install

Install a version

Set global version

Check global version

Creating a Project

Virtual Environement

You can create projects with a package.json alike way, with venv.

When using Virtual Environments, dependencies installed via pip will be installed at a project scope, instead of globally.

Create the environment

Active the environment

Deactivate

Create requirements.txt

This file will act like a package.json, saving the dependencies.

To reinstall from a requirements.txt

Will have to recreate the environment first.

Last updated