关于python配置文件.conf的获取方式

#encoding: utf-8
import os
import ConfigParser
BASE_DIR = os.path.dirname(__file__) #获取当前文件夹的绝对路径
file_path = os.path.join(BASE_DIR, 'config.conf') #获取当前文件夹内的信息
config=ConfigParser.ConfigParser()
with open(file_path,"r") as cfgfile:
config.readfp(cfgfile)
host=config.get("DataBase","HOST")
user=config.get("DataBase","USER")
print host
print user
cfgfile.close()
原文地址:https://www.cnblogs.com/zhisy/p/7765035.html