+ -
当前位置:首页 → 问答吧 → is there a way to define a pure virtual base class in python

is there a way to define a pure virtual base class in python

时间:2010-11-06

来源:互联网

is there any way to create a pure virtual base class like C++
or let a class declare it conform to some protocol like in Object-C

作者: beyond_touch   发布时间: 2010-11-06

I found a solution
  1. from abc import ABCMeta

  2. class MyABC(metaclass=ABCMeta):
  3.     pass

  4. MyABC.register(tuple)

  5. assert issubclass(tuple, MyABC)
  6. assert isinstance((), MyABC)
复制代码
http://docs.python.org/py3k/library/abc.html

作者: beyond_touch   发布时间: 2010-11-06