读书人

python资料读写1

发布时间: 2012-09-03 09:48:39 作者: rapoo

python文件读写1

写文件:

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"

读书人网 >perl python

热点推荐