使用Python怎么查找文件中包含中文的行

  介绍

使用Python怎么查找文件中包含中文的行?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

# !/usr/bin/env  python3   #,- *安康;编码:utf-8  - * -   #,find 从而,line  of  containing  chinese 拷贝文件      时间=__author__  & # 39;爱# 39;      import 再保险      def  start_find_chinese ():=,find_count  0;   ,with 开放(& # 39;ko_untranslated.txt& # 39;,, & # 39; wb # 39;), as 输出文件:   with 才能打开(& # 39;source_ko.txt& # 39;,, & # 39; rb # 39;), as  infile:   ,,while 真正的:   ,,,content =, infile.readline ()   ,,,if  re.match (" # 39; (。* [\ u4E00 - \ u9FA5] +) | ([\ u4E00 - \ u9FA5] +。*) & # 39;,, content.decode (& # 39; utf - 8 # 39;)):   ,,,,outfile.write(内容)   ,,,,find_count  +=, 1;      ,,,if  not 内容:   ,,,,return  find_count      # start 用发现   if  __name__ ==, & # 39; __main__ # 39;:=,,count  start_find_chinese ()   ,打印(“find 完成!,count =?,, count)

<强>原始文件

source_ko。txt文件内容

3, ? ? ?, Lv.50  ? ?   8,? ? ?,Lv.80  ? ?   10,? ? ?,Lv.90  ? ?   …   …   2840年,飞黄腾达   4841年,同归于尽   8848年,? ? ?,Lv.50  ?

<强>运行效果(ko_untranslated.txt文件)

2840,飞黄腾达   之前4841年,同归于尽 Python主要用来做什么

Python主要应用于:1,网络开发;2、数据科学研究;3,网络爬虫;4、嵌入式应用开发,5日游戏开发;6桌面应用开发。

关于使用Python怎么查找文件中包含中文的行问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注行业资讯频道了解更多相关知识。

使用Python怎么查找文件中包含中文的行