Python Try

2018-07-17  本文已影响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()
上一篇下一篇

猜你喜欢

热点阅读