Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidMetcalfe/e582c6840518b0fe30f191128cdd9c4d to your computer and use it in GitHub Desktop.
Save DavidMetcalfe/e582c6840518b0fe30f191128cdd9c4d to your computer and use it in GitHub Desktop.
Gets the location of the currently running Python script. Allows one to easily access files in the same directory as the script.
import os
__location__ = os.path.realpath(
os.path.join(os.getcwd(), os.path.dirname(__file__)))
f = open(os.path.join(__location__, 'example.jpg'))
import os
__location__ = os.path.realpath(
os.path.join(os.getcwd(), os.path.dirname(__file__)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment