Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python: import file not working in the if statement

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading