tongjiword,write / read file demo

1.tong ji letter demo

mport sys

def tongjiword():
fi =open(paht,'r')
cont=fi.read()
wl={}
for line in fi.read():
lin =line.trip()
for i in range(len(lin)):
if lin(i) not in wl:
wl[lin(i)] =0
wl[line(i)] +=1

temp = sorted(wl.items,key=lambda:d:d(1),reverse=True)
print(temp)

f=open(path,'w',encoding='utf-8')
for item in temp:
str=item[0]","+ str(item[1])
f.write(str+"\n")
f.colse()

2. write read file demo

import sys


def reafile(path):
fi=open(path,"r")
#fi=open(path,"rb")
try:
text=fi.read()
#text=fi.read(100)
#text=fi.readlines()
finally:
fi.colse()

def writefile(path):
fi=open(path,"w")
#fi=open(path,'wb')
#fi=open(path,'w+')
try:
fi.write("alltext")
#fi.writelines("alltext")
finally:
fi.colse()

posted @ 2017-10-17 15:01  大树2  阅读(142)  评论(0编辑  收藏  举报