I have implemented a plugin to be used by other Python projects. I want this plugin to be able to obtain the root directory of the project which called it. How would this be possible?
Asked
Active
Viewed 38 times
0
-
Use `__file__` attribute along with `os.path.abspath` to get the desired path. @D. Basil – Vishnudev Krishnadas Jun 24 '22 at 16:54
-
@Vishnudev Would it be this - ```root = os.path.dirname(os.path.abspath(__file__))``` – D. Bazel Jun 24 '22 at 16:57
-
1Just `os.path.dirname(__file__)` should work. – Vishnudev Krishnadas Jun 24 '22 at 17:17
-
This wouldn't give me the root directory of where the plugin is, correct? I need the root of the project from where the plugin was called. – D. Bazel Jun 24 '22 at 17:22
-
What do you mean by root? How can you distinguish a root? – Vishnudev Krishnadas Jun 24 '22 at 17:23
-
The plugin would be defined in a separate project, which my current working project imports. I need the plugin to access the root of the project which is calling it, not the root of the project where the plugin is defined. – D. Bazel Jun 24 '22 at 17:26
-
Check this out https://stackoverflow.com/questions/55469447/get-caller-functions-absolute-path-to-its-file – Vishnudev Krishnadas Jun 24 '22 at 17:36