社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

如何在Python中让类继承其父类的值?

pylab • 6 年前 • 1938 次点击  

下面是我想做的一个粗略的想法:

class PlayerModel(Timeline):
    def __init__(self, name):
        self.name = name

        self.timeline_min = super(timeline_min)     # I don't know the syntax for this
        self.timeline_max = super(timeline_max)     # I don't know the syntax for this


class Timeline:
    def __init__(self):
        self.timeline_min = 0
        self.timeline_max = 120

    def make_model(self, m_name):
        return PlayerModel(m_name)

我想要 PlayerModel 拥有相同的属性 Timeline 它们是:

self.timeline_min = 0
self.timeline_max = 120

在里面 __init__ ,而不必将它们作为参数传递。我能用 super() ? 我找不到一种方法来处理父变量。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/51892
文章 [ 1 ]  |  最新文章 6 年前