0

I have the following problem: I installed a Python package from GitHub (textstat) in which there is a txt-file. The content of the txt-file (actually just a long list of easy english words) is used in some functions defined within the package. Now, I added some more words to the list in the txt-file by opening the file with a text editor and saving it, but somehow when I execute my python code (in Jupyter Notebook) it seems like the old list is used, not the updated one. How do I fix this?

EDIT: some more information, because reload() did not solve my problem. Also restarting the kernel or even my entire computer did not work out...

In textstat.py the txt-file "easy_words.txt" (in the same directory as textstat.py) is saved in the variable "easy_word_set" in the following way:

easy_word_set = set([ln.strip() for ln in pkg_resources.resource_stream('textstat', 'easy_words.txt')])

Now, in my Jupyter Notebook I import textstat as usual:

import textstat.textstat as ts

Somehow

ts.easy_word_set

gives me the updated list. But when I use e.g.

ts.textstat.gunning_fog(word)

the old list is used.

Tom K
  • 11
  • 1
  • 2
  • reload(your_module) – Ari Gold Nov 25 '16 at 14:14
  • Possible duplicate of [How do I unload (reload) a Python module?](http://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module) – mx0 Nov 25 '16 at 14:40
  • Seems like textstat (or pkg_resources) is caching information about your easy_words.txt file. If so, we'd need to figure out how to clear that cache, it seems. On Linux systems, I'd probably run the program via strace at this point to see what files it's reading. – Waxrat Nov 25 '16 at 15:50

1 Answers1

0

ipython's autoreload extension can be useful:

In [1]: %load_ext autoreload

In [2]: %autoreload 2

In [3]: from foo import some_function

In [4]: some_function()
Out[4]: 42

In [5]: # open foo.py in an editor and change some_function to return 43

In [6]: some_function()
Out[6]: 43
Taufiq Rahman
  • 5,600
  • 2
  • 36
  • 44