获取config.ini文件配置的方法

#coding:utf-8

import os
import configparser#导入配置文件包

def read_conf(option,section):
    cur_path = os.path.dirname(os.path.realpath(__file__))  # 获取当前目录
    configPath = os.path.join(cur_path, "config.ini")  # 拼接目录跟文件名
    conf = configparser.ConfigParser()  # 新建实例
    conf.read(configPath)  # 读取config.ini文件
    peizhi=conf.get(option,section)#获取配置
    return peizhi

下面这个就是我config.ini文件的配置

[web]
user = zhangsan
pwd  = 111111

[email]
smtp_server = smtp.qq.com
port = 465
sender = 504527497@qq.com
原文地址:https://www.cnblogs.com/onelove1/p/13123960.html