473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

how to re-import changed code?

Hi,

another beginner's question:
when I import a module, change the corresponding textfile and try to
import the same module again, it looks like the internal code does not
change (the source-line in an error-message is up to date, however!). Also
del module before import and deleting the .pyc file do not help! How to
realize a fast edit-try-cycle? (btw: I am using python 2.2 under windows)

thanks in advance!

Wolfgang
Jul 18 '05 #1
2 16774
Wo***************@profactor.at wrote:
Hi,

another beginner's question:
when I import a module, change the corresponding textfile and try to
import the same module again, it looks like the internal code does not
change (the source-line in an error-message is up to date, however!). Also
del module before import and deleting the .pyc file do not help! How to
realize a fast edit-try-cycle? (btw: I am using python 2.2 under windows)


What you're looking for is the reload() function.

Normally, an imported module is cached by the interpreter, and
subsequent imports go straight to the cache without checking whether the
file has changed or not. If you reload(), that specifically clears the
cache and imports from the (current) disk file again.

Jeff Shannon
Technician/Programmer
Credit International

Jul 18 '05 #2

"Jeff Shannon" <je**@ccvcorp.com> wrote in message
news:10*************@corp.supernews.com...
Wo***************@profactor.at wrote:
Hi,

another beginner's question:
when I import a module, change the corresponding textfile and try to
import the same module again, it looks like the internal code does not
change (the source-line in an error-message is up to date, however!). Also
del module before import and deleting the .pyc file do not help! How to
realize a fast edit-try-cycle? (btw: I am using python 2.2 under windows)

What you're looking for is the reload() function.

Normally, an imported module is cached by the interpreter, and subsequent
imports go straight to the cache without checking whether the file has
changed or not. If you reload(), that specifically clears the cache and
imports from the (current) disk file again.


That works, but with a very important caveat: reload() does not
change anything in the module that's currently being referred to.
This can lead to very subtle bugs, and all IDE/debugger combinations
don't handle it properly.

What I do is keep a command line open under Windows, and
I create a .cmd file with a very short name. It takes about three
keystrokes to run the test (alt-tab, t, return), and one keystroke
to get back to the IDE (alt-tab). This reloads my unit test suite
and runs it.

John Roth


Jeff Shannon
Technician/Programmer
Credit International


Jul 18 '05 #3

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

Similar topics

1
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would...
4
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
4
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function...
8
by: Lothar Scholz | last post by:
Because PHP5 does not include the mysql extension any more is there a chance that we will see more Providers offering webspace with Firebird or Postgres Databases ? What is your opinion ? I must...
1
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id ...
3
by: presspley | last post by:
I have bought the book on advanced dreamweaver and PHP recently. I have installed MySQL and PHP server but am getting an error on the $GET statement show below. It says there is a problem with...
2
by: sky2070 | last post by:
i have two file with jobapp.html calling jobapp_action.php <HTML> <!-- jobapp.html --> <BODY> <H1>Phop's Bicycles Job Application</H1> <P>Are you looking for an exciting career in the world of...
1
by: Brian | last post by:
I have an array like this: $events = array( array( '2003-07-01', 'Event Title 1', '1' //ID Number (not unique) ), array( '2003-07-02',
1
by: Clarice Almeida Hughes | last post by:
tenho um index onde tenho o link pro arq css, como sao visualizados pelo include todas as paginas aderem ao css linkado no index. so q eu preciso de alguns links com outras cores no css, o q devo...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.