Search code examples
pythonpythonanywhere

How to see new results in console after updating imported module in PythonAnywhere


When I import a selfmade module and run the program, the output is what I expected. However when I update the module and run the program in the same console, the previous result is shown. If I open a new console, then the new result is correctly shown.

Let's take an example:

# Filename: myfunctions.py

def helloWorld():
    print("Hello World")
# Filename: runfuction.py

from myfunctions import helloWorld

helloWorld()

The output is Hello World. When I replace in myfunctions.py Hello into Bye, and when I run the program in the same console, my result is still Hello World, and not Bye World. The updated text Bye World will be only shown when I open a new console.


Solution

  • try:

    reload(module_name)
    

    that's how it works in a local python console. I don't have a PythonAnywhere account, but I would guess it's pretty similar.

    Note that any object instances you have already created will not be changed, but this (or something similar) should work fine for functions.