Skip to content

Instantly share code, notes, and snippets.

@KPB3rd
Created September 30, 2022 14:43
Show Gist options
  • Select an option

  • Save KPB3rd/fbe23585fa898456fac7ee0ec6e633f2 to your computer and use it in GitHub Desktop.

Select an option

Save KPB3rd/fbe23585fa898456fac7ee0ec6e633f2 to your computer and use it in GitHub Desktop.
Get the directory location where the python script file is
# get the location of the script, NOT the location we are running from
# Consider if the code is run by python or exe
# determine if application is a script file or frozen exe
if getattr(sys, 'frozen', False):
dir_path = os.path.dirname(sys.executable)
elif __file__:
dir_path = os.path.dirname(os.path.realpath(__file__))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment