Guest User

Untitled

a guest
Feb 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. Type "help", "copyright", "credits" or "license" for more information.
  2. >>> Tester = type('Tester', (object, ), {})
  3. >>> foo = Tester()
  4. >>> foo.__class__
  5. <class '__main__.Tester'>
  6. >>> foo.__class__ = 'SomeOther'
  7. Traceback (most recent call last):
  8. File "<stdin>", line 1, in <module>
  9. TypeError: __class__ must be set to new-style class, not 'str' object
  10. >>> Bar = type('Bar', (object, ), {})
  11. >>> foo.__class__ = Bar
  12. >>> Bar = type('Bar', (object, ), {'some': 'other'})
  13. >>> foo.some
  14. Traceback (most recent call last):
  15. File "<stdin>", line 1, in <module>
  16. AttributeError: 'Bar' object has no attribute 'some'
  17. >>> foo.__class__ = Bar
  18. >>> foo.some
  19. 'other
Add Comment
Please, Sign In to add comment