该功能缺点是必须保证该文件不存在的情况才会成功
f=open('E:/mywork/保存文件.txt','x')def userwrite(code):if code=='w':f.close()return Falseelse:f.writelines(code+'\n')return True isbool = True count = 0 while isbool:code=''if count==0:code = input("请输入内容:\n")else:code = input("")isbool = userwrite(code)count+=1