thispath(*args, frame=1, aspath=True, **kwargs)[source]#

Alias for sc.thisdir() that returns a path by default instead of a string.

New in version 2.1.0.

Tiny helper function to get the folder for a file, usually the current file. If not supplied, then use the current file.

  • file (str) – the file to get the directory from; usually __file__

  • path (str/list) – additional path to append; passed to os.path.join()

  • args (list) – also passed to os.path.join()

  • frame (int) – if file is None, which frame to pull the folder from (default 1, the file that calls this function)

  • aspath (bool) – whether to return a Path object instead of a string

  • kwargs (dict) – passed to Path()


the full path to the folder (or filename if additional arguments are given)

Return type:

filepath (str)


thisdir = sc.thisdir() # Get folder of calling file
thisdir = sc.thisdir('.') # Ditto (usually)
thisdir = sc.thisdir(__file__) # Ditto (usually)
file_in_same_dir = sc.thisdir(path='new_file.txt')
file_in_sub_dir = sc.thisdir('..', 'tests', '') # Merge parent folder with sufolders and a file
np_dir = sc.thisdir(np) # Get the folder that Numpy is loaded from (assuming "import numpy as np")
New in version 1.1.0: “as_path” argument renamed “aspath”
New in version 1.2.2: “path” argument
New in version 1.3.0: allow modules
New in version 2.1.0: frame argument