Guest User

Untitled

a guest
Aug 26th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. class Thing:
  2. '''a class with a constructor (or other function)
  3. that takes a variable number of arguments and then
  4. sets them as class attributes conditionally.
  5. '''
  6. def __init__(self, **kwargs):
  7. for key, value in kwargs.items():
  8. setattr(self, key, value)
  9.  
  10. door = Thing(size='180x70', color='red chestnut', material='oak')
  11. print(door.size, door.color, door.material, sep = ', ')
  12.  
  13. house = Thing(height='23 m', doors=6, rooms=4, material='break') #180x70, red chestnut, oak
  14. print(house.height, house.doors, house.rooms, house.material, sep=', ') #23 m, 6, 4, break
Add Comment
Please, Sign In to add comment