external python scripts?

I keep puzzling over this and keep forgetting to ask this question.
How do you load scripts into blender while in the game engine?
I am starting to use longer and longer scripts, so this is very valuable.

While the script is in the path and has a .py, .pyc, or .pyo extension:

import scriptname

option A: an import statement

option B: use setScript() to change the current controller’s script. (note: i havent tested this, just from the top of my head)


con = GameLogic.getCurrentController()
try:
    f = open(GameLogic.expandPath("//module.py"), "rU")
except:
    print "oops, problems opening external script"
else:
    script = f.read()
    f.close()
    con.setScript(script) #this will replace THE CURRENT script with the file we loaded