如何使用python中的另一个类访问子类方法?

2024-06-16 19:04:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经编写了抽象基类的代码,如何使用另一个类访问子类方法(enviroment\u trees)?有可能吗?你知道吗

from abc import ABCMeta, abstractmethod


class EnvironmentAsset(object):
    __metaclass__ = ABCMeta

    @abstractmethod
    def __init__(self):
        print("method1")


class Trap(EnvironmentAsset):
    def __init__(self):
        super(Trap, self).__init__()

    @abstractmethod
    def enviorment_trees(age):
    print("age",age);
    return

Tags: 方法代码selfageinitdef基类子类