skip420

Visual_Tree

Jan 25th, 2021
470
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #python skip420.py
  2.  
  3. class magictree:
  4.     def __init__(self, parent=None):
  5.         self.parent = parent
  6.         self.level = 0 if parent is None else parent.level + 1
  7.         self.attr = []
  8.         self.rows = []
  9.  
  10.     def add(self, value):
  11.         tr = magictree(self)
  12.         tr.attr.append(value)
  13.         self.rows.append(tr)
  14.         return tr
  15.  
  16.     def printtree(self):
  17.         def printrows(rows):
  18.             for i in rows:
  19.                 print("{}{}".format(i.level * "\t", i.attr))
  20.                 printrows(i.rows)
  21.  
  22.         printrows(self.rows)
  23.  
  24. tree = magictree()
  25. group = tree.add("Richmond_Chinese_Staff")
  26. group.add("Primary_Teacher")
  27. group.add("Teachers_Assistance")
  28. emp_3 = group.add("Marketing")
  29. emp_3 = group.add("Sales")
  30.  
  31. group = tree.add("Richmond_Foreign_Staff")
  32. group.add("Foreign_Teachers")
  33. group.add("Head_Teacher")
  34. group.add("Full_Time")
  35. group.add("Part_Time")
  36. emp_3.add("Part_Time")
  37. emp_3.add(" ")
  38. emp_3.add(" ")
  39.  
  40. group = tree.add("Other")
  41. group.add("Pencils")
  42. group.add("Pens")
  43. group.add("Books")
  44.  
  45. emp_3.add("Papers")
  46. emp_3.add("Crayons")
  47. emp_3.add("ART")
  48.  
  49. tree.printtree()
RAW Paste Data