Variáveis de ambiente com Python
This commit is contained in:
4
.env-example
Normal file
4
.env-example
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
BD_USER="CHANGE-ME"
|
||||||
|
BD_PASSWORD="CHANGE-ME"
|
||||||
|
BD_PORT=CHANGE-ME
|
||||||
|
BD_HOST="CHANGE-ME"
|
||||||
22
aula184.py
Normal file
22
aula184.py
Normal file
@@ -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'))
|
||||||
@@ -6,6 +6,7 @@ mypy-extensions==0.4.3
|
|||||||
pycodestyle==2.10.0
|
pycodestyle==2.10.0
|
||||||
pyflakes==3.0.1
|
pyflakes==3.0.1
|
||||||
python-dateutil==2.8.2
|
python-dateutil==2.8.2
|
||||||
|
python-dotenv==0.21.0
|
||||||
pytz==2022.6
|
pytz==2022.6
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
tomli==2.0.1
|
tomli==2.0.1
|
||||||
|
|||||||
Reference in New Issue
Block a user