diff --git a/.env-example b/.env-example new file mode 100644 index 0000000..9831f04 --- /dev/null +++ b/.env-example @@ -0,0 +1,4 @@ +BD_USER="CHANGE-ME" +BD_PASSWORD="CHANGE-ME" +BD_PORT=CHANGE-ME +BD_HOST="CHANGE-ME" diff --git a/aula184.py b/aula184.py new file mode 100644 index 0000000..097dd1c --- /dev/null +++ b/aula184.py @@ -0,0 +1,22 @@ +# Variáveis de ambiente com Python +# Para variáveis de ambiente +# Windows PS: $env:VARIAVEL="VALOR" | dir env: +# Linux e Mac: export NOME_VARIAVEL="VALOR" | echo $VARIAVEL +# Para obter o valor das variáveis de ambiente +# os.getenv ou os.environ['VARIAVEL'] +# Para configurar variáveis de ambiente +# os.environ['VARIAVEL'] = 'valor' +# Ou usando python-dotenv e o arquivo .env +# pip install python-dotenv +# from dotenv import load_dotenv +# load_dotenv() +# https://pypi.org/project/python-dotenv/ +# OBS.: sempre lembre-se de criar um .env-example +import os + +from dotenv import load_dotenv # type: ignore + +load_dotenv() + +# print(os.environ) +print(os.getenv('BD_PASSWORD')) diff --git a/requirements.txt b/requirements.txt index b49d4bf..28f2742 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,7 @@ mypy-extensions==0.4.3 pycodestyle==2.10.0 pyflakes==3.0.1 python-dateutil==2.8.2 +python-dotenv==0.21.0 pytz==2022.6 six==1.16.0 tomli==2.0.1