Python : Config/ini/Properties file
-----------credentials.config-----------
[db]
dbname= dbname
hostname= host_anme
port= 1234
username= usr_name
password= pass
----------------------
Python : Config /Properties/ ini file
from configparser import RawConfigParser
config_path = os.getcwd()+'/properties/credentials.config'
confparser = RawConfigParser()
with open(config_path, "r") as config_file:
confparser.read_file(config_file)
"dbname": confparser["db"]["dbname"],
"hostname": confparser["db"]["hostname"],
"port":confparser["db"]["port"],
"username": confparser["db"]["username"],
"password": confparser["db"]["password"]
No comments:
Post a Comment