使用参考:https://www.yuque.com/u1046159/erg6ec/giok20
config.ini
[mysql]
host = localhost
user = root
password =
db = sizechart_spider
port = 3306
charset = utf8
readconfig.py
import configparser
import os
class ReadConfig:
"""读取配置文件类"""
def __init__(self,filepath=None):
if filepath:
configpath =filepath
else:
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)