1、 配置文件如下
[swift]
auth_url = http://192.168.0.230:5000/v3/
username = admin
password = itnihao
user_domain_name = default
project_name = admin
project_domain_name = default
[mongodb]
db = yunpan
host = 192.168.0.215
port = 27017
username = admin
password = 123456
[tempurl]
key = ljs
seconds = 1200
[view_host]
host = 192.168.0.239
port = 8021
2、读取 python 代码
import configparser
def readConfig():
"""
一次加载配置文件到系统中
:return:
"""
config = configparser.ConfigParser()
config.read('config.ini', encoding='utf-8')
swift = dict(config.read('swift'))
tempurl = dict(config.read('tempurl'))
view_host = dict(config.read('view_host'))
conf = {}
# swift 配置
conf["auth_url"] = swift.get("auth_url")
conf["username"] = swift.get("username")
conf["password"] = swift.get("password")
conf["username_domain_name"] = swift.get("username_domain_name")
conf["project_name"] = swift.get("project_name")
conf["project_domain_name"] = swift.get("project_domain_name")
# tmpurl
conf["key"] = tempurl.get("key")
conf["seconds"] = tempurl.get("seconds")
# view_host
conf["host"] = view_host.get("view_host")
conf["port"] = view_host.get("port")
print("xxxxxxxxxxxxxxxxx")
return conf