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') else: pass else:#try里的代码成功执行完后,才会走else file.write('ssss') file.close()