使用参考:https://www.yuque.com/u1046159/erg6ec/giok20
config.ini
[mysql]host = localhostuser = rootpassword =db = sizechart_spiderport = 3306charset = utf8
readconfig.py
import configparserimport osclass ReadConfig:"""读取配置文件类"""def __init__(self,filepath=None):if filepath:configpath =filepathelse:root_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))configpath = os.path.join(root_dir, 'config.ini')print(configpath)self.cf = configparser.ConfigParser()self.cf.read(configpath, encoding="utf-8")def get_db(self, param):return self.cf.get('mysql', param)
