Class Foo (object): def exec (self): raise Notimplementederror (' implement Exec method ') class A (Foo): passobj=a () Obj.exec ()
Class A inherits the class Foo and therefore owns all the properties of Class Foo. Class A instantiates an object obj,obj calls the Exec () method, and throws an exception if Class A does not define its own Exec method.
From ABC import abstractmethod,abcmetaclass Foo (Metaclass=abcmeta): @abcstractmethod def exec: Passclass A (Foo): passobj=a ()
Call the class Abstractmethod and class Abcmeta from the ABC module, define the class Foo yourself, inherit the abstract class Abcmeta, define the Exec method in class Foo, and add the adorner abcstractmethod. Defining Class A inherits the class Foo and instantiates the object obj, Class A must have a method in class Foo or an exception will be thrown.
Abstract classes and abstract methods of Python