我該如何解決這個錯誤,我正在嘗試組合文本并創建一個詞云圖像。from os import path from PIL import Imagefrom wordcloud import WordCloud, STOPWORDS, ImageColorGeneratortext = [] cb = cbData #text datasettc = 0for t in cb.text: text.append(t) tc += 1all_text = " ".join(t for t in text)print("Total words in all posts: ", len(all_text))這是錯誤:----> 3 for t in cb.text:AttributeError: 'int' object has no attribute 'text'
1 回答

侃侃無極
TA貢獻2051條經驗 獲得超10個贊
該錯誤只是告訴您您正在嘗試使用不存在的屬性或方法。我建議列出確實存在的屬性/方法,并從那里弄清楚要做什么。這可以這樣做:
# code that generates variable "cb" (not supplied in post) print(dir(cb))
現在,查看輸出并查看您應該嘗試訪問的方法/屬性。也許它就是這樣簡單的事情.Text
或.text()
注意:生成的列表不會告訴您它是否應該是.text
或.text()
(區別在于括號)所以如果一個不起作用就使用另一個!
添加回答
舉報
0/150
提交
取消