[Bf-python] Importing python code from textwindow as a module
Willian Padovani Germano
wgermano at ig.com.br
Thu Jul 3 03:27:59 CEST 2003
On Wed, 2003-07-02 at 13:03, John wrote:
> Ok, I guess I missunderstood what you ment by sandbox. I thought that
> was the modules storeed within blenders text window objects (or not
> stored in external files). Anyway the .blend file I have included
> illistrates what I mean, I know that the problem is in 2.25. THanks asdf_46
Hi, John
Thanks for the .blend example, it helped : ).
I understand the problem now. When you import a module in Python, it's
not part of the global dictionary (so doesn't get cleared with it).
Only its contents are.
The module itself is put in this dict: sys.modules
So to solve the problem you report, do this at the end of the script
that imports the others (the one you run):
------------
#if you import a module that is a Blender Text, like:
import output
#end the script with this:
import sys
del (sys.modules['output'])
------------
same for each module you import this way, of course.
I tried to find a way to do this automatically, from C, but the code
would be awkward. The Python way above is much, much cleaner. We'll
add this info to a Blender Python FAQ, we'll need one.
Any problem, please tell us. Thanks again : ).
--
Willian, wgermano at ig.com.br
More information about the Bf-python
mailing list