[Tutor] OOD - Another class question
C.T. Matsumoto
tmatsumoto at gmx.net
Mon Mar 1 09:50:22 CET 2010
James Reynolds wrote:
> I have another question related to OOD. What I have is a module with
> one parent class and two child classes. Some stuff is done to the
> object that is passed to the function in one of the child classes and
> this then calls a function from the global class passing local
> variables (from the child class).
>
> When I do this, I am told: AttributeError: 'HillBuilder' object has no
> attribute 'MountainBuilder'
>
> The question is, what am I doing wrong?
>
> Here is an example:
>
> class MountainBuilder(object):
> def __init__(self, mountain):
> self.mountain = mountain
> self.mountain_func
> self.pinetree_func
>
>
> def pinetree_func(self, knoll)
> do stuff to knoll
> return knoll
>
>
> def mountain_func(self, hill)
> knoll = hill * 2
> pinetree = pintree_func(knoll)
> return hill
>
>
> class HillBuilder(MountainBuilder):
> def __init__(self, mountain):
> OptionLoad.__init__(self, mountain)
> self.MountainBuilder.mountain_func
> self.hill_func
>
>
> def hill_func(self)
> hill= do stuff to self.mountain
> grassyknoll = MountainBuilder.mountain_func(hill)
>
> return grassy knoll
>
>
> do stuff with grassy knoll
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
The line grassyknoll = MountainBuilder.mountain ...
Since you inherit MountainBuilder you call the mountain_func (which is a
method :-) ) with self:
grassyknoll = self.mountain_func(hill)
All methods inside the MountainBuilder can be called as if they are a
part of the HillBuilder (thus inheritance).
Cheers,
T
More information about the Tutor
mailing list