在FactsheetExporter
,我有data
实例变量。我需要将data
作为实例变量传递给Parameter
类,但不知道如何。你知道怎么做吗?
class FactsheetExporter:
def __init__(self):
self.data = {somedata...}
class Parameter:
def __init__(self):
self.data = data
def compute(self):
do_stuff(self.data)
# do data stuff...
class PortfolioFactsheetExporter(FactsheetExporter):
class Meta(FactsheetExporter.Meta):
name = "export_portfolio_factsheets"
entities = Parameter()
答案 0 :(得分:1)
data
是类FactsheetExporter
的实例变量。因此,必须将FactsheetExporter
的实例发送到Parameter
才能访问data
。
class FactsheetExporter:
def __init__(self):
self.data = {somedata...}
class Parameter(FactsheetExporter):
def compute(self,FactsheetExporter_var):
data = FactsheetExporter_var.data
# do data stuff...
object1 = FactsheetExporter()
#Object1 should be passed to Parameter in order for it to be able to access data variable
object2 = Parameter(object1)
object2.compute(value_for_data)