Python: import file not working in the if statement

Question:

This is a main file in which I start an other.py script.
The initial import works, it executes the other.py on line 1.

But when this has ran the other.py, it will ask input to to restart other.py once more.
The ‘no’ answer is working, the ‘yes’ answer just keeps giving me the same prompt.

So the import is not working in my if statement.
Any ideas please?

import other

while True:
    prompt = input("Restart? Yes / No: ")
    if prompt == "yes" or prompt == "Yes":
        import other
    elif prompt == "no" or prompt == "No":
        print("Goodbye!")
        break
Asked By: Kevin Provoost

||

Answers:

Once python has imported a module it won’t import it again. You have to specifically ask python to reload a module if you want it to reload it.

Try and remove the import other from the top and run your app.

Answered By: Michael Wiles
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.