I've been on an OOP exploration kick lately.
I have two classes: one for an event and one to calculate some set of attributes of that event.
class Event(object):
def __init__(self,name,info):
self.name = name
self.category = info.category
self.classification = info.classification
@property
def attributes(self):
return dict((k,v) for k,v in self.__dict__.items())
class class1(object):
def __init__(self,some_number):
self.number = some_number
@property
def category(self):
#stuff
return category
@property
def classification(self):
#stuff
return classification
Right now I can do something like
e = Event('myevent', class1(42))
e.attributes
{'category': 1,
'classification': None,
'name': 'myevent'}
But I want to have the option of giving Event()
instances of any number/combination of future class2
, class3
, etc; and therefore I want Event()
's init()
method to gracefully handle them so that e.attributes
will return all appropriate attributes. Giving Event.__init__
a *param to unpack doesn't seem to bypass the need for it to know the attribute names it needs to assign to itself. Ultimately what I want to do is to be able to create this event and then create/update its varying sets of attributes as needed later, using this paradigm. Is it possible?