views:

299

answers:

4

I have have a python file that imports a few frequently changed python files. I have had trouble with the imported files not recompiling when I change them. How do I stop them compiling?

+2  A: 

I don't think that's possible - its the way Python works. The best you could do, I think, is to have some kind of automated script which deletes *.pyc files at first. Or you could have a development module which automatically compiles all imports - try the compile module.

I've personally not had this trouble before, but try checking the timestamps on the files. You could try running touch on all the Python files in the directory. (find -name \\*.py -exec touch \\{\\} \\;)

Lucas Jones
compileall.compile_dir with force = True looks like it should do the trick, thanks
jonatron
+1  A: 

There are some modules which might help you:

The py_compile module (http://effbot.org/librarybook/py-compile.htm) will allow you to explicitly compile modules (without running them like the 'import' statement does).

import py_compile
py_compile.compile("my_module.py")

Also, the compileall module (http://effbot.org/librarybook/compileall.htm) will compile all the modules found in a directory.

import compileall
compileall.compile_dir(".", force=1)
ewall
A: 

You are looking for compileall

compileall.compile_dir(dir[, maxlevels[, ddir[, force[, rx[, quiet]]]]])

Recursively descend the directory tree named by dir, compiling all .py files along the way.

Nadia Alramli
A: 

In python 2.6, you should be able to supply the -B option.

rhettg