Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## This scrap of code uses the ElementTree's 'Element' type. It defines a function that checks if
- ## the provided element contains sub-elements (the list(element) phrase) and then returns all of the
- ## sub elements of each of the sub elements of the provided element. Put your hands up if you've used
- ## the word element too many times already. It returns the elements in dictionary form, so that my
- ## previously-made dictionary in the getShard() method can be update()d with the results from this function.
- def getSubElements(element):
- if list(element):
- return [getSubElements(i) for i in list(element)]
- else:
- return {element.tag: element.text}
Advertisement
Add Comment
Please, Sign In to add comment