Python读写配置文件模块--Configobj
Python读写配置⽂件模块--Configobj from configobj import ConfigObj
圣诞节 短信import os
# Python读写配置⽂件模块--Configobj
class TestConfig():
def__init__(self):
self.path = os.path.dirname(os.path.dirname(__file__)) + "/config/config.ini"
print(self.path)
# 实例化⼀个Configobj对象,给ConfigObj⼀个配置⽂件的路径,然后通过字典来访问成员,⼦段也是⼀个字典水泥外加剂
# 读取配置⽂件信息
def query_config(self):
fig['HJ'])
fig['HJ']['hj'])
如何制作启动优盘
# 给配置⽂件添加新项
def add_config(self):
# 修改配置⽂件
def modify_config(self):
fig['HJ']['hj'])
fig['HJ']['hj'])
十二星宿风之少年fig['HJ']['hj'])
假如给我三天光明好词好句# 删除配置⽂件中的某个项
def del_config(self):
fig['data']['user']
fig['data']
# 将配置⽂件写⼊到不同的⽂件
中秋佳节祝福短信
def write_other_file(self):
# 创建⼀个新配置⽂件
def create_new_config(self):
config = ConfigObj()
config.filename = os.path.dirname(os.path.dirname(__file__)) + "/config/test1.ini"
config['student'] = {}
config['student']['name'] = 'Jardon'
config['student']['age'] = '56'
config.write()
if__name__ == '__main__':
t = TestConfig()
# t.query_config()
# t.modify_config()
# t.add_config()
# t.del_config()
# t.write_other_file()

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