[Python-talk] Modules force recompilation?
Bruce Labitt
bruce.labitt at myfairpoint.net
Sat Feb 6 12:34:34 EST 2010
Kent Johnson wrote:
> On Thu, Feb 4, 2010 at 5:43 PM, <bruce.labitt at autoliv.com> wrote:
>
>> I have created a couple modules(?) that have functions in them. They are
>> spread across a couple of files.
>>
>> One thing that I don't know how to do gracefully, is to force a recompile
>> of a module to bytecode once I have editted the source file.
>>
>> How is this done in python?
>>
>> I mean the only thing that I know that works for sure is
>> Edit file2.py
>> 1. Bail out of ipython
>> 2. Manually delete file2.pyc
>> 3. Launch ipython
>> 4. Run main.py
>>
>> Naturally, this is a relatively slow and annoying process...
>> Is there a better way?
>>
>
> You should not have to delete the .pyc file. The interpreter should
> see that the .py file is more recent and re-compile automatically.
> What is the relationship between main.py and file2.py? Probably you
> need to reload file2. I think the problem is that the loaded module
> has been cached, not that it is not being re-compiled. Re-launching
> ipython clears the module cache. What happens if you try the above
> sequence without deleting file2.pyc?
>
> Kent
> _______________________________________________
>
>
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?
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.
This can be quite confusing to analyze! Did I fix my bug or not? A few
minutes may pass before I remember this python gotcha again... If I've
been working on something for a long time, or if I get distracted by
something, I can easily fall into this trap!
This is not a good thing for the language IMHO. Even more so when in
development mode.
FWIW, both uladata.py and targets.py do not import any other modules
I've created. They are self contained. However, both (uladata &
targets) import stuff from numpy and scipy.
Anyone have some insight on how to do this within the ipython
environment? Or some other environment?
Thanks,
Bruce
More information about the Python-talk
mailing list