[Tutor] python varying mulitple inheritance

kendy at kendy.org kendy at kendy.org
Tue Jun 19 07:14:52 CEST 2012

Hmmm. No need to write the whole thing written out. Just how not to code:

class Pocket1(Wallet, Keys, Comb, Usb, CellPhone, WorkBadge):
class Pocket2(Wallet, Keys, Comb, Usb, CellPhone):
class Pocket3(Wallet, Keys, Comb, Usb,            WorkBadge):
class Pocket4(Wallet, Keys, Comb, Usb):
class Pocket5(Wallet, Keys, Comb,      CellPhone, WorkBadge):
class Pocket6(Wallet, Keys, Comb,      CellPhone):

On Mon Jun 18 22:03 ,  sent:

>Thank you Steve, for the pointing me in a smarter direction!
>My immediate homework is:
>- Practice consistent conventions for naming things -- pep-0008.
>- Learn composition/has-a. 
>I thought of a better way to think of my problem. A list element would contain
>the things that Bob has in his pockets, at a given moment. For example:
>Bob has 6 things. They are well known things and it's easy to make a class for
>each of them. But Bob could have 2 to the power of 6, combinations of those
>things in his pockets. I don't want to make 64 classes, to cover each possible
>combination. I would read from a file to know what Bob has:
>time wallet keys comb USB cell_phone work_badge
>0    0      0    0    0   0          0
>1    1      1    0    0   0          1
>2    0      0    0    0   1          0
>3    0      0    0    0   1          1
>4    1      1    1    1   0          0
>    0 = not in his pocket
>    1 = has-a in his pocket
>I don't want an instance of something, if it's not in Bob's pocket at that time.
>(Maybe I'm making it harder than it needs to be.)
>If no one responds, it's OK because now I know where to focus. (But help would be
>I was told that you guys were great. You are!!!
>On Sun Jun 17 18:36 , Steven D"Aprano  sent:
>>kendy at kendy.org wrote:
>>> Hello
>>> I'm new to classes. And I hope the my question isn't too big.
>>> I have electronic test equipment, but thought that a boat example
>>> would be easier. Can you help me untangle my class design?
>>> My problem is basically multiple inheritance, but I want to be
>>> flexible for how many will inherit.
>>Your first problem is that you are misusing inheritance when you should be 
>>using composition instead.
>Tutor maillist  -  Tutor at python.org
>To unsubscribe or change subscription options:

More information about the Tutor mailing list