17. python 错误捕捉

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

  

try:

  ...

except Exception as e:

  print(e)

posted @ 2017-03-18 12:43  涵叔  阅读(101)  评论(0)    收藏  举报