classGetCfg:"""读取配置文件方法"""def__init__(self, config_file: str, section: [str, None] = None, key: [str, None] =None): self.config_file=config_file self.conf=ConfigParser() self.section=section self.key=key self.conf.read(self.config_file, encoding="utf-8")defget(self) -...
from configparserimportConfigParserimportosclassReadConfigFile(object):defread_config(self):conn=ConfigParser()file_path=os.path.join(os.path.abspath('.'),'config_test.ini')ifnot os.path.exists(file_path):raiseFileNotFoundError("文件不存在")conn.read(file_path)url=conn.get('api','url')metho...
rc = ReadConfigFile() print(rc.read_config()) 运行结果: 配置文件yaml 上面已经介绍配置文件ini读取方法,现在讲yaml文件读取。 yaml [ˈjæməl]: Yet Another Markup Language :另一种标记语言。yaml 是专门用来写配置文件的语言。 1、yaml文件规则 1.区分大小写; 2.使用缩进表示层级关系; 3.使用...
class ReadConfigFile(object): def read_config(self): conn = ConfigParser() file_path = os.path.join(os.path.abspath('.'),'config_test.ini') if not os.path.exists(file_path): raise FileNotFoundError("文件不存在") conn.read(file_path) url = conn.get('api','url') method = conn...
importconfigparser# 读取配置文件config=configparser.ConfigParser()config.read('config.ini')# 读取配置value=config.get('section','key')print(value)# 写入配置config['section']={'key':'value'}withopen('config.ini','w')asconfigfile:config.write(configfile) ...
# 读取config.ini文件cf.read(config.ini) 然后进行配置文件的读取操作。 以get为例,示例代码如下: # 定义方法,获取config分组下指定name的值 def getConfigValue(self, name): value = self.cf.get("config", name) return value # 定义方法,获取cmd分组下指定name的值 ...
2,写一个 readConfig.py 的文件用来读取 config.txt 配置文件,具体代码如下import osimport configparserproDir = os.path.split(os.path.realpath(__file__))[0]# proDir = os.path.dirname(os.path.realpath(__file__)) 与上面一行代码作用一样configPath = os.path.join(proDir, "configs.txt")path ...
configfile)运行以上代码,将创建包含以下内容的配置文件:[INFO]languages = Chinesetype = GBK修改 .ini 文件import configparserconfig = configparser.ConfigParser()config.read("config.ini")config['LOGIN']["user"] = "guest"with open("config.ini", "w") as configfile: config.write(configfile)以...
exit(-1) with open(cfgFile, mode='rb') as f: content = f.read() if content.startswith(b'\xef\xbb\xbf'): # 去掉 utf8 bom 头 content = content[3:] cfg.read_string(content.decode('utf8')) if not cfg.sections(): input('Read config.ini failed...') sys.exit(-1) SrcRoot ...
fields=/huawei-cfg:cfg/startup-infos/startup-info({filtering_str})') req_data = None ret, _, rsp_data = ops_conn.get(uri, req_data) if ops_return_result(ret) or rsp_data == '': raise OPIExecError('Failed to get the current config file information') node_dict = {} root_...