Skip to content

Instantly share code, notes, and snippets.

@girishramnani
Created October 15, 2015 15:21
Show Gist options
  • Save girishramnani/ec5283582e9481e391cb to your computer and use it in GitHub Desktop.
Save girishramnani/ec5283582e9481e391cb to your computer and use it in GitHub Desktop.
snippet to add parent module into the path (use only for testing)
"""
this snippet is used to import module from parent directory ( but as this is considered anti pattern dont use it other than for
unittesting )
http://stackoverflow.com/questions/16981921/relative-imports-in-python-3
"""
import sys
import os
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment