0
votes

I have a simple module and a basic def. Module name is example315.py and the def is

def right_justify(s)
    print(s)

This works fine when I import example315 and then call example315.right_justify("hello world")

If I change my def to not return anything (in fact I can change it in any way) and then run the function again (AFTER saving my module of course) iit still does the print.

Short of exiting IDLE and starting over I can't seem to get it to work.

Any help appreciated

2

2 Answers

2
votes

The module is loaded once per session, you have to re-load it when you change it.

From the Python tutorial on modules:

For efficiency reasons, each module is only imported once per interpreter session. Therefore, if you change your modules, you must restart the interpreter – or, if it’s just one module you want to test interactively, use reload(), e.g. reload(modulename).

1
votes

The problem you're facing is the fact that IDLE has already imported and built its internal representation of your module. Editing the file on disk won't reflect on the now imported memory-resident version in IDLE. You should be able to get the behavior you're looking for with:

example315 = reload(example315)

And here's some source: Python Docs Source