Skip to content

Instantly share code, notes, and snippets.

@h4c5
Last active August 4, 2025 07:54
Show Gist options
  • Select an option

  • Save h4c5/34aeef03ddc4f3c41b378396f2059d09 to your computer and use it in GitHub Desktop.

Select an option

Save h4c5/34aeef03ddc4f3c41b378396f2059d09 to your computer and use it in GitHub Desktop.
[python] current_dir
# Cf. https://stackoverflow.com/questions/2632199/how-do-i-get-the-path-of-the-current-executed-file-in-python/33531619#33531619
from inspect import getsourcefile
from pathlib import Path
CURRENT_DIR = Path(file).parent if (file := getsourcefile(lambda: 0)) else Path.cwd()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment