python读写修改配置文件(ini)

更新时间:2023-06-18 15:19:45 阅读: 评论:0

python读写修改配置⽂件(ini)⽰例ini配置⽂件(tting.ini)
[txtA]
name = comma,end,full,run
comma =1000
end =3
full =2
run =1
default_comma =3
写给幸福default_end =3
default_full =2
default_run =1
色王堂综合
[txtB]
name = comma,end,full,run
comma =1000
end =3
full =2
run =1
default_comma =3
default_end =3
default_full =2
default_run =1
[chine]
name = volume,tones,speed,spokesman
volume =5
tones =5
speed =5
spokesman =1
default_volume =5
default_tones =5
default_speed =5
default_spokesman =1
[english]
name = volume,tones,speed,spokesman
volume =5
tones =5
speed =5
spokesman =1
default_volume =5
default_tones =5
default_speed =5
default_spokesman =1
[help]
[about]
⽰例ini配置⽂件操作程序1:
关于竹子的诗句
使⽤configparr函数,缺点:增删、修改都是重写ini⽂件操作
'''
遇到问题没⼈解答?⼩编创建了⼀个Python学习交流QQ群:778463939
寻找有志同道合的⼩伙伴,互帮互助,群⾥还有不错的视频学习教程和PDF电⼦书!
'''
德国大使馆
import configparr
import os
# *** 初始化配置⽂件路径 *** #
curpath = os.path.dirname(alpath(__file__))# 当前⽂件路径
inipath = os.path.join(curpath,"tting.ini")# 配置⽂件路径(组合、相对路径)# *** 数据读取 *** #
conf = configparr.ConfigParr()
# ctions = ions()              # 获取所有的ctions名称
# options = conf.options(ctions[0])    # 获取ction[0]中所有options的名称
# items = conf.items(ctions[0])        # 获取ction[0]中所有的键值对
# value = (ctions[-1],'txt2')  # 获取ction[-1]中option的值,返回为string类型# value1 = int(ctions[0],'comma')        # 返回int类型
# value2 = float(ctions[0],'end')        # 返回float类型
# value3 = boolean(ctions[0],'run')      # 返回boolen类型
# *** 删除内容 *** #
# ve_option(ctions[0], "comma")
# ve_ction(ctions[1])
# *** 修改内容 *** #
conf.t('txtB',"comma","1000")
conf.write(open(inipath,"r+", encoding="utf-8"))# r+模式
# print(conf.items(ctions[0]) )
⽰例ini配置⽂件操作程序2:
葱油面的做法使⽤configobj 函数
from configobj import ConfigObj
# *** 配置⽂件预处理 *** #
config = ConfigObj("tting.ini",encoding='UTF8')
突然英文
# *** 读配置⽂件 *** #
# print(config['txtB'])
# print(config['txtB']['name'])
# *** 修改配置⽂件 *** #
# config['txtB']['comma'] = "Mufasa"
黄果树瀑布旅游
# config.write()
油焖大虾的做法家常# *** 添加ction *** #
# config['txtC'] = {}
# config['txtC']['index0'] = "wanyu00"
# config.write()

本文发布于:2023-06-18 15:19:45,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/984077.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:修改   配置   学习   解答   做法   视频
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图