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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

FileNotFoundError: [Errno 2] 沒有這樣的文件或目錄:

FileNotFoundError: [Errno 2] 沒有這樣的文件或目錄:

慕桂英546537 2023-03-22 16:21:04
整個錯誤:C:\Users\Desktop\texts>python similarity1.pyTraceback (most recent call last):  File "similarity1.py", line 19, in <module>    documents = [open(f, encoding="utf-8").read() for f in text_files]  File "similarity1.py", line 19, in <listcomp>    documents = [open(f, encoding="utf-8").read() for f in text_files]FileNotFoundError: [Errno 2] No such file or directory: 'apempe_chunks.txt'以及產(chǎn)生特定錯誤的代碼:import osimport codecsimport string, refrom pathlib import Pathpath = "C:\\Users\\Desktop\\texts\\dataset"text_files = os.listdir(path)documents = [open(f, encoding="utf-8").read() for f in text_files]sparse_matrix = tfidf_vectorizer.fit_transform(documents)奇怪的是程序找到了apempe_chunks.txt文件里面的那個dataset。我已經(jīng)在 SO 中研究了這個問題,但我無法解決它。
查看完整描述

1 回答

?
倚天杖

TA貢獻(xiàn)1828條經(jīng)驗 獲得超3個贊

為了解決這個錯誤,我similarity1.pydataset文件夾中移動,將其添加到我的代碼中if f.endswith('.txt')],現(xiàn)在它可以正常工作了。

所以現(xiàn)在完整的代碼是

documents = [open(f, encoding="utf-8").read() for f in text_files if f.endswith('.txt')]

確保我只處理.txt數(shù)據(jù)集目錄中的每個文件,不計算它自己的 python 腳本或其他文件。

這個想法來自這個答案線程,一個類似于我的問題。


查看完整回答
反對 回復(fù) 2023-03-22
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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