创建一个ini文件,例如:config.ini
[mysql]
host='127.0.0.1'
port='3306'
[other]
tips="提示_—【说明"
from configparser import ConfigParser
ini_file_path = r"C:/resources/config.ini"
taeget=ConfigParser()
taeget.read(filenames=ini_file_path , encoding='utf-8')
print(taeget.get('mysql', 'host'))
print(taeget.get('other', 'tips'))
# 当key不存在时,返回fallback的值
print(taeget.get('test', 'tips', fallback="123"))
print(taeget.get('other', 'tiwps', fallback="234"))