468,301 Members | 1,485 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

Re-running script from Tk shell

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
2 1270
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
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.

Similar topics

1 post views Thread by Chris | last post: by
11 posts views Thread by James | last post: by
1 post views Thread by John Ryan | last post: by
10 posts views Thread by James | last post: by
8 posts views Thread by Beowulf | last post: by
3 posts views Thread by presspley | last post: by
2 posts views Thread by sky2070 | last post: by
1 post views Thread by Brian | last post: by
1 post views Thread by Clarice Almeida Hughes | last post: by
2 posts views Thread by Frans Schmidt | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.