'Get linenumber for ElementTree Xpath match
With lxml I can get the linenumber of referenced xpath match object:
>>> results = tree.xpath('.//field[@name="name"]')
>>> first_result = results[0]
>>> print(first_result.sourceline)
6
while by using SPL's ElementTree I can't find such method exposed to .findall() match objects.
Is there any way to get the linenumber of xpath match with SPL?
Solution 1:[1]
for txt in tree.xpath('//field[@name="name"]'):
print(txt.sourceline)
Try this
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | parthi u |
