- import os
- while True:
- filename=input(‘Please enter the filename‘)
- if os.path.exists(filename):
- print(‘the file is exist‘)
- break
- else:
- all=[]
- while True:
- content=input(‘>‘)
- if content==‘.‘:
- print(‘Exit‘)
- break
- else:
- all.append(content)
- fobj=open(filename,‘w‘)
- str_list=[i+‘\n‘for i in all]
- fobj.writelines(str_list)
- fobj.close()
- break
时间: 2024-10-15 03:48:08