美文网首页
Python Try

Python Try

作者: 闫_锋 | 来源:发表于2018-07-17 16:32 被阅读9次

Try

try:
    file=open('eeee.txt','r')  #会报错的代码
except Exception as e:  # 将报错存储在 e 中
    print(e)

##############################

try:
    file=open('eeee.txt','r+')
except Exception as e:
    print(e)
    response = input('do you want to create a new file:')
    if response=='y':
        file=open('eeee.txt','w')
        file.write('ssss')
        file.close()
    else:
        pass
else:
    file.close()

相关文章

网友评论

      本文标题:Python Try

      本文链接:https://www.haomeiwen.com/subject/lmlgpftx.html