19 Jul
2008
19 Jul
'08
3:48 a.m.
Hi, 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. Stefan