class person:
def __init__(self):
self.l = []
self.count = 0
self.index = 0
def __call__(self, name, age):
personReal = {'name':name, 'age':age}
self.count = self.count + 1
self.l.append(personReal)
def __getitem__(self):
print("__getitem__")
def next(self):
print('next')
def __next__(self):
print('__next__')
if self.index < self.count :
self.index = self.index + 1
return self.l[self.index]
def __iter__(self):
print('__iter__')
if self.index < self.count:
self.index = self.index + 1
return iter(self.l)
if __name__ == '__main__':
personS = person()
personS('john',8)
personS('jane', 7)
personS('Steve', 9)
print(personS.count, personS.index, personS.l)
for ps in personS:
print(ps)
print(len(ps))
print(ps.keys)
for key in ps.keys():
print("key %s, ps[key] = %s" % (key, ps[key]))