Advertisement
Liversalts

2-helper.py

Mar 8th, 2021
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. # Helper module with User class and additional functions
  2. from datetime import date
  3.  
  4. ## User Class
  5. class User:
  6. def __init__(self):
  7. self.id = None
  8. self.first_name = None
  9. self.last_name = None
  10. self.birth_date = None
  11. self.address = None
  12. self.score = None
  13.  
  14. # Print the object
  15. def __repr__(self):
  16. return str(self.__dict__)
  17.  
  18. # User object serialization
  19. def serializeUser(object):
  20. if isinstance(object, User):
  21. return object.__dict__
  22.  
  23. if isinstance(object, date):
  24. return object.__str__()
  25.  
  26. ## Used For MiniDom
  27. # Print the tags of a nodeList object
  28. def printTags(nodeList):
  29. for node in nodeList:
  30. if node.nodeName != '#text':
  31. print(node.nodeName)
  32.  
  33. # Recursively print the node list childern's name (tag) and its value
  34. def printNodes (nodeList, level=0):
  35. for node in nodeList:
  36. if node.nodeName != '#text':
  37. print( (" ")*level + node.nodeName + ':' + node.firstChild.data)
  38. printNodes(node.childNodes, level+1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement