Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我通常会做以下事情:
nextPreset = element.firstChild while nextPreset != None: #doThings nextPreset = nextPreset.nextSibling
我想知道是否有类似的东西:
for child in element.children: #doThings
我看到了一个方法_get_childNodes,但它是私有的......
_get_childNodes
如果你在一个项目中多次这样做,你可以使用
def iterate_children(parent): child = parent.firstChild while child != None: yield child child = child.nextSibling
然后做
for child in iterate_children(element): # foo