December 8th, 2004, 04:01 AM
saving changes to scripts
I've noticed this right from day three of learning Python..but didn't take it much seriously. When the length of the scripts grew bigger, it was hard to make changes.
When we make changes to the Python script...how to retain the changes w/o changing the name of the file.
1> Write the script
2> Save it as myFile.py
3> If suppose there are some errors or changes, make changes and again save it.... but this doesn't work...again when I import the file and run it ...it continues to display the same error I was getting before making the changes.
How do I save my changes in python file?????
December 8th, 2004, 05:11 AM
I suspect that you are doing this using IDLE (or similar) and the file you are editing is actually a module you import into another module.
If the python interpreter is still running the old copy of the module stays in memory even if you modify the py file. The cleanest way to test it is close down python and re-run it. This is a consequence of the import optimisation - it only really imports a module once.
You can use the reload(module) at the command prompt if you prefer. There are other work arounds involving modifying the module lists but frankly it is easier to restart the interpreter IMO.
December 8th, 2004, 05:58 AM
Hey thanks so much Grimey!
Used the reload thingy....
This solved the my great problem...I used to actually save the changes as a different file...which was a mess.
<module 'count' from 'count.py'>
Thanks so much...I'm very happy now!
December 8th, 2004, 11:25 AM
PythonWin has a "reload module" button, in case you're interested.
December 8th, 2004, 10:09 PM
Hey thanks .... I got that button!