diff --git a/README.md b/README.md index b585cc4..b15b01e 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,5 @@ Hier entsteht eine Sammlung meiner öfter genutzten Python-Scripts. ## Liste -- mausposition_anzeigen.py: zeigt die Mausposition an \ No newline at end of file +- mausposition_anzeigen.py: zeigt die Mausposition an +- resource_path: Damit wird der relative Pfad von eingebundenen Dateien definiert. Wird benötigt, wenn man ein Python-Script als ausführbare Datei kompilieren möchte, in dem Dateien eingebunden werden \ No newline at end of file diff --git a/resource_path.py b/resource_path.py new file mode 100644 index 0000000..6888fb3 --- /dev/null +++ b/resource_path.py @@ -0,0 +1,12 @@ +import sys +import os + +def resource_path(relative_path): + """ Get absolute path to resource, works for dev and for PyInstaller """ + try: + # PyInstaller creates a temp folder and stores path in _MEIPASS + base_path = sys._MEIPASS + except Exception: + base_path = os.path.abspath(".") + + return os.path.join(base_path, relative_path) \ No newline at end of file