首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python资料读写1

2012-09-03 
python文件读写1写文件:import os?ls os.linesepfname raw_input(Please input a file path:)while

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"

热点排行