str object has no attribute read

0 votes

hi,

I'm parsing a string type to my stopword removing statement and I get this error 'str' object has no attribute 'read'. why?

def stopWordRemove(token_data):
  stopword = file_name
  ar_list = stopword.read().split('\n')
  needed_word = []
  word = word_tokenize(token_data)
  for w in words:
    if w not in (ar_list):
      needed_word.append(w)
  filterd_sentence = ' '.join(needed_word)
  return filterd_sentence
  print (ar_list)
print(stopWordRemove("احسن من ترحال"))
Jun 27, 2020 in Python by zena
• 140 points

edited Jun 29, 2020 by MD 4,773 views

1 answer to this question.

0 votes

Hi@zena,

In the below section you are trying to pass string but sting has no attribute read. 

stopword = file_name 
ar_list = stopword.read().split('\n')

So if you are trying to read data from a file then you can use the open function as given below.

stopword=open('file_name',"r")
ar_list = stopword.read().split('\n')
answered Jun 29, 2020 by MD
• 95,060 points

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

Python error "AttributeError: 'str' object has no attribute 'casefold'"

Check your python version. Casefold is possible ...READ MORE

answered Jul 4, 2019 in Python by Yesha
3,484 views
0 votes
1 answer

Python error "'str' object has no attribute 'turtle' in Python turtle"

There is a syntax error. Change the ...READ MORE

answered Jul 8, 2019 in Python by Pallavi
4,653 views
0 votes
1 answer
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,842 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,419 views
+1 vote
3 answers

AttributeError: 'module' object has no attribute 'listen"

You'll have to install the pyaudio module ...READ MORE

answered Oct 3, 2019 in Python by Liala
2,144 views
0 votes
1 answer

AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'

Hi@akhtar, I think numpy version is not compatible ...READ MORE

answered Apr 13, 2020 in Python by MD
• 95,060 points
3,917 views