Tuesday, October 30, 2012

python: import a custom file

suppose you wrote a python file with common functions, say util.py and you want use it in another of your python files

If they in the same directory the below should work

import util

If they in different directories the below will not work. To make it work add another entry

sys.path.append('<path/to/the/folder/of/util.py>')
import util

This fixes it. This is the simplest way to me but there must be more.I will explore it further and update.

No comments: