473,657 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.

Dec 2 '05 #1
10 1489
sandorf wrote:
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
Dec 2 '05 #2
> 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:
import foo
#change the contents of foo
foo = reload(foo)


Dec 2 '05 #3
infidel a écrit :
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:


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.
Dec 2 '05 #4
Christophe wrote:
infidel a écrit :
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:


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
sc***********@a cm.org
Dec 3 '05 #5
Christophe wrote:
"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.


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>

Dec 3 '05 #6
Fredrik Lundh a écrit :
Christophe wrote:

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

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.
Dec 5 '05 #7
"Christophe " wrote:
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>

Dec 5 '05 #8
Fredrik Lundh a écrit :
"Christophe " wrote:

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?


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.
Dec 5 '05 #9
On Fri, 02 Dec 2005 18:04:15 +0100 in comp.lang.pytho n, Christophe
<ch************ *@free.fr> wrote:
infidel a écrit :
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:


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

--
Change is inevitable, progress is not.
Dec 5 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
3377
by: Enzo | last post by:
Hi Ng, It's possible to protect the source code of a js file? With PHP? Thanks in advance! Enzo
29
2773
by: Frank Millman | last post by:
Hi all I am writing a multi-user accounting/business system. Data is stored in a database (PostgreSQL on Linux, SQL Server on Windows). I have written a Python program to run on the client, which uses wxPython as a gui, and connects to the database via TCP/IP. The client program contains all the authentication and business logic. It has dawned on me that anyone can bypass this by modifying the program. As it is written in Python, with...
9
2948
by: Jay Kim | last post by:
Hi, We're implementing a Windows application using Visual Basic .NET. One of the key features we need to implement is that we should be able to get the accurate byte offset of user selected text in the file. We've been trying to use the RichTextBox control to load
10
2713
by: Atley | last post by:
I am trying to make sure that an MDB is not in use and then delete it. If it is in use, I want to automatically disconnect all the users and then delete the file. Any suggestions are welcome.
5
2434
by: Egbert Nierop \(MVP for IIS\) | last post by:
hi, I have a testing win2003 machine, where I debug inside a MMC process using a DebugBreak() statement. But only the first time, source code was shown, after that, I only get to see disassembly while I -did- install a debug DLL + PDB and the .CPP's in the same directory. I have installed visual studio 2005 without installing any language, so no
1
1759
by: Henry Law | last post by:
(I posted this to comp.infosystems.www.browsers.misc but there seems to be very little traffic there. I can't see another suitable group; is it on topic here? If not, any suggestions as to where?) I'm coding an application which serves out files for download via HTTP. I can provide the file name thus Content-Disposition:attachment;filename="somename.dat" I read in RFC2183 that I should be able to supply the modification date
20
2273
by: Guy Fawkes | last post by:
Hi, I was wondering if Python programs always need to include the source code with the program itself. I'm asking this because I don't want my program to be open-source and so far all the Python programs I've seen included the source code. Is it possible to make an executable with only bytecode? Thanks in advance!
13
1812
by: ts-dev | last post by:
Is it possible to prevent modification of a python file once its been deployed? File permissions of the OS could be used..but that doesn't seem very secure. The root of my question is verifying the integrity of the application and the scripts being run. Is this possible, if so, how?
10
2029
by: desktop | last post by:
I have found the stl_tree.h for a red-black tree in: /usr/include/c++/4.1.2/bits But where is the .cpp source file located or are all the implementation located in the .h file?
0
8411
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.