簡體   English   中英

無法打開 local.txt 文件以在 NLTK 中讀取

[英]Cannot open local .txt file to read in NLTK

我不是一個經驗豐富的程序員,我只是想用它來用 NLTK 進行一些數據分析。 我正在關注在線書籍,但以下代碼無法打開讀取文件。

#download nltk

import nltk
nltk.download()

#import everything from nltk
from nltk.book import *

import io
open('ALL FEMALES1.txt', encoding="ISO-8859-1")

output:<_io.TextIOWrapper name='ALL FEMALES1.txt' mode='r' encoding='ISO-8859-1'>

我試過用

f = open('ALL FEMALES1.txt')
>>> raw = f.read()

但這給了我以下錯誤:'utf-8' codec can't decode byte 0xd5 in position 18929: invalid continuation byte

有什么建議嗎? 如果這很重要,我正在使用 Jupyter Notebook。

打開文件可以很好地完成

with open('sample_file.txt', encoding="ISO-8859-1") as f:
    print(f.read())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM