【发布时间】:2015-09-07 12:54:04
【问题描述】:
import abc
class SetterGetter(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def set_val(self, inp):
return
@abc.abstractmethod
def get_val(self):
return
class TryAbsMethod(SetterGetter):
def get_val(self):
return self.inp
def set_valz(self, inp):
self.inp = inp
a = TryAbsMethod()
print(a)
根据教程,我期望从上面的代码中得到 excption,但我得到了来自 python 的输出,这很奇怪,有人可以解释一下为什么吗?
输出得到
/usr/bin/python3.4 /home/murtuza/MyCodes/abstract.py
<__main__.TryAbsMethod object at 0x7f93ba8ab048>
Process finished with exit code 0
预期的异常
TypeError: Can't instantiate abstract class TryAbsMethod with abstract method set_val
【问题讨论】:
-
你用的是哪个教程?
标签: python python-3.x