[Python] 纯文本查看 复制代码 #-*-coding:GBK-*-
import os
name = raw_input("请输入文件名:")
qrwz = True
while qrwz:
if os.path.exists(name) == True:
qrwj = raw_input('文件名存在!是否替换?<y/n>').strip()
if qrwj == 'y':
print '替换成功!请输入内容!'
all = []
while True:
shuru = raw_input('>>>>')
if shuru == '.':
break
else:
all.append(shuru)
op = open(name,'w')
op.writelines(['%s%s' % (x,'\n') for x in all])
op.close()
print '成功'
qrwz = False
elif qrwj != 'n':
print '输入正确请输入正确指令'
else:
exit()
else:
all = []
while True:
shuru = raw_input('>>>>')
if shuru == '.':
break
else:
all.append(shuru)
op = open(name,'w')
op.writelines(['%s%s' % (x,'\n') for x in all])
op.close()
print '成功'
break
新手,求照顾 |