Python: Save a list of text files. It can be an English text file, but not a Korean text file.

Asked 2 years ago, Updated 2 years ago, 142 views

import pandas as pd
import glob
from afinn import Afinn
from nltk.corpus import stopwords 
from nltk.stem.porter import PorterStemmer
from nltk.tokenize import RegexpTokenizer
import numpy as np
import matplotlib.pyplot as plt
import nltk

pos_review= (glob.glob (r"C:/Users/user/Desktop/Data/articlenew/*.txt")[0:11]

lines_pos=[ ]    

for i in pos_review:
    try:
        f = open(i, 'r')
        temp = f.readlines()[0]
        lines_pos.append(temp)
        f.close()
    except Exception as e:
        continue

You want to save content from multiple text files to an empty list It can be an English text file, but I can't save the Korean text file. I don't know what the problem is.

python nlp

2022-09-20 19:25

1 Answers

It is important to narrow down the problem area. Coding beginners should learn this.

After open and readlines in the code you uploaded, the text is append in the list.

Where did the problem occur during this process?

The way to figure that out is to see if I did the action I intended in the middle of these three processes. A very basic and primitive way is to print the results of each process, and a more convenient way is to run each line in debugging mode.

Please learn what is described in the above paragraph before you do it.


2022-09-20 19:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.