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

P

Phipps Xue

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
 
?

=?ISO-8859-1?Q?Gerhard_H=E4ring?=

Phipps said:
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
 
P

Peter Otten

Phipps said:
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:
original

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

Back to the commandline, without restarting the interpreter:

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
 

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
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top