Okay

class A:
   def __init__(self,x,y):
     self.x = x
     self.y = y

   def save(self,fn):
     f = open(fn,"w")
     f.write(str(self.x)+ '\n') # convert to a string and add newline
     f.write(str(self.y)+'\n')
     return f             # for child objects to use

   def restore(self, fn):
     f = open(fn)
     self.x = int(f.readline()) # convert back to original type
     self.y = int(f.readline())
     return f

class B(A):
   def __init__(self,x,y,z):
     A.__init__(self,x,y)
     self.z = z

   def save(self,fn):
     f = A.save(self,fn)  # call parent save
     f.write(str(self.z)+'\n')
     return f         # in case further children exist

   def restore(self, fn):
     f = A.restore(self,fn)
     self.z = int(f.readline())
     return f

In the class B,  I'm not understanding the A.__init(self,x,y) part.  So its
initializing the class A, and basically you can use the A class like normal?
Part im confused about is the self.z, does that belong to the class A or
class B?  Else I think I'm understanding it correctly.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to