In this paper, we describe the method of Python3 reading UTF-8 file and statistic file line number. Share to everyone for your reference. The implementation method is as follows:
"" Created on Dec, Python read the number of rows in the UTF-8 file statistics file @author: Liury_lab "#-*-coding:utf-8-*-import codecs # for smaller File, the simplest way is to read the file into a list of rows, # and then calculate the length of the table by Count = Len (Codecs.open (' d:/freakout.cpp ', ' RU ', ' utf-8 '). ReadLines ()) Print ( Count) # for larger files, can cycle count count =-1 for count, line in enumerate (Codecs.open (' d:/freakout.cpp ', ' RU ', ' Utf-8 ')): Pass Cou NT + = 1 print (count) # for "\ n" like the Windows end tag, there are also the following options: Count = 0 the_file = codecs.open (' d:/freakout.cpp ', ' RB ', ' Utf-8 ') w Hile (True): buffer = the_file.read (8192*1024) if not buffer: break
Hopefully this article will help you with Python programming.