try:
# int('qwe')
f = open('我为什么是一个文件.txt','w')
print(f.write('我存在了!!!'))
sum = 1+'1'
f.close()
#except OSError as reason:
# print('文件出错\n错误的原因是: '+str(reason))
#except TypeError as reason:
# print('类型出错\n错误的原因是: '+str(reason))
#except TypeError as reason:
# print('类型出错\n错误的原因是: '+str(reason))
except (OSError,TypeError):
print('出错了')
finally:
f.close()
finally
无论如何都会执行
来源:CSDN
作者:韩凯 dragon in sky
链接:https://blog.csdn.net/hk2121/article/details/104064589