|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
小白在此求助给为路过的大佬帮忙审查一下bug出在哪里,感激不尽!
工作环境:win10系统, Python3.6.5, idlex编程环境.
代码如下:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#针对不同异常设置多个except:
try:
sum1 = 1 + "1"
f = open("我是一个不存在的文档呀.txt")
print(f.read())
f.close()
except TypeError as reason:
print("类型出错啦T_T\n错误原因是:", +str(reason))
except OSError as reason:
print("文件出错啦T_T\n错误原因是:", +str(reason))
----------------------------------------------------------------运行结果出错:
Traceback (most recent call last):
File "D:/Python源代码组/fish_05.25.py", line 31, in <module>
sum1 = 1 + "1"
TypeError: unsupported operand type(s) for +: 'int' and 'str'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/Python源代码组/fish_05.25.py", line 36, in <module>
print("类型出错啦T_T\n错误原因是:", +str(reason))
TypeError: bad operand type for unary +: 'str'
==========================================
代码来源于小甲鱼<零基础入门Python>第二版,page121,照葫芦画瓢也能出bug,我今晚真想喝碗甲鱼汤补补脑了,哼!
print("文件出错啦T_T\n错误原因是:", +str(reason))
改为
print("文件出错啦T_T\n错误原因是:" +str(reason))
去掉逗号
|
|