标签:table 读取 inter dex use mit lse als compress
ConfigParser模块在python中是用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section),每个节可以有多个参数(键=值)。
注意:在python 3 中ConfigParser模块名已更名为configparser
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
config.read(‘example.ini‘,encoding="utf-8")"""读取配置文件,python3可以不加encoding"""options(section)"""sections(): 得到所有的section,并以列表的形式返回"""config.defaults()"""defaults():返回一个包含实例范围默认值的词典"""config.add_section(section)"""添加一个新的section"""config.has_section(section)"""判断是否有section"""print(config.options(section))"""得到该section的所有option"""has_option(section, option)"""判断如果section和option都存在则返回True否则False"""read_file(f, source=None)"""读取配置文件内容,f必须是unicode"""read_string(string, source=’’)"""从字符串解析配置数据"""read_dict(dictionary, source=’’)"""从词典解析配置数据"""get(section, option, *, raw=False, vars=None[, fallback])"""得到section中option的值,返回为string类型"""getint(section,option)"""得到section中option的值,返回为int类型"""getfloat(section,option)"""得到section中option的值,返回为float类型"""getboolean(section, option)"""得到section中option的值,返回为boolean类型"""items(raw=False, vars=None)"""和items(section, raw=False, vars=None):列出选项的名称和值"""set(section, option, value)"""对section中的option进行设置"""write(fileobject, space_around_delimiters=True)"""将内容写入配置文件。"""remove_option(section, option)"""从指定section移除option"""remove_section(section)"""移除section"""optionxform(option)"""将输入文件中,或客户端代码传递的option名转化成内部结构使用的形式。默认实现返回option的小写形式;"""readfp(fp, filename=None)"""从文件fp中解析数据""" |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import configparser #配置文件config = configparser.ConfigParser()"""生成configparser配置文件 ,字典的形式""""""第一种写法"""config["DEFAULT"] = {‘ServerAliveInterval‘: ‘45‘, ‘Compression‘: ‘yes‘, ‘CompressionLevel‘: ‘9‘}"""第二种写法"""config[‘bitbucket.org‘] = {}config[‘bitbucket.org‘][‘User‘] = ‘hg‘"""第三种写法"""config[‘topsecret.server.com‘] = {}topsecret = config[‘topsecret.server.com‘]topsecret[‘Host Port‘] = ‘50022‘ # mutates the parsertopsecret[‘ForwardX11‘] = ‘no‘ # same hereconfig[‘DEFAULT‘][‘ForwardX11‘] = ‘yes‘"""写入后缀为.ini的文件"""with open(‘example.ini‘, ‘w‘) as configfile: config.write(configfile) |
|
1
2
3
4
5
6
7
8
9
10
11
12
|
[DEFAULT]serveraliveinterval = 45compression = yescompressionlevel = 9forwardx11 = yes[bitbucket.org]user = hg[topsecret.server.com]host port = 50022forwardx11 = no |
标签:table 读取 inter dex use mit lse als compress
原文地址:https://www.cnblogs.com/bert227/p/9326313.html