Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. class Base(object):
  2.     Trackable = []
  3.     def __init__(self, ):
  4.         self.identification = 'Base'
  5.         Base.Trackable.append(self)
  6.         self.trackable = list(Base.Trackable)
  7.     def __len__(self, ):
  8.         return len(Base.Trackable)
  9.     def __getitem__(self, key):
  10.         return Base.Trackable[key]
  11.     def __setitem__(self, key, value):
  12.         Base.Trackable[key] = value
  13.     def __delitem__(self, key):
  14.         del Base.Trackable[key]
  15.     def __iter__(self, ):
  16.         return self
  17.     def next(self, ):
  18.         if self.noMoreToGo():
  19.             self.trackable = list(Base.Trackable)
  20.             raise StopIteration
  21.         for item in Base.Trackable:
  22.             if item.identification == 'ExtendBase':
  23.                 self.trackable[self.trackable.index(item)] = 0
  24.                 return item
  25.             if item.identification == 'Base':
  26.                 self.trackable[self.trackable.index(item)] = 0
  27.                 return item
  28.     def noMoreToGo(self, ):
  29.         if self.trackable:
  30.             return False
  31.         else:
  32.             return True
  33.  
  34.  
  35. class ExtendBase(Base):
  36.     def __init__(self, ):
  37.         Base.__init__(self, )
  38.         self.identification = 'Base'
  39.  
  40. g = Base()
  41. gg = ExtendBase()
  42.  
  43. for i in g:
  44.     print i.identification
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement