By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,986 Members | 1,583 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,986 IT Pros & Developers. It's quick & easy.

Re-running script from Tk shell

P: n/a
gtb

I am testing a simple script by running it in the Tk shell. It imports
a class from another module. I edit and save the file from which I
import. When I want to re-run I delete the Tk window and run the
module from the Edit window (F5 - Run Module). The script that does
the importing does not see the changes to the imported class, even if
I delete the compiled files. For it to see the changes I must close
all the edit windows and re-open an Idle edit.

Perhaps I need to de-import the class, but I have not found a method
in the tutorial or the reference (yet).

Thanks

Apr 30 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Apr 30, 9:51 am, gtb <goodTweetieB...@hotmail.comwrote:
I am testing a simple script by running it in the Tk shell. It imports
a class from another module. I edit and save the file from which I
import. When I want to re-run I delete the Tk window and run the
module from the Edit window (F5 - Run Module). The script that does
the importing does not see the changes to the imported class, even if
I delete the compiled files. For it to see the changes I must close
all the edit windows and re-open an Idle edit.

Perhaps I need to de-import the class, but I have not found a method
in the tutorial or the reference (yet).

Thanks
You probably need to reload() the imported module. Check out the
following thread: http://www.python.org/search/hyperma...1993/0342.html

Hopefully that's what you meant anyway.

Mike

Apr 30 '07 #2

P: n/a
In article <11**********************@h2g2000hsg.googlegroups. com>,
gtb <go*************@hotmail.comwrote:
I am testing a simple script by running it in the Tk shell. It imports
a class from another module. I edit and save the file from which I
import. When I want to re-run I delete the Tk window and run the
module from the Edit window (F5 - Run Module). The script that does
the importing does not see the changes to the imported class, even if
I delete the compiled files. For it to see the changes I must close
all the edit windows and re-open an Idle edit.

Perhaps I need to de-import the class, but I have not found a method
in the tutorial or the reference (yet).
Try having your script first import the library and then reload it, e.g.:

import foo
reload(foo)

It will load foo more slowly the first time (and a clever if statement
could avoid that) but it will always use the latest foo.

Warning: this will not work if you use
from foo import...

-- Russell
Apr 30 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.