第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何制作目錄中的文件列表并一一處理?- Python

如何制作目錄中的文件列表并一一處理?- Python

暮色呼如 2021-06-11 10:58:00
我想列出目錄中的所有文本文件。然后我想在每個(gè)文件中創(chuàng)建單獨(dú)的內(nèi)容列表。例如 document1=[] 然后 document2=[] 等等。然后通過使用文檔 1 和文檔 2 關(guān)鍵字,我想計(jì)算詞頻和其他過程。代碼正在運(yùn)行,但不能為列表分配不同的名稱,如 document1 等等。import globimport mathimport rea=0flist=glob.glob(r'D:/Final Year Project/Development process/Text_data_extraction/MyFolder/*.txt') #get all the files from the d`#open each file >> tokenize the content >> and store it in a setfor fname in flist:             tfile=open(fname,"r")    line=tfile.read()    a+=1    line = line.lower() # lowercase    line = re.sub("</?.*?>"," <> ",line) #remove tags    line = re.sub("(\\d|\\W)+"," ",line)  # remove special characters and digits    l_ist = line.split("\n")    print 'document'    print(l_ist)tfile.close() # close the fileprint"Number of documents:"print(a)
查看完整描述

2 回答

?
慕尼黑的夜晚無繁華

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊

這里,我相信不要只給出文本文件名,而是給出目錄路徑和名稱結(jié)構(gòu),對(duì)于“document1, document2...”使用循環(huán),或者如果設(shè)置了文檔文件的數(shù)量,則使用它們。


查看完整回答
反對(duì) 回復(fù) 2021-06-22
  • 2 回答
  • 0 關(guān)注
  • 221 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)