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

StackOverflow https://stackoverflow.com/questions/8453189

  •  12-03-2021
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top