I will be importing some CSV files from the directory of the script that I have opened on Python Console on QGIS. Yet, I cannot access the true directory with os.getcwd()
or something else.
Is there a way to do that?
I will be importing some CSV files from the directory of the script that I have opened on Python Console on QGIS. Yet, I cannot access the true directory with os.getcwd()
or something else.
Is there a way to do that?
The QGIS python console is an emulated python console (python plugin).
To do that it's a little bit tricky and I didn't find an other way :
import os
from console.console import _console
script_path = _console.console.tabEditorWidget.currentWidget().path
print(os.path.dirname(script_path))
NB :This sample example only works when the tabEditor is opened and the script is saved on the disk.