Reputation: 1056
Given the below cut down headache of a function, how would I go about calling a function on the utils.PrintingTemplateBase object that PrintingTemplate is inheriting?
I would also mention that PrintingTemplateBase requires an instance of itself to use (the closest being PrintingTemplate)
class PrintingTemplate (utils.PrintingTemplateBase) :
# Class used to accumulate lines of data
#
class LineData :
# Class constructor, optionally passed an existing instance in which case
# data is copied.
#
def __init__ (self, data = None) :
self.number_of_panes = 0
self.material = ''
#--------------------------------------------------------------------------
#
# LineData subclass for data coming from CalcGlass
#
class LineDataGlass (LineData) :
def __init__ (self, calc_glass) :
self.number_of_panes = calc_glass.calc_component.calc_subitem.item.quantity
try : self.material = calc_glass.glass_unit.workshop_description
except : self.material = 'Undefined glass'
def __init__(self) :
utils.PrintingTemplateBase.__init__ (self)
self.constants = None
Upvotes: 0
Views: 48
Reputation: 599630
Python is not Java.
In Python, declaring a class inside another class does not give it any special access to the parent class. That's why I said there's almost never a good reason to do this.
If you need a LineData instance to have access to a PrintingTemplate instance, you'll need to give it a reference to that instance, either by passing it into the __init__
method or by instantiating one directly there.
Upvotes: 3