Importing module

20 views
Skip to first unread message

Slavko Ilic

unread,
Feb 19, 2016, 4:06:45 PM2/19/16
to Interactive Editor for Python
I have two files in same directory(main.py and media.py). When I import media.py to main.py it works fine. But when I make change in media.py and again run main.py it does not recognizes that change. It only
recognizes it if I run file as script, but that reset shell. Is it possibile to make change and than import that module so main file
recognizes that change, but not reseting shell. Code works fine in IDLE, but here I have that problem. Sorry for bad English, I hope you can understand question.

Almar Klein

unread,
Feb 20, 2016, 5:13:31 AM2/20/16
to Slavko Ilic, Interactive Editor for Python

If you import a module, importing it again will not load the actual file again, because Python remembered that it was imported earlier.

 

You can do a dirty trick to force a reload:

Import sys

sys.modules.pop(‘main’, None)

import main

 

But I would in general discourage this. This is essentially why there is a “run as script”.

 

- Almar

--
You received this message because you are subscribed to the Google Groups "Interactive Editor for Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iep_+uns...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

Reply all
Reply to author
Forward
0 new messages