Get Python file directory in Python可打印版本 +- RoboDK Forum (//m.sinclairbody.com/forum) +-- Forum: RoboDK (EN) (//m.sinclairbody.com/forum/Forum-RoboDK-EN) +---Forum: RoboDK API (//m.sinclairbody.com/forum/Forum-RoboDK-API) +---Thread: Get Python file directory in Python (/Thread-Get-Python-file-directory-in-Python) |
Get Python file directory in Python-JobdV-10-05-2021 Hi! I am trying to get the directory in which my Python program is saved. However, using the following code, I always get back the AppData/Local/Temp folder. Is it possible in RoboDK to get my original directory? For my specific purpose, it is also okay to get the directory of where my RoboDK file is stored. Example: import os DIR = os.path.dirname(os.path.realpath(__file__)) print(DIR) Result: C:\Users\MyName\AppData\Local\Temp Thank you for your help! RE: Get Python file directory in Python-Sam-10-06-2021 (10-05-2021, 07:59 PM)JobdV Wrote:Hi! Running a script that is held in RoboDK's tree will always return a path in %TEMP%, as RoboDK keeps an internal copy of the script. If you wish to run a python script that is not saved in RoboDK, I suggest you take a look at RoboDK Apps! More info here:https://github.com/RoboDK/Plug-In-Interface/tree/master/PluginAppLoader |