Why my modification of source file doesn't take effect when debugging?

S

sandorf

I'm using the Windows version of Python and IDLE. When I debug my .py
file, my modification to the .py file does not seem to take effect
unless I restart IDLE. Saving the file and re-importing it doesn't help

either. Where's the problem?

Thanks.
 
J

Jeremy Jones

sandorf said:
I'm using the Windows version of Python and IDLE. When I debug my .py
file, my modification to the .py file does not seem to take effect
unless I restart IDLE. Saving the file and re-importing it doesn't help

either. Where's the problem?

Thanks.
No problem. Just reload() it.


- jmj
 
I

infidel

I'm using the Windows version of Python and IDLE. When I debug my .py
file, my modification to the .py file does not seem to take effect
unless I restart IDLE. Saving the file and re-importing it doesn't help
either. Where's the problem?

"import" only reads the file the first time it's called. Every import
call after that looks up the module in memory. This is to prevent
circular dependencies between modules from creating infinite loops.
You need to use the reload() function:

#change the contents of foo
 
C

Christophe

infidel a écrit :
"import" only reads the file the first time it's called. Every import
call after that looks up the module in memory. This is to prevent
circular dependencies between modules from creating infinite loops.
You need to use the reload() function:

As a matter of fact, it would help a lot if that stupid behaviour of
Idle was dropped. I'm sure I'm not the only one who lost lots of time
because of that bug. Yes I call it a bug.
 
S

Scott David Daniels

Christophe said:
infidel a écrit :

As a matter of fact, it would help a lot if that stupid behaviour of
Idle was dropped. I'm sure I'm not the only one who lost lots of time
because of that bug. Yes I call it a bug.
You are mistaken if you think this is an Idle behavior; it is a Python
behavior that speeds the execution of large systems.

--Scott David Daniels
(e-mail address removed)
 
F

Fredrik Lundh

Christophe said:
As a matter of fact, it would help a lot if that stupid behaviour of
Idle was dropped. I'm sure I'm not the only one who lost lots of time
because of that bug. Yes I call it a bug.

in the version of IDLE I have on this machine, if I modify my script and
run it again (using F5), things work exactly as expected.

if I modify my script and import it into a clean shell (ctrl-F6), things work
exactly as expected.

the only way to get the "buggy" behaviour you're describing is to attempt
to run your program by importing it as a module more than once into an
existing python shell process. in that case, import works in the same way
as it always works.

after all, "import" isn't designed to run programs, it's designed to import
modules. if you want to run stuff in IDLE, why not just use the "run"
command ?

</F>
 
C

Christophe

Fredrik Lundh a écrit :
Christophe wrote:




in the version of IDLE I have on this machine, if I modify my script and
run it again (using F5), things work exactly as expected.

if I modify my script and import it into a clean shell (ctrl-F6), things work
exactly as expected.

the only way to get the "buggy" behaviour you're describing is to attempt
to run your program by importing it as a module more than once into an
existing python shell process. in that case, import works in the same way
as it always works.

after all, "import" isn't designed to run programs, it's designed to import
modules. if you want to run stuff in IDLE, why not just use the "run"
command ?

F5 is designed to run the current open file. Sane people won't assume
that pressing twice the F5 key will yield different. Sane people will
assume that when you edit file1.py and press F5, it reparses the file,
but when you edit file2.py and press F5 with file1.py it won't work. Why
make it different ? Why make is so that I have to select the shell
window, press CTRL+F6, select the file1.py and press F5 just so that it
works as expected ?

Idle is ok when you edit a single .py file. As soon as I need to edit 2
..py files with one using the other, I'm glad I have other editors which
spanw a clean shell each time I run the current file.
 
F

Fredrik Lundh

Christophe said:
F5 is designed to run the current open file. Sane people won't assume
that pressing twice the F5 key will yield different. Sane people will
assume that when you edit file1.py and press F5, it reparses the file,
but when you edit file2.py and press F5 with file1.py it won't work. Why
make it different ? Why make is so that I have to select the shell
window, press CTRL+F6, select the file1.py and press F5 just so that it
works as expected ?

I'm not sure I follow here: in the version of IDLE I have here, pressing
F5 will save the current file and run it. If you've edit other parts of the
application, you have to save those files (Control-S) and switch to the
main script before pressing F5, but that's only what you'd expect from
a "run this module" command.

(being able to bind F5 to a specific script might be practical, of course,
but I'm don't think that's what you're complaining about. or is it?)
Idle is ok when you edit a single .py file. As soon as I need to edit 2
.py files with one using the other, I'm glad I have other editors which
spanw a clean shell each time I run the current file.

In the version of IDLE I have, that's exactly what happens (that's what
the RESTART lines are all about).

Is there some secret setting somewhere that I've accidentally managed
to switch on or off to get this behaviour?

</F>
 
C

Christophe

Fredrik Lundh a écrit :
:




I'm not sure I follow here: in the version of IDLE I have here, pressing
F5 will save the current file and run it. If you've edit other parts of the
application, you have to save those files (Control-S) and switch to the
main script before pressing F5, but that's only what you'd expect from
a "run this module" command.

(being able to bind F5 to a specific script might be practical, of course,
but I'm don't think that's what you're complaining about. or is it?)




In the version of IDLE I have, that's exactly what happens (that's what
the RESTART lines are all about).

Is there some secret setting somewhere that I've accidentally managed
to switch on or off to get this behaviour?

What I remember ( but maybe it was changed in recent Idle versions ) was
that when your project has a main.py which imports a module.py, when you
run your project once, any later changes you make in module.py won't be
taken into account.
 
D

Dave Hansen

infidel a écrit :

As a matter of fact, it would help a lot if that stupid behaviour of
Idle was dropped. I'm sure I'm not the only one who lost lots of time
because of that bug. Yes I call it a bug.

But, if you are editing a Python Module in Idle, and press F5 to run
the module, the interpreter is restarted for you. So what's the
problem?

I would consider it a far greater problem if Idle _didn't_ do that --
it could mean you module worked when you were debuggining it because
of some initialization that doesn't get performed in a clean start.

Regards,
-=Dave
 
C

Christophe

Dave Hansen a écrit :
But, if you are editing a Python Module in Idle, and press F5 to run
the module, the interpreter is restarted for you. So what's the
problem?

I would consider it a far greater problem if Idle _didn't_ do that --
it could mean you module worked when you were debuggining it because
of some initialization that doesn't get performed in a clean start.

Regards,
-=Dave

Well, I'm happy to see that Idle now restarts the interpreter by default
when you press F5. I guess I might consider using it again after all
that time :)
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top