Skip to content

Instantly share code, notes, and snippets.

@splee
Created February 10, 2012 21:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save splee/1793220 to your computer and use it in GitHub Desktop.
Save splee/1793220 to your computer and use it in GitHub Desktop.
"""This is main.py, where the main stuff happens.
"""
import sys
import os
# lets assume your file is in /home/oli/nuke_files/main.py
#
# __file__ is a magic variable which python automatically populates, and is the
# full path to the file which is currently being executed (i.e. this one),
# so __file__ == '/home/oli/nuke_files/main.py'
#
# os.path.dirname() takes a path, and removes one level of the directory
# structure. Returns '/home/oli/nuke_files/'
PROJECT_ROOT = os.path.dirname(__file__)
# os.path.join() will join any arbitrary strings into a correct path (even if
# you're running on windows). LIB_PATH == '/home/oli/nuke_files/lib/'
LIB_PATH = os.path.join(PROJECT_ROOT, 'lib')
# sys.path is a list of directories which Python should check for modules.
# insert() will push the path we want at the beggining of the list
# (hence 0 as the position, which is the first argument; to insert something at
# the 50th position you'd use sys.path.insert(50, PROJECT_ROOT). This is not
# limited to sys.path, any list has this function.
#
# once this has been updated, any folder or .py file which is a valid python
# module (has an __init__.py etc) will be found in this directory first, falling
# back to the usual paths if it's not found.
sys.path.insert(0, PROJECT_ROOT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment