fork download
  1. class MyClass():
  2.  
  3. def __init__(self):
  4. self.ID = self.id_generator()
  5.  
  6. def id_generator(self):
  7. id_ = 0
  8. while 1:
  9. id_ += 1
  10. yield id_
  11.  
  12.  
  13. def order(self):
  14. return {'Type': 'CLIENT',
  15. 'Id': next(self.ID)}
  16.  
  17.  
  18. customer = MyClass()
  19. print(customer.order())
  20. print(customer.order())
  21. customer = MyClass()
  22. print(customer.order())
  23. print(customer.order())
  24. print(customer.order())
  25.  
Success #stdin #stdout 0.02s 9084KB
stdin
Standard input is empty
stdout
{'Type': 'CLIENT', 'Id': 1}
{'Type': 'CLIENT', 'Id': 2}
{'Type': 'CLIENT', 'Id': 1}
{'Type': 'CLIENT', 'Id': 2}
{'Type': 'CLIENT', 'Id': 3}