写文件:
import os
ls = os.linesep
fname = raw_input("Please input a file path:")
while True:
if os.path.exists(fname) and os.path.isfile(fname):
fname = raw_input("ERROR: '%s' is exist,Please input another file path:"%fname)
else:
break
all=[]
print "\nEnter lines ('.' by itself to quit).\n"
while True:
entry = raw_input(">>>")
if entry == ".":
break
else:
all.append(entry)
fobj = open(fname,"w")
fobj.writelines(['%s \n' % (x) for x in all])
fobj.close()
print "DONE"