python提取文件中的汉字

python提取文件中的汉字,第1张

概述读取指定目录下的文件,提取文件中的所有汉字#-*-coding:utf-8-*-importosimportioimportrefo=open("word.txt","w")#遍历指定目录,显示目录下的所有文件名defeach_file(filepath):forroot,dirs,filesinos.walk(filepath):forfileinfiles:

读取指定目录下的文件,提取文件中的所有汉字

# -*- Coding: utf-8 -*-import osimport ioimport refo = open("word.txt", "w")# 遍历指定目录,显示目录下的所有文件名def each_file(filepath):  for root, dirs, files in os.walk(filepath):    for file in files:      filename = @[email protected](root, file)      read_file(filename)def read_file(filename):  with io.open(filename, 'r', enCoding='utf-8', errors='ignore') as fn:    lines = fn.readlines()    han = re.compile('"[\u4e00-\u9fff]+"').findall(str(lines))    for val in han:      fo.write(val + "\n")if __name__ == '__main__':  each_file("src")
总结

以上是内存溢出为你收集整理的python提取文件中的汉字全部内容,希望文章能够帮你解决python提取文件中的汉字所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1185388.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存