Advertisement
VikkaLorel

tag with inheritance

Aug 20th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. from typing import List
  2.  
  3.  
  4. class Parent:
  5.     tags: List[str]
  6.  
  7.     def __init__(self):
  8.         tag = 'parent'
  9.         try:
  10.             self.tags.append(tag)
  11.         except AttributeError:
  12.             self.tags = list([tag])
  13.  
  14.  
  15. class ChildA(Parent):
  16.     def __init__(self):
  17.         tag = 'child_a'
  18.         try:
  19.             self.tags.append(tag)
  20.         except AttributeError:
  21.             self.tags = list([tag])
  22.         super().__init__()
  23.  
  24.  
  25. class ChildB(Parent):
  26.     def __init__(self):
  27.         tag = 'child_b'
  28.         try:
  29.             self.tags.append(tag)
  30.         except AttributeError:
  31.             self.tags = list([tag])
  32.         super().__init__()
  33.  
  34.  
  35. class GrandChild(ChildA, ChildB):
  36.     def __init__(self):
  37.         super().__init__()
  38.  
  39.  
  40. if __name__ == '__main__':
  41.     test = GrandChild()
  42.     print(test.tags)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement