Ha! Inheritance! On Thu, Aug 25, 2011 at 7:51 PM, John <washa...@gmail.com> wrote: > Hello, I am writing a module that will have two classes ('runners') I > am calling them, as they will ultimately use subprocess to run a > command line program, so they are basically option parsers, etc... > > As I wrote the second 'runner', I realized many of the methods are > going to be the same as the first, so I would actually like to create > a third class that has the methods which are mutual between the two. > The problem are the 'self' calls.... > > I know a code example might help, so I try to show it here (my code > I'm afraid is too complex and ugly at the moment). You can see the it > fails because MyTools doesn't have 'this' attribute... > > class MyTools: > def f(self, this): > print(this) > > def foo(self): > this = self.this > print(this) > > class MyProcess: > def __init__(self): > self.tools = MyTools() > > self.this = 'My Process, this' > > self.tools.f(self.this) > > self.tools.foo() > > if __name__ == "__main__": > mp = MyProcess() >
-- Configuration `````````````````````````` Plone 2.5.3-final, CMF-1.6.4, Zope (Zope 2.9.7-final, python 2.4.4, linux2), Python 2.6 PIL 1.1.6 Mailman 2.1.9 Postfix 2.4.5 Procmail v3.22 2001/09/10 Basemap: 1.0 Matplotlib: 1.0.0 _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor