I have two files …
b.py
def showsomething():
print("this is b.py")
and
test.py
print("this is file test.py")
showsomething()
How on earth do I get test.py to use the code in b.py?
I have two files …
b.py
def showsomething():
print("this is b.py")
and
test.py
print("this is file test.py")
showsomething()
How on earth do I get test.py to use the code in b.py?
Heh, figured it out…
import sys
import os
import bpy
blend_dir = os.path.dirname(bpy.data.filepath)
if blend_dir not in sys.path:
sys.path.append(blend_dir)
import b
import imp
imp.reload(b)
b.showsomething()
lets test see b
Is there a better way/proper way of doing this? - what I found does not feel clean!
I would like to code this python script in an external editor and spread it across a number of files for ease of development.
That’s pretty much how it’s done… aside from the imp.reload part which is totally not needed.
You can also take a look at ‘modules’ on the python.org docs.
imp.reload() is there so blender does not keep hold of the external file I might be changing
this is my solution
chanbe test.py so:
import b
print("this is file test.py")
b.showsomething()
Running gives:
C:\BlenderSVN\cmake_all3\bin\2.62\scripts\addons\Ephestos>python test.py
this is file test.py
this is b.py
C:\BlenderSVN\cmake_all3\bin\2.62\scripts\addons\Ephestos>
blah.py
def yada():
print(42)
with blah in modules folder:
from blah import yada
with blah in same folder (init perhaps):
from .blah import yada