How can I transform data from a .ini
file into a dict
into Python?
Is there any way to do this in Python
?
[database]
host = localhost
password = sabe_nada_de_python
port = 3306
How can I transform data from a .ini
file into a dict
into Python?
Is there any way to do this in Python
?
[database]
host = localhost
password = sabe_nada_de_python
port = 3306
Yes, using configparser
:
import configparser
import os
configuracao = configparser.ConfigParser()
configuracao.read(os.path.join(os.getcwd(), "meuarquivo.ini"))
host = configuracao["database"]["host"]
password = configuracao["database"]["password"]
port = configuracao["database"]["port"]