I’m currently writing an add-on and I would like to get the path the add-on is stored in so that I can create a log file in that directory containing relevant information of the internal things that my add-on is doing for debugging.
I’ve looked into __name__
and os.getcwd()
but none of these get the directory of the add-on. The following is a minimal working example that I’m using to check that I’m actually getting the directory the add-on exists in (sharing it just in case anyone is interested in experiment with them).
import os
import aqt
def my_function():
message = [__name__, os.getcwd()]
aqt.utils.showText('\n'.join(message))
my_action = aqt.qt.QAction("My new action", aqt.mw)
my_action.triggered.connect(my_function)
aqt.mw.form.menuTools.addAction(my_action)