IDLE confusion

M

MrBlueSky

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
 
C

Claudio Grondi

MrBlueSky said:
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
 
C

Christophe

Claudio Grondi a écrit :
MrBlueSky said:
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
 
T

Terry Reedy

Christophe said:
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
 
T

taleinat

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...
 
C

Christophe

Terry Reedy a écrit :
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.
 
S

Scott David Daniels

Christophe said:
Terry Reedy a écrit :
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
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,297
Messages
2,571,529
Members
48,249
Latest member
reactnativeexpert

Latest Threads

Top