Python 2.7 Inheriting Values from a Class which Inherits Values from User Input -
learning python , making program... have read docs , forums on inheritance, struggling wrap head around while trying implement it. can please me understand?
i understand, think, inheritance user defined data class, implemented it. want have class inherit class inherits user defined data, second degree inheritance?
i building program uses heavy math. have portion user define: angle, x0:x5, , y0:y5. have class calculate_xy_at_angle takes user defined data , calculates new x , y points.
then have class take new x , y points , calculate ax:fx , ay:fy polynomial equation. code follows (i cut out code after x2... long , picture)
my problem don't understand how values
class calculate_xy_at_angle
pass calculated values
class abcdef_of_x?
and once user defines data, how retrieve values last class? have do, in sense, pipeline started?
### placeholders user defined data angle = 30 x0 = 0 x1 = 1 x2 = 5 x3 = 7 x4 = 5 x5 = 1 y0 = 0 y1 = 5 y2 = 8 y3 = 9 y4 = 2 y5 = 0 class calculate_xy_atangle(object): def __init__(self,angle,x0,x1,x2,x3,x4,x5,y0,y1,y2,y3,y4,y5): # user defined data self.angle = angle self.x0 = x0 self.x1 = x1 self.x2 = x2 self.x3 = x3 self.x4 = x4 self.x5 = x5 self.y0 = y0 self.y1 = y1 self.y2 = y2 self.y3 = y3 self.y4 = y4 self.y5 = y5 ### x def x0_at_angle(self): x_0 = (self.x0*math.cos(math.radians(self.angle)))-(self.y0*math.sin(math.radians(self.angle))) print x_0 return x_0 def x1_at_angle(self): x_1 = (self.x1*math.cos(math.radians(self.angle)))-(self.y1*math.sin(math.radians(self.angle))) print x_1 return x_1 def x2_at_angle(self): x_2 = (self.x2*math.cos(math.radians(self.angle)))-(self.y2*math.sin(math.radians(self.angle))) print x_2 return x_2 #### more code ### y def y0_at_angle(self): y_0 = (self.x0*math.sin(math.radians(self.angle)))+(self.y0*math.cos(math.radians(self.angle))) print y_0 return y_0 def y1_at_angle(self): y_1 = (self.x1*math.sin(math.radians(self.angle)))+(self.y1*math.cos(math.radians(self.angle))) print y_1 return y_1 def y2_at_angle(self): y_2 = (self.x2*math.sin(math.radians(self.angle)))+(self.y2*math.cos(math.radians(self.angle))) print y_2 return y_2 ### more code class abcdef_of_x(calculate_xy_atangle): # should inherit values previous class def __init__(self,.....???): # stuck on how initialize , define self.x0 = x0 # ? self.x1 = x1 # ? self.x2 = x2 self.x3 = x3 self.x4 = x4 self.x5 = x5 def ax(self): ax = (-1*self.x0)+(5*self.x1)+(-10*self.x2)+(10*self.x3)+(-5*self.x4)+(self.x5) print "ax =", ax return ax def bx(self): bx = (5*self.x0)+(-20*self.x1)+(30*self.x2)+(-20*self.x3)+(5*self.x4) print "bx =", bx return bx def cx(self): cx = (-10*self.x0)+(30*self.x1)+(-30*self.x2)+(10*self.x3) print "cx =", cx return cx ## more code class abcdef_of_y(object): # should inherit first class def __init__(self, y0, y1, y2, y3, y4, y5): self.y0 = y0 self.y1 = y1 self.y2 = y2 self.y3 = y3 self.y4 = y4 self.y5 = y5 def ay(self): ay = (-1 * self.y0) + (5 * self.y1) + (-10 * self.y2) + (10 * self.y3) + (-5 * self.y4) + (self.y5) print "ay =", ay return ay def by(self): = (5 * self.y0) + (-20 * self.y1) + (30 * self.y2) + (-20 * self.y3) + (5 * self.y4) print "by =", return ### more code
ok, missed out little big thing i, state point should remember sufficient solve problem
class claculate_xy_atangle(object): def __init__(self, x, y): self.x = x self.y = y class abcdef_of_x(calculate_xy_atangle): def __init__(self): super().__init__(x, y) #call parent class constructor prerogative of child class def get_x_y(): return self.x, self.y if __name__ == "__main__": child = abcdef_of_x(12, 10) x, y = child.get_x_y() #this give value 12, 10
now doubt why not super class calculate_xy_atangle doesn't call super().____init____(), default python since every class inherits super class object.
Comments
Post a Comment