0

Python - WordCloud

Hello following is my code where I am trying to generated wordcloud of a sample text, but I am facing an attribute error. Can someone help me with that? Thanks >> CODE >> with open("/home/sahil/worldcloud.txt") as f: count = dict() for line in f: words = line.split() for word in words: if word.isalpha(): if word in count: count[word] += 1 else: count[word] = 1 cloud = count.WordCloud() cloud.generate_from_frequencies(frequencies) cloud.to_file("myfile.jpg") << ENCODE << **ERROR Traceback (most recent call last): File "/usr/lib/python3.8/idlelib/run.py", line 559, in runcode exec(code, self.locals) File "/home/sahil/wordcloud.py", line 11, in <module> cloud = count.WordCloud() AttributeError: 'dict' object has no attribute 'WordCloud' **

12th Jul 2021, 10:30 AM
Muhammad Idrees
Muhammad Idrees - avatar
1 Answer
0
the error says it all . You are trying to access the value stored for key "WordCloud()", how do you think it will work ?
12th Jul 2021, 3:32 PM
Abhay
Abhay - avatar