您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python ConfigParser检查Section和Key Value的存在

5b51 2022/1/14 8:22:57 python 字数 1431 阅读 555 来源 www.jb51.cc/python

使用ConfigParser的has_section()方法,我可以检查文件中是否存在某个部分,例如: config.has_section(section_name) 什么是检查密钥是否存在的命令? 因此,在使用以下方法查询值之前,可以验证段和键是否存在: value = config.get(section, key) 提前致谢! 除了has_section之外,还有一个has_option方

概述

config.has_section(section_name)

什么是检查密钥是否存在的命令?
因此,在使用以下方法查询值之前,可以验证段和键是否存在:

value = config.get(section,key)

提前致谢!

config.has_option(section,option)

Python documentation

has_option*(section,option)* If the given section exists,and contains the given option,return True; otherwise return False. If the specified section is None or an empty string,DEFAULT is assumed.

总结

以上是编程之家为你收集整理的Python ConfigParser检查Section和Key Value的存在全部内容,希望文章能够帮你解决Python ConfigParser检查Section和Key Value的存在所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶