NOTES & EXPLORATIONS
Python--配置文件的读写
Table of Contents
1. configparser 与 ini 配置
1.1. ini 文件
# zh_cn.config(UTF-8)
[lang]
name=中文简体
[message]
applyLangTip = 重启程序来应用更改。
runCommands = 执行命令
[menu]
id = 96
service = 服务
help = 帮助
officialSite = 官网
officialHelp = 帮助文档
[UI]
title = 集成运行环境
stop = 停止
startZentao = 启动
account = 账号
password = 密码
1.2. 读取
from configparser import ConfigParser
config = ConfigParser()
# 传入读取文件的地址,encoding文件编码格式,中文必须
config.read('zh_cn.config', encoding='UTF-8')
all_sections = config.sections()
>>>
['lang', 'message','UI']
items = config.items('user')
>>>
[("name","中文简体")]
options = config.options('lang')
>>>
["name"]
一个问题,通向下一个问题。
继续探索知识库 →