469,954 Members | 1,827 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

IDLE confusion

Hi, I'm trying to use IDLE to develop My First Python App and my head
hurts...

I've a file called spalvi.py with this in it:
from Test import *
firstTest("Mike")

And a file called Test.py with this in it:
def firstTest(name):
print "Yo",name

I open spalvi.py with IDLE and Run it. It says "Yo Mike".
I use the File menu to open Test.py and change the message from "Yo" to
"Hi".
I Run it again.... it still says "Yo Mike" :-(
I close everything down, open spalvi.py with IDLE and Run it again. It
says "Hi Mike".

So I'm obviously not using IDLE in the "right" way. But what *is* the
"right" way, when you're trying to develop using several source files?

John

May 16 '06 #1
6 1636
MrBlueSky wrote:
Hi, I'm trying to use IDLE to develop My First Python App and my head
hurts...

I've a file called spalvi.py with this in it:
from Test import *
firstTest("Mike")

And a file called Test.py with this in it:
def firstTest(name):
print "Yo",name

I open spalvi.py with IDLE and Run it. It says "Yo Mike".
I use the File menu to open Test.py and change the message from "Yo" to
"Hi".
I Run it again.... it still says "Yo Mike" :-(
I close everything down, open spalvi.py with IDLE and Run it again. It
says "Hi Mike".

So I'm obviously not using IDLE in the "right" way. But what *is* the
"right" way, when you're trying to develop using several source files?

John

You need some deeper understanding of what import does and what happens
when you import again (after the library files have changed).
Try in the IDLE menu [Shell] "Restart Shell" (Ctrl+F6) each time you
have changed something in your files - this "resets" anything previously
imported, which stays the same way otherwise.

Claudio
May 16 '06 #2
Claudio Grondi a écrit :
MrBlueSky wrote:
Hi, I'm trying to use IDLE to develop My First Python App and my head
hurts...

I've a file called spalvi.py with this in it:
from Test import *
firstTest("Mike")

And a file called Test.py with this in it:
def firstTest(name):
print "Yo",name

I open spalvi.py with IDLE and Run it. It says "Yo Mike".
I use the File menu to open Test.py and change the message from "Yo" to
"Hi".
I Run it again.... it still says "Yo Mike" :-(
I close everything down, open spalvi.py with IDLE and Run it again. It
says "Hi Mike".

So I'm obviously not using IDLE in the "right" way. But what *is* the
"right" way, when you're trying to develop using several source files?

John

You need some deeper understanding of what import does and what happens
when you import again (after the library files have changed).
Try in the IDLE menu [Shell] "Restart Shell" (Ctrl+F6) each time you
have changed something in your files - this "resets" anything previously
imported, which stays the same way otherwise.

Claudio


And I though that "bug" was fixed already :) Try to use something else
than IDLE for your code editing. Use Scite for example.

http://www.scintilla.org/SciTE.html
May 16 '06 #3

"Christophe" <ch*************@free.fr> wrote in message
news:44**********************@news.free.fr...
Try in the IDLE menu [Shell] "Restart Shell" (Ctrl+F6) each time you
have changed something in your files - this "resets" anything previously
imported, which stays the same way otherwise.


And I though that "bug" was fixed already :)

On my system, the current 2.4.3 version of Python+IDLE *does* auto restart
with each run (F5). So either the OP is using a much older version (did
not specify) or the respondant mis-diagnosed the problem.

tjr

May 16 '06 #4
This isn't really an IDLE issue, it's a Python feature which needs to
be understood.

In Python, once you've imported a module once, importing it again is
ignored. This works fine under the assumption that modules don't change
during a single Python session. However, when you're developing a
module this isn't true, and a workaround for this mechanism is needed.
The safest way to go is to start a new Python session.

In the IDLE interpreter ("Shell" window) you can do this from the Shell
menu. Running a module from an IDLE editor window (Run->Run Module)
will also restart the interpreter.

Notice, however, that these will only work if IDLE has a sub-process
for the interpreter! If not, the Shell menu won't exist, and Run Module
won't restart the interpreter.

On Windows, opening IDLE by right-clicking a file and choosing 'Edit
with IDLE' will cause it to open without a subprocess.

If you change a module and want to use the newer version in the same
Python session, use the built-in 'reload' function:

import Test
reload(Test)

Notice that if you use the 'from <module> import ...' syntax, you need
to import the module itself (i.e. import <module>) before you can
reload it.

I advise to use this with care, as things can get quite confusing after
a few reloads...

May 17 '06 #5
Terry Reedy a écrit :
"Christophe" <ch*************@free.fr> wrote in message
news:44**********************@news.free.fr...
Try in the IDLE menu [Shell] "Restart Shell" (Ctrl+F6) each time you
have changed something in your files - this "resets" anything previously
imported, which stays the same way otherwise.

And I though that "bug" was fixed already :)

On my system, the current 2.4.3 version of Python+IDLE *does* auto restart
with each run (F5). So either the OP is using a much older version (did
not specify) or the respondant mis-diagnosed the problem.


I was looking at some idlefork info not long ago and I found something
which might get those different behaviours with a recent version of idle
: if idle cannot open it's RPC socket, it'll execute all python code in
it's own interpreter. There's an option for that in fact.
May 17 '06 #6
Christophe wrote:
Terry Reedy a écrit :
"Christophe" <ch*************@free.fr> wrote in message
news:44**********************@news.free.fr...
Try in the IDLE menu [Shell] "Restart Shell" (Ctrl+F6) each time you
have changed something in your files - this "resets" anything previously
imported, which stays the same way otherwise.

And I though that "bug" was fixed already :)

On my system, the current 2.4.3 version of Python+IDLE *does* auto
restart with each run (F5). So either the OP is using a much older
version (did not specify) or the respondant mis-diagnosed the problem.


I was looking at some idlefork info not long ago and I found something
which might get those different behaviours with a recent version of idle
: if idle cannot open it's RPC socket, it'll execute all python code in
it's own interpreter. There's an option for that in fact.

The option (for those playing along) is '-n'
So:
Windows: command is: \python24\Lib\idlelib\idle.pyw -n
OS-X: command is: pythonw ?/python24/Lib/idlelib/idle.pyw -n
Linux & such: python ?/python24/Lib/idlelib/idle.pyw -n
(I think these don't
distinguish python & pythonw)

It is useful if you are having some socket-to-self issues typically
caused by over-conservative firewall settings, because no socket
is allocated for communication.

It is also useful for experimenting with Tkinter, because a Tkinter
display loop is already running, so you can see the effects of your
Tkinter commands as they are entered.

--Scott David Daniels
sc***********@acm.org
May 17 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Kerry Neilson | last post: by
1 post views Thread by Moosebumps | last post: by
1 post views Thread by dbrown2 | last post: by
8 posts views Thread by Jonathan Polley | last post: by
19 posts views Thread by Frank Rizzo | last post: by
7 posts views Thread by iwdu15 | last post: by
reply views Thread by Stefan Felkel | last post: by
1 post views Thread by cbielins | last post: by
5 posts views Thread by Russ P. | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.