Skip to content

Instantly share code, notes, and snippets.

@jumpingchu
Last active August 12, 2023 15:04
Show Gist options
  • Save jumpingchu/c209c56eb58639aa1a2ba696e8067361 to your computer and use it in GitHub Desktop.
Save jumpingchu/c209c56eb58639aa1a2ba696e8067361 to your computer and use it in GitHub Desktop.
[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
[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'
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
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)
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)
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