![](/img/trans.png)
[英]Python Beautifulsoup : how to find a tag by attribute value without knowing corresponding attribute name?
[英]How to find value based on key without knowing section name
如果我仅知道B的值(并且现在不知道在哪个部分可以找到B的值),是否有办法获得下面SEC-1的A值?
所以我所知道的是B = XX,我想获得A值为101。
[SEC-1]
A=101
B=XX
[SEC-2]
A=102
B=YY
这可能会有所帮助。
import configparser
config = configparser.ConfigParser()
config.read(filename)
for ses in config.sections():
if config[ses].get("B") == "XX": #Check if var B has XX
print(config[ses].get("A"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.