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 13,359 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,460 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
6,458 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 9, 2019 in Python by Pallavi
7,612 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,466 views
0 votes
1 answer
+5 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,790 points
4,127 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
7,235 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,460 points
14,767 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP