[英]Python - Automatically update base class attribute (alias) in inherited class
I'm sure this is something trivial, but I can't seem to find any insight from the Python (3) docs. 我敢肯定这是微不足道的,但是我似乎无法从Python(3)文档中找到任何见解。
Given the following code, how can I ensure that the t
class attribute in the base class is updated in the inherited class. 给定以下代码,如何确保在继承的类中更新基类的
t
类属性。
class DbBase:
table = None
t = table
class Articles(DbBase):
table = Table(....)
I'd now like to be able to refer to Article.table
as Article.t
as well. 我现在也希望能够将
Article.table
称为Article.t
。
Thanks! 谢谢!
Make t
a property
: 使
t
为property
:
class DbBase:
table = None
@property
def t(self):
return self.table
class Articles(DbBase):
table = {} # for demo purposes
A = Articles()
A.t # returns {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.