reloading modules

A

aine_canby

I'm using python.exe to execute my modules. I have a music.py module
which contains my classes and a main.py module which uses these
classes. In python.exe, I call "import main" to execute my program. The
problem is that I have to close python and reopen it everytime i change
music.py or main.py. What should I be doing.

Thanks,

Aine.
 
D

Dustan

I'm using python.exe to execute my modules. I have a music.py module
which contains my classes and a main.py module which uses these
classes. In python.exe, I call "import main" to execute my program. The
problem is that I have to close python and reopen it everytime i change
music.py or main.py. What should I be doing.

Thanks,

Aine.
### Execution Occurs ###
 
D

Dustan

Dustan said:
### Execution Occurs ###

I was obviously assuming that your module does something just by
importing, which may or may not be the case. Either way, whenever a
module may have been edited during a program's lifetime, it can be
reloaded using the reload function.
 
F

Frank Millman

I'm using python.exe to execute my modules. I have a music.py module
which contains my classes and a main.py module which uses these
classes. In python.exe, I call "import main" to execute my program. The
problem is that I have to close python and reopen it everytime i change
music.py or main.py. What should I be doing.

Thanks,

Aine.

Instead of calling 'import', use the 'imp' module and call
'find_module' followed by 'load_module'. As the docs explain, one of
the differences between this and 'import' is that it loads the module
every time, even if it is already imported.

HTH

Frank Millman
 
K

Kent Johnson

Dustan said:
### Execution Occurs ###

If you edit music.py you will have to
import music
reload(music)

to get the new music module, then
reload(main)

to run again.

You could just type
> python main.py

at the command line each time you want to run, or use an editor that
lets you run the program from within the editor.

Kent
 

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,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top