Using external python files

Normally python files have to be either:

  1. In the blend file itself
  2. In the same folder as the blend file

By using some other python you can manually add another directory
Or by linking to a blend in the scripts directory you can get blender to add it

I discovered a new way recently.

Say I have a script:
/Data/Scripts/test.py

I can run it in module mode by putting in the logic brick:
Data.Scripts.test.function_to_run

It doesn’t require spare blend files, python code to add the directory or anything really. Just enter the path separated by dots (and don’t have spaces in directory names)
This is a clear abuse of pythons package syntax, but hey, it works!

Could you write code then execute it?

Save the generated snippet if conditions are met?

might be cool for random generated ai,

Thanks for the tip! (Data.Scripts.text.function_to_run or Data.Scripts.teSt.function_to_run ? )

When you type text in python, it magically changes it to test… ahem, I mean, uh…

Yup, it should be test (fixed)