read(filenames, encoding=None):直接读取配置文件内容 read_file(f, source=None):读取配置文件内容,f必须是unicode read_string(string, source=’’):从字符串解析配置数据 read_dict(dictionary, source=’’)从词典解析配置数据 get(section, option, *, raw=False, vars=None[, fallback]):得到section中...
5. read(filenames, encoding=None) 读取配置文件的内容到对象; 1. 6. read_file(f, filename=None) 读取配置文件的内容到对象;这里的f是一个文件的句柄; 例如: import configparser config = configparser.ConfigParser() f=open('example.ini') config.read_file(f) # 这两句等效 config.read('example....
config_filename='config.ini'config=configparser.ConfigParser()config['default']={'name':'易天','age':30,'gender':'male'}config['young']={'name':'yitian','age':20}withopen(config_filename,'w',encoding='utf8')asfile:config.write(file)config2=configparser.ConfigParser()config2.read(confi...
1.1.读取配置文件 -read(filename) 直接读取ini文件内容 -sections() 得到所有的section,并以列表的形式返回 -options(section) 得到该section的所有option -items(section) 得到该section的所有键值对 -get(section,option) 得到section中option的值,返回为string类型 -getint(section,option) 得到section中option的值...
config.read_file(open('defaults.cfg')) config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')], encoding='cp1250') 3.2 新版功能: encoding 形参。 在之前的版本中,所有文件都将使用 open() 的默认编码格式来读取。 3.6.1 新版功能: filenames 形参接受一个 path-like object。
read_file(f, filename=None) Read and parse one configuration file, given as a file object. The filename defaults to f.name; it is only used in error messages (if f has no `name` attribute, the string `<???>` is used).
**read(filename)直接读取文件内容** get(section, option)获取section下具体某一配置项的值(返回的是字符串) sections()得到所有的section,并以列表的形式返回 options(section)得到该section的所有option items(section)键值对的形式 得到该section的所有option ...
# -read(filename) 直接读取文件内容 # -sections() 得到所有的section,并以列表的形式返回 # -options(section) 得到该section的所有option # -items(section) 得到该section的所有键值对 # -get(section,option) 得到section中option的值,返回为string类型 ...
read(filename):直接读取配置文件内容 sections():以列表的形式返回所有section options(section):得到对应section下的所有option items(section):得到对应section下的所有键值对 get(section,option):得到对应的section中的option的值,并以string的类型返回 getint(section,option):得到对应的section中的option的值,并以...
config.read(file_path) In [5]: config.read('example.ini') Out[5]: ['example.ini'] In [6]: config.sections() Out[6]: ['bitbucket.org', 'topsecret.server.com'] 方法2:从文件对象读取配置 read_file(f_obj, source=None) f 为文件对象,从 f 读取并解析配置数据, ...