[Tutor] positional argument error

Mats Wichmann mats at wichmann.us
Sun Apr 26 19:08:05 EDT 2020


On 4/26/20 9:30 AM, shubham sinha wrote:
> hello,
> I am new to python and as a doing excercise I got an error that is
> mentioned below:
> please help me through that.
> 
> q. create a "word cloud" from a text by writing a script. This script needs
> to process the text, remove punctuation, ignore case and words that do not
> contain all alphabets, count the frequencies, and ignore uninteresting or
> irrelevant words. A dictionary is the output of the calculate_frequencies
> function.
> 
> my code:
> 

>     def generate_from_frequencies(file_contents):

That function is declared to need an argument.

Except:

>     cloud = wordcloud.WordCloud()
>     cloud.generate_from_frequencies()

you call it without an argument.

Further, it looks like it was actually a method in a class, because of
the way you call it - but there is no class definition in what you
included, so we can't really untangle this for you completely.  Even
stranger, a thing called file_contents is referenced _outside_ the
function, which isn't going to work

However the error is pretty clear:

> TypeError: generate_from_frequencies() missing 1 required positional
> argument: 'frequencies'

you needed to call it with an argument and you didn't.


More information about the Tutor mailing list