您的位置:首页 > 编程语言 > Python开发

python 中使用ConfigParser类修改配置文件

2011-10-21 13:53 821 查看
使用python 中ConfigParser类修改配置文件中的值

配置文件的格式:

[user]
user_ip=127.0.0.1
user_name=testuser
user_id=13

import ConfigParser

conf = ConfigParser.ConfigParser()

filepath = "c:\test.conf"

conf.read(filepath)

node ="user"

key = "user_id"

value = "45"

conf.set(node,key,value)

fh = open(filepath ,'w')

conf.write(fh)#把要修改的节点的内容写到文件中

fh.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: