[Python-talk] Modules force recompilation?
Bruce Labitt
bruce.labitt at myfairpoint.net
Sat Feb 6 15:41:25 EST 2010
Kent Johnson wrote:
> On Sat, Feb 6, 2010 at 12:34 PM, Bruce Labitt
> <bruce.labitt at myfairpoint.net> wrote:
>
>
>> It would appear this is a common 'issue' with python.
>> Reload doesn't seem to alway do what one expects...
>>
>> What then is a good way to force the recompilation and module cache flush?
>>
>> /code snippet of my main
>>
>> if __name__ == '__main__':
>> import uladata as ud
>> import targets as tgt
>> ps = persistentstorage()
>>
>> ...
>> TGT = tgt.getTGT( p, sqrt(sig2) )
>> ...
>> YY = ud.myuladata(TGT, m, k, d, t, epsilon, arrayerror, chatty)
>> ...
>>
>>
>> If I edit anything in uladata.py, or targets.py, (and save it of course) how
>> can I force the recompile of either or both modules, while in the ipython
>> environment?
>>
>
> In ipython, if you
> import uladata
> import targets
> reload(uladata)
> reload(targets)
>
> it should do what you want. You only have to do the imports once; the
> reload has to be after each change.
>
>
>> As I indicated in my original post, maybe somewhat unclearly, if I
>>
>> %run main.py
>>
>> after editing either uladata or targets, I execute old code and not the new
>> code.
>>
>
> You could put the reloads into main.py for development.
>
>
>> Anyone have some insight on how to do this within the ipython environment?
>> Or some other environment?
>>
>
> You might look at
> http://www.indelible.org/ink/python-reloading/
> http://code.google.com/p/livecoding/
>
>
Thanks for the links. I'll check them out.
> In most environments this is not an issue because each execution uses
> a new instance of the python interpreter. For example running from the
> command line directly. Many editors have good support for running
> python programs also, so you might run main from the same editor you
> are using to change it. Again, the editor will start a new interpreter
> for each execution so it is not an issue.
>
>
I don't like working under SCITE which allows this. I find it hard to
work with sometimes. I much prefer ipython, it seems more natural to me...
> Kent
>
>
>
For me at least, under ipython in linux, if I do a reload of uladata
from the prompt I do not get a forced compilation and update. I have
not tried
reload(ud) rather than reload(uladata)
Thanks for the suggestions, I'll give them all a go.
Bruce
More information about the Python-talk
mailing list