Python ConfigParser模块,pythonconfigparser,[Python]代码#-
Python ConfigParser模块,pythonconfigparser,[Python]代码#-
[Python]代码
#-*- encoding: gb2312 -*-import ConfigParserimport string, os, syscf = ConfigParser.ConfigParser()cf.read("test.conf")# 返回所有的sections = cf.sections()print 'section:', so = cf.options("db")print 'options:', ov = cf.items("db")print 'db:', vprint '-'*60#可以按照类型读取出来db_host = cf.get("db", "db_host")db_port = cf.getint("db", "db_port")db_user = cf.get("db", "db_user")db_pass = cf.get("db", "db_pass")# 返回的是整型的threads = cf.getint("concurrent", "thread")processors = cf.getint("concurrent", "processor")print "db_host:", db_hostprint "db_port:", db_portprint "db_user:", db_userprint "db_pass:", db_passprint "thread:", threadsprint "processor:", processors#修改一个值,再写回去cf.set("db", "db_pass", "zhaowei")cf.write(open("test.conf", "w"))
相关内容
- Python HTMLParser模块,pythonhtmlparser,[Python]代码#-
- Python StringIO模块,pythonstringio模块,[Python]代码im
- Python zipfile模块,pythonzipfile模块,[Python]代码im
- Python 动态规划算法,计算单词距离,python算法,[Python]代
- Python 获取按键(跨平台),python获取按键,[Python]代码 c
- Python 读取mp3 ID3信息,python读取mp3id3,[Python]代码fr
- Python 相似单词,Python单词,[Python]代码fr
- Python 代码行数统计程序,python行数统计程序,[Python]代码
- Python PIL批量处理处理图片,,[Python]代码 #
- python计算方程式的根的代码,python计算方程式,''' root
评论关闭