#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    12

    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?????

    Subha
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    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.

    grim
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    12
    Hey thanks so much Grimey!

    Used the reload thingy....

    PHP Code:
    >>> reload(count)
    <
    module 'count' from 'count.py'>
    >>> 
    count.count() 
    This solved the my great problem...I used to actually save the changes as a different file...which was a mess.
    Thanks so much...I'm very happy now!

    Subha
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    PythonWin has a "reload module" button, in case you're interested.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    12
    Originally Posted by sfb
    PythonWin has a "reload module" button, in case you're interested.

    Hey thanks .... I got that button!
    Good...thanks sfb!

    Subha

IMN logo majestic logo threadwatch logo seochat tools logo