[Tutor] help with 'organization'
steve at pearwood.info
Fri Aug 26 03:48:34 CEST 2011
> 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):
> def foo(self):
> this = self.this
> class MyProcess:
> def __init__(self):
> self.tools = MyTools()
> self.this = 'My Process, this'
And change this to:
self.this = 'My Process, this'
self.tools = MyTools(self.this)
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
# shared methods go here
# methods unique to FirstRunner
# methods unique to SecondRunner
More information about the Tutor