Skip to content

Instantly share code, notes, and snippets.

@tsalo
Last active August 29, 2015 14:17
Show Gist options
  • Save tsalo/04f46174e0bc0c3e36bb to your computer and use it in GitHub Desktop.
Save tsalo/04f46174e0bc0c3e36bb to your computer and use it in GitHub Desktop.
Get directory of script. Also, get parent directory. Add to the beginning of a script to help you load files in the same directory as the script. Makes projects more portable.
"""
Get directory of script. Also, get parent directory.
"""
import os.path
code_dir = os.path.dirname(__file__)
par_dir = os.path.abspath(os.path.join(code_dir, os.path.pardir))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment