Inheritance vs class instance in python module import

后端 未结 2 1011
盖世英雄少女心
盖世英雄少女心 2021-01-13 20:15

Apologies if this doesn\'t make sense, i\'m not much of an experienced programmer.

Consider the following code:

import mymodule

class MyClass:
             


        
2条回答
  •  佛祖请我去吃肉
    2021-01-13 20:51

    You make it sound like you're trying to "choose between" those two approaches, but they do completely different things. The second one defines a class that inherits from a class (confusingly) called classInstance. The first one defines a class called MyClass (not inheriting from anything except the base obect type) that has an instance variable called self.classInstance, which happens to be set to an instance of the classInstance class.

    Why are you naming your class classInstance?

提交回复
热议问题