Last active
August 12, 2023 15:04
-
-
Save jumpingchu/c209c56eb58639aa1a2ba696e8067361 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[MYSQL] | |
HOST = 127.0.0.1 | |
USERNAME = mysql_root | |
PASSWORD = mysql_password | |
PORT = 3306 | |
DATABASE = MYSQL_DATA | |
[MSSQL] | |
SERVER = test.database.windows.net | |
USERNAME = mssql_root | |
PASSWORD = mssql_password | |
DATABASE = MSSQL_DATA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DB_INFO] | |
[DB_INFO.MYSQL] | |
HOST = '127.0.0.1' | |
USERNAME = 'mysql_root' | |
PASSWORD = 'mysql_password' | |
PORT = 3306 | |
DATABASE = 'MYSQL_DATA' | |
[DB_INFO.MSSQL] | |
SERVER = 'test.database.windows.net' | |
USERNAME = 'mssql_root' | |
PASSWORD = 'mssql_password' | |
DATABASE = 'MSSQL_DATA' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DB_INFO: | |
MYSQL: | |
HOST: 127.0.0.1 | |
USERNAME: mysql_root | |
PASSWORD: mysql_password | |
PORT: 3306 | |
DATABASE: MYSQL_DATA | |
MSSQL: | |
SERVER: test.database.windows.net | |
USERNAME: mssql_root | |
PASSWORD: mssql_password | |
DATABASE: MSSQL_DATA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import configparser | |
def read_ini(filepath): | |
config = configparser.ConfigParser() | |
config.read(filepath) | |
return config | |
ini_config = read_ini('config.ini') | |
mysql_info = ini_config['MYSQL'] | |
host = mysql_info['HOST'] | |
username = mysql_info['USERNAME'] | |
port = mysql_info['PORT'] | |
# host: 127.0.0.1 (str) | |
# username: mysql_root (str) | |
# port: 3306 (str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tomllib | |
def read_toml(filepath): | |
with open(filepath, "rb") as f: | |
config = tomllib.load(f) | |
return config | |
toml_config = read_toml('config.toml') | |
mysql_info = toml_config['DB_INFO']['MYSQL'] | |
host = mysql_info['HOST'] | |
username = mysql_info['USERNAME'] | |
port = mysql_info['PORT'] | |
# host: 127.0.0.1 (str) | |
# username: mysql_root (str) | |
# port: 3306 (int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
def read_yaml(filepath): | |
with open(filepath) as f: | |
config = yaml.safe_load(f) | |
return config | |
yaml_config = read_yaml('config.yaml') | |
mysql_info = yaml_config['DB_INFO']['MYSQL'] | |
host = mysql_info['HOST'] | |
username = mysql_info['USERNAME'] | |
port = mysql_info['PORT'] | |
# host: 127.0.0.1 (str) | |
# username: mysql_root (str) | |
# port: 3306 (int) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment