Multiple scripts and refreshing problem

Im trying to split a big script into multiple files but I encountered a problem. I’ll try to explain with a simple example.

I open the Blender’s text editor and I write:

def poof():
    print "123"

…I name that datablock “”. Then I create a new datablock with ADD NEW and write in it:

import foo

,I name it “”, If I execute the “” the console prints “123” as it should. The problem is that if I edit the “” the “” will still print “123”. For some reason the code doesn’t refresh.

Is that a workaround or I should report it as bug?
Thanks in advance!!

I get the same issue, both with internal and external files…

the only workaround I’ve found is reloading the scripts (or file)… but then the pyc versions can get in the way too if you’re using external files so make sure you delete them before re-load!

I’d be interested in any more elegant solutions that anyone might suggest!

The reload() forces the import of a module even if its loaded already. This is not a bug: normally import checks if something is imported already and if so does not import it again to prevent executing a module twice. It does check whether the source (.py) or the compiled versions (.pyo or .pyc) are newer but in this case no such check is done as Blender keeps both source and bytecode internal and (apparently) does no time check (This might be called a bug but I not sure it is documented at all). Anyway, Blender does the right thing when reload() is called, so you might just use that as long as you are developing and remove it once the code is mature and installed.

Edit: I checked the source by way of documentation and if I understand it correctly an import does this:

use Pythons regular import (i.e. check for a file or .pyc .pyo )
if not succesful:
    check whether there is a textblock
    if there is and it is compiled: use compiled textblock
    if there is and it is not compiled: compile it and use the compiled textblock

So it never checks whether the compiled version of a text block is older than the textblock itself. Also, once you have saved your textblock to an external file, that external file will be used, even if the internal textblock is altered (although this is flagged by the red sync button in the text editor)

Many thanks for the solution! I will test it when I get home