如何在python中进行类的约束

使某些类必须有一些方法

1 python 的抽象类实现

        === 约束性不高

			Python是 解释性语言

		from abc import ABCMeta
from abc import abstractmethod class Base(ABCMeta);
def send(*args,**kwargs):
pass class A(Base):
pass 运行的时候才报错
不运行不会报错

2 通过父类抛异常实现

                    class Base(object):
def send(*args,**kwargs):
raise NotImplementError('未实现的方法') class A(Base):
pass 定义一个需要重写的方法,否则会抛出异常

最新文章

  1. Ternary Expression Parser
  2. Ubuntu 安装Theano
  3. 使用JSP开发动态网站基础
  4. Java+FlexPaper+swfTools仿百度文库文档在线预览系统设计与实现
  5. Aspect Oriented Programming using Interceptors within Castle Windsor and ABP Framework AOP
  6. spring-boot项目在外部tomcat环境下部署
  7. 我来说说MVC过滤器
  8. 添加gif效果图
  9. Linux基本命令(5)管理使用者和设立权限的命令
  10. js如何判断一个数组中是否有重复的值
  11. php cloure闭包
  12. Mac os 进行Android开发笔记(1)
  13. 5.1 timestamp数据类型默认值
  14. spring的Convert机制
  15. 算法(第四版)C# 习题题解——1.3
  16. pip3 install pymysql
  17. How to Pronounce We’ll Contraction
  18. JPA注解指南
  19. Web开发中常用的定位布局position
  20. cf1088D. Ehab and another another xor problem(思维)

热门文章

  1. iOS学习之库
  2. 爬虫基础库之requests模块
  3. open函数and文件处理
  4. event driven model
  5. $Android去除系统默认的标题栏和全屏的三种方法
  6. requestAnimationFrame 的实验性实践
  7. h5新特性 File API详解
  8. python的计算保留小数
  9. groupby和agg的使用
  10. Harbor 镜像管理专家