从python中的基类继承namedtuple

2024-04-24 21:13:51 发布

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

是否可以生成继承自基类的namedtuple?在

我想要的是CircleRectanglenamedtuple,并且是从一个公共基类('Shape')继承的:

from collections import namedtuple

class Shape:
    def addToScene(self, scene):
         ...

Circle=namedtuple('Circle', 'x y radius')
Rectangle=namedtuple('Rectangle', 'x1 y1 x2 y2')

我该怎么做?在


Tags: fromimportselfdefscene基类namedtuplecollections