【发布时间】:2021-07-23 15:28:48
【问题描述】:
我一直在将一些 XPath 从我的 Perl 脚本转换为 Python。一切正常,但 Pylint 抱怨线路太长。在 Perl 中,我使用空格通过分解长行来使 XPath 更具可读性。
Perl 示例:
my $node_list = $device->findnodes(
"./templateObjects
/TemplateObject[fieldName/text() = 'SCADAArea']
/keyPairs
/TemplateKeyValuePair[TemplateName/text() = '%AREA%']
/TemplateValue");
在 Python 中:
node_list = device.xpath( "templateObjects/TemplateObject[fieldName/text() = 'SCADAArea']/keyPairs/TemplateKeyValuePair[TemplateName/text() = '%AREA%']/TemplateValue")
在 Python 中有更好的方法吗?我尝试了三引号,但它不接受这样的 XPath。
【问题讨论】: