Steven D'Aprano a écrit :
I have some code that currently takes four different classes, A, B, C and
D, and subclasses each of them in the same way:
class MyA(A):
def method(self, x):
result = super(MyA, self).method(x)
if result == "spam":
return "spam spam spam"
On Sat, 11 Sep 2010 08:53:38 +0200, Peter Otten wrote:
> Steven D'Aprano wrote:
>
>> I have some code that currently takes four different classes, A, B, C
>> and D, and subclasses each of them in the same way:
[...]
>> Any suggestions or guidelines?
>
> You could use a mixin:
Nice! I'll give it
Steven D'Aprano wrote:
> I have some code that currently takes four different classes, A, B, C and
> D, and subclasses each of them in the same way:
>
> class MyA(A):
> def method(self, x):
> result = super(MyA, self).method(x)
> if result == "spam":
> return "spam
I have some code that currently takes four different classes, A, B, C and
D, and subclasses each of them in the same way:
class MyA(A):
def method(self, x):
result = super(MyA, self).method(x)
if result == "spam":
return "spam spam spam"
return result
#