Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active February 28, 2019 04:37
Show Gist options
  • Save CMCDragonkai/2e0ae76e87537b708ed12ba05851d96b to your computer and use it in GitHub Desktop.
Save CMCDragonkai/2e0ae76e87537b708ed12ba05851d96b to your computer and use it in GitHub Desktop.
Get Script Directory in Python #python
import os.path as path
from inspect import getsourcefile
from pathlib import Path
path_to_this_script = path.abspath(getsourcefile(lambda: 0))
path_to_containing_dir = path.dirname(path_to_this_script)
# alternative using Path object
path_to_this_script = Path(getsourcefile(lambda: 0)).resolve()
path_to_containing_dir = path_to_this_script.parent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment