John wrote:

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...

Then give it one.

class MyTools:

Add an initialisation method:

    def __init__(self, this):
        self.this = this

    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()

And change this to:

    def __init__(self):
        self.this = 'My Process, this'
        self.tools = MyTools(self.this)
        self.tools.f(self.this)
        self.tools.foo()



There are probably better, or at least other, ways to organise the code which will do the job. An abstract base class with just the shared methods might work. (I'm not sure if that's best described as a mixin or not...)

class SharedMethods(object):
    # shared methods go here

class FirstRunner(SharedMethods):
    # methods unique to FirstRunner

class SecondRunner(SharedMethods):
    # methods unique to SecondRunner




--
Steven
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to