Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. class IdCounter:
  2.     __counter = 0
  3.  
  4.     def __getattr__(self, attr):
  5.         if attr == 'id':
  6.             IdCounter.__counter += 1
  7.             self.id = IdCounter.__counter
  8.             return self.id
  9.         else:
  10.             raise AttributeError("no attribute '" + attr + "'")
  11.  
  12. class Account(IdCounter):
  13.     pass
  14.  
  15. class Vehicle(IdCounter):
  16.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement