From: David G. <go...@py...> - 2006-03-17 04:24:20
|
Hi Edward! It's been a while. [Edward Loper] > Which of the following is the preferred idiom for accessing the childre= n > of a docutils.nodes.Element node? (All 3 seem to work) >=20 >>>> for child in node: ... >>>> for child in node.children: ... >>>> for child in node.get_children(): ... node.get_children() has been removed from recent Docutils, so avoid that = one. The other two are both valid; "for child in node" is higher level, but "f= or child in node.children" is more direct and efficient. The choice is up t= o you; both are here to stay. > Similarly, which of the following is preferred for replacing the childr= en? >=20 >>>> node[:] =3D new_child_list >>>> node.children =3D new_child_list >>>> node.children[:] =3D new_child_list "node[:] =3D new_child_list" is preferred, because the docutils.nodes.Element.__setitem__ method handles some bookkeeping (via t= he =2Esetup_child method). --=20 David Goodger <http://python.net/~goodger> |