title: Handling <class 'nltk.corpus.reader.wordlist.WordListCorpusReader'> in Python
body: <p>I am using the "wordcloud" package in Python and trying to ingest my own tri-lingual (English, French and German) stopword list.</p>
  
  <p>This "EN_FR_DE" stopword list is stored in the NLTK data folder alongside the standard NLTK stopword lists on my PC because I am using it in other contexts, too. I would now like to import this custom stopword list, turn it into a string and use it in "wordcloud". I used "string" to convert the list. When I check its "type", however, the output still is:</p>
  
  <pre><code>&lt;class 'nltk.corpus.reader.wordlist.WordListCorpusReader'&gt;
  </code></pre>
  
  <p>Of course, "wordcloud" does not accept this list and ignores all the stopwords (see graph image linked below).</p>
  
  <p><strong>I wasn't even aware that this was a class of its own, and I could not find instructions how to handle this particular type of class. What is the proper way to convert it into a string?</strong></p>
  
  <p>My full script for building the wordcloud is:</p>
  
  <pre><code># Generate word cloud from publication titles in English, French and German
  
  from wordcloud import WordCloud
  import matplotlib.pyplot as plt 
  import string
  import nltk
  from nltk.corpus import stopwords
  
  infile=("C:\\Users\\mobarget\\Google Drive\\ACADEMIA\\Metadata_PhD\\BritishRiots_TopicModel\\British_riots_text.txt")  
  
  # define stopwords and convert them to string
  
  stopwords_multiling=' '.join(stopwords.words('en_fr_de'))
  print(stopwords_multiling[:50])
  print(type(stopwords))
  
  # read and pre-process data
  
  with open(infile, 'r', encoding='utf-8') as f: # open file
      data1=f.read() # read content of file as string
      data2=data1.translate(str.maketrans('', '', string.punctuation)).lower() # remove punctuation
      data3=' '.join(data2.split()) # remove additional whitespace from text
  
  # define word cloud layout
  
  wordcloud = WordCloud(width = 800, height = 800, 
                  background_color ='white', 
                  stopwords = stopwords_multiling, 
                  min_font_size = 10).generate(data3) 
  
  # plot the WordCloud image   
  
  plt.figure(figsize = (8, 8), facecolor = None) 
  plt.imshow(wordcloud, interpolation="bilinear") 
  plt.axis("off") 
  plt.tight_layout(pad = 0) 
  
  plt.show() 
  </code></pre>
  
  <p>And this is the output:</p>
  
  <pre><code>i me my myself we our ours ourselves you you're yo
  &lt;class 'nltk.corpus.reader.wordlist.WordListCorpusReader'&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/FJjOg.png" rel="nofollow noreferrer">Graph Image</a></p>