12.16
25.标准库
(1)turtle库:
(2)random库:
(3)os库:
(4)re库:
(5)string库:字符串常量库
(6)math库
26.第三方库:
(1)Wordcloud库
(2)jieba库
(3)imageio库
(4)matplotlib库
(5)requests库
#打开和关闭文件
'''
f=open('../Stu_pack/Dream It Possible.txt','rt',encoding='utf-8')
for line in f:
print(line)
f.close()
'''
#写入和读取文件
#(将Stu_pack里面的‘万疆.txt’写入demo中‘副本_万疆.txt’)
'''
fr=open('../Stu_pack/万疆.txt','rt',encoding='utf-8')
fw=open('副本_万疆.txt','w+',encoding='utf-8')
for line in fr:
fw.write(line)
fr.close()
fw.close()
'''
#复制和转换文件
#CSV-CSV
'''
fr=open('../Stu_pack/学生考勤.csv','rt')
fw=open('副本_学生考勤.csv','w+')
ls=[]
for line in fr:
line=line.replace('\n','') #删除换行符
line=line.split(',') #将每行数据以逗号分隔
ls.append(line) #将分隔的每个数据追加到列表内
print(ls)
for row in ls:
fw.write(','.join(row)+'\n') #在每个数据之间添加逗号,并且每行后面添加换行符
print(row)
fr.close()
fw.close()
'''
#CSV-TXT
fr=open('../demo/副本_学生考勤.csv','rt')
fw=open('副本_学生考勤.txt','w+')
ls=[]
for line in fr:
line=line.replace('\n','') #删除换行符
line=line.split(',') #将每行数据以逗号分隔
ls.append(line) #将分隔的每个数据追加到列表内
print(ls)
for row in ls:
fw.write('\t\t'.join(row)+'\n') #在每个数据之间添加逗号,并且每行后面添加换行符
print(row)
fr.close()
fw.close()
#P147-See You Again-统计频次
'''
import re
fp=open('../Stu_pack/See You Again.txt','r')
txt=fp.read()
fp.close()
txt=txt.lower()
txt=re.sub('[,.?:"\'!-]','',txt)
words=txt.split()
word_sq={}
for each in words:
if each not in word_sq.keys():
word_sq[each]=1
else:
word_sq[each]=word_sq[each]+1
print(word_sq)
res=sorted(word_sq.items(),key=lambda x:x[1],reverse=True)
print(res)
'''