Suppose I have two classes of objects, A and B. Both are linked together in a database. We have an Event and a series of Actions associated with each event, and some attributes of each.
class Event(object):
def __init__(self, ...some irrelevant attributes...):
self.attributes = attributes
self.actions = []
def add_action(self, action):
self.actions.append = action
class Action(object):
def __init__(self, ...some irrelevant attributes...):
self.attributes = attributes
self.event = None
def add_event(self, event):
self.event = event
# I would like to make self part of event.actions as above
When I call
event = Event(...)
in Action(...) to add Action to an event in a database, is there a legal way in Python to make the Action itself (self) part of Event's list of Actions?
Just call
add_action()Also, you have a mistake in
add_action(). It should call theappend()method, not assign to it.