27 Jul
2008
27 Jul
'08
3:45 p.m.
On 19 Jul 2008, at 08:48, Stefan Behnel wrote:
Geoffrey Sneddon wrote:
What's the best way to check whether a given node is a comment or an element? For the former, I'm currently using isinstance(node, etree._Comment), which is rather obviously sub-optimal.
You can do
node.tag is etree.Comment
to check if it's a comment, and
isinstance(node.tag, basestring) # Py2.x
or
isinstance(node.tag, str) # Py3
to see if it's a normal Element.
This may be sub-optimally obvious, but I find it better than checking for underscored classes.
Yeah, seems better, though slightly bizarre. Thanks. -- Geoffrey Sneddon