473,513 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a way to import a modified script module twice?

Dear all,

I wanna reload a script module after it's modified so that I can use
the new function immediately.

Is there any help for that? It's appreciated very much if any example
provided!
TIA

Phipps
Jul 18 '05 #1
2 1810
Phipps Xue wrote:
I wanna reload a script module after it's modified so that I can use
the new function immediately.


<original changeme.py>
def fun():
print "original"
</original changeme.py>

Now on the command line:
import changeme
from changeme import fun
fun() original changeme.fun() original

Now change changeme to
<modified changeme.py>
def fun():
print changed"
</modified changeme.py>

Back to the commandline, without restarting the interpreter:
reload(changeme) <module 'changeme' from 'changeme.py'> fun() original changeme.fun() changed


Note that reload() has no effects on the function imported with

from module import *

General rule: You'd better not use reload().
The minimum precaution is to always use the qualified name.

Peter

Jul 18 '05 #2
Phipps Xue wrote:
Dear all,

I wanna reload a script module after it's modified so that I can use
the new function immediately. [...]


Use the reload() builtin function. The parameter for reload is the
module to reload. Yes, modules are objects, too in Python :)

-- Gerhard
Jul 18 '05 #3

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

Similar topics

0
1117
by: myang | last post by:
I am revising a python module, and try it in python shell. Each time after the module is modified, how can I import the new module? I remember there is an "import" like staff to do it, but dont...
6
1512
by: John J. Lee | last post by:
I'm tearing my hair out at what seems like weird import behaviour I'm getting from Python's stdlib test script, regrtest.py (not for the first time: seem to have forgotten the resolution from last...
4
2178
by: MackS | last post by:
Hi I'm new to Python, I've read the FAQ but still can't get the following simple example working: # file main_mod.py: global_string = 'abc' def main():
5
2144
by: Pekka Niiranen | last post by:
Hi there, I have two scripts. The first "main.py" sets some variables and then imports another called "gen.py". The idea is to provide "main.py" that defines some paths, variables etc. without...
2
1725
by: beliavsky | last post by:
Near the beginning of file test_matrix.py from scipy are the lines import scipy.base reload(scipy.base) from scipy.base import * del sys.path Could someone please explain why the first two...
5
5314
by: Roland Hedberg | last post by:
Hi! I'm having a bit of a problem with import. I'm writing a marshalling system that based on a specification will create one or more files containing mostly class definitions. If there are...
11
1873
by: Cecil Westerhof | last post by:
I have a cgi-script dat uses the modules cgi, os, sys and time. Offcourse I can not time the time used to import time, but os and sys do not take more as a millisecond. My script itself takes 3 or...
49
3888
by: Martin Unsal | last post by:
I'm using Python for what is becoming a sizeable project and I'm already running into problems organizing code and importing packages. I feel like the Python package system, in particular the...
1
1824
by: John Boy | last post by:
First post and very much a newbie to Python. Have 2.5 on Linux (GG). I think I have set up PYTHONPATH correctly in that I can import a module apply_bp and it complains about line 20 in apply_bp...
0
7379
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,...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5084
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...
0
3232
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...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
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...

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.