hi:
使用 python 對乙個大檔案按照行數進行切割:
跑起來跟烏龜一樣,簡直瘋掉。# -*- coding: utf-8 -*-
import os
""""
python 幹起活來 是真的慢
"""def split(fromfile,todir,linenum):
# 如果我資料夾不存在,則建立
if not os.path.exists(todir):
os.mkdir(todir)
else:
# 刪除舊的資料
for fname in os.listdir(todir):
os.remove(os.path.join(todir,fname))
partnum = 0
filenum = 0
# 開啟檔案
inputfile = open(fromfile,'rb')
# 讀取第一行
linestr = inputfile.readline()
# 用乙個字串進行暫存每個子檔案的文字
tempstr = bytes()
while linestr:
partnum += 1
tempstr = tempstr + linestr
if partnum >= linenum:
subfile = open(todir + str(filenum), 'wb')
subfile.write(tempstr)
subfile.close()
print(filenum)
filenum += 1
partnum = 0
tempstr = bytes()
# 讀取下一行
linestr = inputfile.readline()
# print(partnum, '\t' , str(linestr, encoding = "utf-8"))
subfile = open(todir + 'end', 'wb')
subfile.write(tempstr)
subfile.close()
if __name__ == '__main__':
# 資料夾
fromfile = 'e:\\tmp\\audio_check_hit_data.txt'
# 輸出路徑
todir = 'e:\\tmp\\outdir2\\'
# 行數
linenum = 100
# 執行函式
split(fromfile, todir, linenum)
python36無法使用xfeatures2d
報錯 213 the function feature is not implemented this algorithm is patented and is excluded in this configuration set opencv enable nonfree cmake option...
python3 6 爬蟲例子
importurllib.request importre importos importurllib.erroraserror url 請求 request urllib.request.request url 爬取結果 response urllib.request.urlopen reques...
Mac 解除安裝Python3 6
mac 自帶的 python 已經能夠滿足我們的需要了,因此很多同學在安裝完 python 之後,又想要將其刪除,或者稱之為解除安裝。對於刪除 python,我們首先要知道其具體都安裝了什麼,實際上,在安裝 python 時,其自動生成 1 python framework,即 python 框架 ...