Python: 在子类中删除一个类属性

9 浏览
0 Comments

Python: 在子类中删除一个类属性

我有一个子类,我希望它不包含在基类上存在的类属性。

我尝试了这个,但它不起作用:

>>> class A(object):
...     x = 5
>>> class B(A):
...     del x
Traceback (most recent call last):
  File "", line 1, in 
    class B(A):
  File "", line 2, in B
    del x
NameError: name 'x' is not defined

我该怎么做?

0