python异常处理模块raise NotImplementedError
2023-09-14 09:15:32 时间
raise NotImplementedError的使用感觉很类似于C#中虚函数的效果,它的意思是如果这个方法没有被子类重写,但是调用了,就会报错。
唯一的作用就是把这个异常内置进去,然后写父类方法的时候抛出这个异常,报错的时候比较容易看,最终为了方便调试bug。
'''
# class TestClassOne(object):
#
# def Test(self):
# raise NotImplementedError
#
# class TestClassTwo(TestClassOne):
#
# def Test2(self):
# print('hello world')
#
# a = TestClassTwo()
# a.Test()
# coding=utf-8
# class TestClassOne(object):
# def Test(self):
# raise NotImplementedError
#
# class TestClassThree(TestClassOne):
# def Test(self):
# print('hello world')
#
# b = TestClassThree()
# b.Test()
#
# import abc
#
#
# class MyAbstractClass(object):
#
# @abc.abstractmethod
# def my_method(self):
# print('hello world')
# pass
# T = MyAbstractClass()
# T.my_method()
class ClassDemo:
def test_demo(self):
raise NotImplementedError("test:代码从这里出现异常啦!请尽快修复!")
class ChildClass(ClassDemo):
pass
inst = ChildClass()
inst.test_demo()
输出结果:
Traceback (most recent call last):
File "ors.py", line 56, in <module>
inst.test_demo()
File "ors.py", line 49, in test_demo
raise NotImplementedError("test:代码从这里出现异常啦!请尽快修复!")
NotImplementedError: test:代码从这里出现异常啦!请尽快修复!
相关文章
- 做自动化测试选择Python还是Java?
- python fileinput_Python之fileinput模块学习「建议收藏」
- python hashlib_Python hashlib模块实例使用详解
- python常用模块大全_python常用
- 【说站】python中pandas模块查看DataFrame
- 【说站】Python中Exchange发邮件
- 【说站】python模块如何安装
- 【说站】Python中filecmp模块的介绍
- python抛出异常和捕获异常_Python异常
- lambda表达式pythonlist_python lambda表达式简单用法【转】「建议收藏」
- Python保存json_python保存json文件
- PYTHON 用几何布朗运动模型和蒙特卡罗MONTE CARLO随机过程模拟股票价格可视化分析耐克NKE股价时间序列数据|附代码数据
- 校园网自动认证python脚本的实现 - wuuconix's blog
- Python traceback模块:获取异常信息
- Python包(存放多个模块的文件夹)
- Python os.path模块常见函数用法(实例+详细注释)
- python datetime库使用代码详解编程语言
- python_Day44_IO多路复用详解编程语言
- python之os模块详解编程语言
- 快速安装Python MySQL模块(python安装mysql模块)
- python驱动使用pip安装MySQL Python驱动的简单步骤(pip安装mysql)
- Python与Linux:开启互联网信息技术时代(python和linux)
- Linux系统下安装Python模块指南(linux安装python模块)
- Python操作MySQL数据库的必备模块mysqlpython(mysql_python)
- 在Python安装MySQL支持模块的方法
- Python中urllib2模块的8个使用细节分享
- python实现多线程暴力破解登陆路由器功能代码分享
- python中bisect模块用法实例