python 配置文件返回的两种方式,写法不一样而已

配置文件如下:
[MODE]
mode:{ "register":"all"} 或者 mode = {"register":"all"}
注意:只是:换成了=,效果是一样的。

[basic_info]
HostURL: http://www.baidu.com 或:
HostURL=http://www.baidu.com

@staticmethod
def get_config(file_path, section, option):
cf = configparser.ConfigParser()
cf.read(file_path)
  
  # 方式一:
 return cf[section][option]
  或者
  # 方式二:
  return cf[section].get(option)
   

猜你喜欢

转载自www.cnblogs.com/zzllovehappy/p/10762156.html