Guest User

Untitled

a guest
Feb 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. from __future__ import division, with_statement
  4. import sys, os
  5.  
  6. class StrictPerson(object):
  7. __slots__ = ["first", "last", "age"]
  8.  
  9. def __str__(self):
  10. return "%s %s (%s)" % (self.first, self.last, self.age)
  11.  
  12. def main():
  13. me = StrictPerson()
  14.  
  15. try:
  16. print me
  17. except AttributeError:
  18. "Because I haven't set any of the required attributes, obviously."
  19.  
  20. me.first = "Jeremy"
  21. me.last = "Banks"
  22. me.age = 19
  23.  
  24. print me
  25.  
  26. try
  27. me.likesPotatoes = True
  28. except AttributeError:
  29. "Because I haven't made a slot for that attribute!"
  30.  
  31. if __name__ == "__main__": sys.exit(main())
Add Comment
Please, Sign In to add comment