# -*- coding: cp936 -*- import os #当前平台的行终止符 ls=os.linesep fname='C:\UsersAdministrator\Desktop\clt_workspace\20150526.txt' #判断文档是否存在,存在则继续,不存在则终止 while True: if os.path.exists(fname): print "%s is already exists" %fname break else: break #文档中输入内容 data=[] print ". means quit!" while True: entry=raw_input('>') if entry=='.': break else: data.append(entry) #写入到文档中 fobj=open(fname,'w') fobj.writelines(['%s%s'%(x,ls) for x in data]) fobj.close() print 'DONE'