I use boto to control EC2 . It provides an instance class. I would like to subclass it to meet my specific needs. Since boto provides a query interface to get your instances, I need to convert something between classes. This solution seems to work, but changing the attribute of the class seems dodgy. Is there a better way?
from boto.ec2.instance import Instance as _Instance class Instance(_Instance): @classmethod def from_instance(cls, instance): instance.__class__ = cls # set other attributes that this subclass cares about return instance
I would not subclass or drop. I don't think casting is a good policy.
Instead, consider a wrapper or facade.
class MyThing( object ): def __init__( self, theInstance ): self.ec2_instance = theInstance
MyThing , , boto.ec2.instance.Instance. .
MyThing
boto.ec2.instance.Instance
Source: https://habr.com/ru/post/1709525/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1709520/efficient-way-to-implement-paged-sql-result-table-in-a-java-desktop-application&usg=ALkJrhhK089dnnSkddCXFbMefR5EUooNLgHow to make AnkhSVN remember my SVN + SSH password? - svnIO Other operations Performance counter Explanation - performanceWhat are the benefits of using InfoPath forms in SharePoint? - infopathSSRS report loses formatting in interactive view - sql-server-2005At what point does segfault happen? - cWhat are the best methods for the AspNetDevelopmentServerHost attribute? - tfsNET enumerations of symbolic constants for string values - enumshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1709529/core-data-is-it-possible-to-build-a-desktop-app-to-create-the-data-model-for-an-iphone-app-with-core-data&usg=ALkJrhhtqZ0lQEAzSKBf8Lql6I8hbMKTBwHow to stop execution for ALL exceptions during debugging in Visual Studio? - c #All Articles