Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Type "help", "copyright", "credits" or "license" for more information.
- >>> Tester = type('Tester', (object, ), {})
- >>> foo = Tester()
- >>> foo.__class__
- <class '__main__.Tester'>
- >>> foo.__class__ = 'SomeOther'
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- TypeError: __class__ must be set to new-style class, not 'str' object
- >>> Bar = type('Bar', (object, ), {})
- >>> foo.__class__ = Bar
- >>> Bar = type('Bar', (object, ), {'some': 'other'})
- >>> foo.some
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- AttributeError: 'Bar' object has no attribute 'some'
- >>> foo.__class__ = Bar
- >>> foo.some
- 'other
Add Comment
Please, Sign In to add comment