How to import a script in an other script ?

Hello !

This is probably a silly question, please forgive me ^^
I’m writing scripts for my bge game. How can I import (I mean, with the from-import statement) a script packed inside the .blend ?
Bonus question : and if the script is outside the .blend ? (not packed, not linked)

Thanks !

just make a file called x.py
and write some thing like

c=12

and in the other script file
use

import x
print c

that’s it.
python 2.6

Haha it didn’t work just because of the missing ‘.py’ ! Thanks !

I think you might still have to say something like…

print (x.c)

I use something like this.


import myPythonLibrary as myLib

print (myLib.mvVar)

Or call functions or what not as well.

Alternatively: the deprecated way, but doesn’t require writing to file

import Blender, sys, new

def createModule(textName):
    text = Blender.Text.Get(textName)
    pcode = ''.join(text.asLines())
    module = new.module(textName)
    exec(pcode,module.__dict__)
    sys.modules[textName] = module

createModule('bla')
from bla import * 

creates a module directly from a blender text, I don’t think it will work on 2.5+