Python 3多重继承__init__第二类

时间:2019-10-06 08:43:35

标签: python initialization multiple-inheritance

在Python3中,我有一个继承其他两个类的类。 但是,正如我看到的,当初始化一个对象时,仅初始化它的第一类也请参见示例...

    class A:
        def __init__(self):
            print("A constructor")


    class B:
        def __init__(self):
            print("B constructor")


    class C(A, B):
        def __init__(self):
            print("C constructor")
            super().__init__()


    c = C()

其输出为:

  

C构造函数   构造函数

我的问题是,为什么它也不同时调用B构造函数? 可以用C从C类调用B构造函数吗?

1 个答案:

答案 0 :(得分:1)

// Add to queue
client.on('message', async (message) => {

   // It's good practice to ignore other bots. This also makes your bot ignore itself and not get into a spam loop
    if(message.author.bot) return;

    if(message.content.startsWith(`${prefix}me`)){
        var temp = message.author;
        rankedList.push(temp);  // the array will dynamically grow
        console.log(message.author + "added to queue.");
        message.channel.send(`${message.author} added to queue.
        ${rankedList.map((player,index) => `${index+1} - ${player}`).join('
n')}`);
    }
});