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

python 之ConfigParser模块

2011-07-13 22:33 141 查看
ConfigParser是用来处理ini格式的配置文件的Python标准库.
函数 :
read(self, filenames):直接读取ini文件内容。
sections(self):得到所有的section,并以列表的形式返回。
options(self, section):得到指定section的所有option.
get(self, section, option, raw=False, vars = None):得到section中option的值,返回为string类型.
set(self,section, option, value): 对section中的option进行设置,其值为value。
实例:
[portal]
url = http://%(host)s:%(port)s/portal host = localhost
port = 8080

from ConfigParser import ConfigParser
config = ConfigParser()
config.read(filename)
url = config.get('portal', 'url')
print url

>>> http://localhost:8080/portal[/code] 
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: