Python __class__ Attribute : Design Patterns In Python

Опубликовано: 18 Март 2021
на канале: SBCODE
796
11

Channel Membership :    / @sbcode  

Documentation : https://sbcode.net/python/proxy/#__cl...

You can change the class of an object by executing self.__class__ = SomeOtherClass

Note that doing this does not affect any attributes created during initialisation, eg self.instance_attribute = 'abc' , since the object itself hasn't changed. Only the references to it's methods and static attributes have been replaced with the methods and static attributes of the new class.

This explains how calling tell_me_the_future() and tell_me_your_form() from the Proxy use case example, produced different results after changing self.__class__

(Book) Sometimes you just want to switch off your computer and read from a book. So, all GoF patterns are discussed in my Design Patterns In Python book
https://www.amazon.com/dp/B08XLJ8Z2J : ASIN B08XLJ8Z2J
https://www.amazon.com/dp/B08Z282SBC : ASIN B08Z282SBC

#python
#designPatterns
#pythonDesignPatterns


На этой странице сайта вы можете посмотреть видео онлайн Python __class__ Attribute : Design Patterns In Python длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь SBCODE 18 Март 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 796 раз и оно понравилось 11 зрителям. Приятного просмотра!