Sharing Base Class members

Greg Lindstrom greg.lindstrom at
Mon Jul 12 16:27:30 CEST 2004


I have a base class which does the heavy lifting associated with creating,
modifying, and writing record segments for an application I've developed.
One of the requirements of the app is I must track how many segments have
been written to the output stream.  Since the Write() method is in the base
class, I'd like to add a member in the base class, but I would like to
"share" it across all objects created with the base class. Suppose

class myBase:
    def __init__(self, op=None):
         self.op = op
         self.segment = 'This is a test'
    def Write(self):
          if self.op is not None:  op.Write(self.segment)

class A(myBase, op=None):
     def __init__(self, op=op):

class B(myBase, op=None):
     def __init__(self, op=op):

Can, or rather *how*, can I add a member to myBase that will increment each
time A.Write() or B.Write() is called?  I will then add a
TotalSegmentsWritten() method to myBase to get the total number of segments

I'm using Python 2.3.3 on Windows XP "professional"


Greg Lindstrom                                         (501) 975-4859
NovaSys Health                  greg.lindstrom at

"We are the music makers, and we are the dreamers of dreams"  W.W.

More information about the Python-list mailing list