pythonqgispyqgis

How to re-use a custom function based on Qgis processing tools in another script?


I'm working in QGIS with python script. I created a script that use processing tools from QGIS using the processing.run(...) function. Everything worked fine. Then, I embedded my code in a function to re-use it in another script. So, I modified the code to make it a function (called my_func) and I saved this function in a file (my_function.py). Then, I import it in my new script (import my_function as mf) in a new script (saved in the same folder). I call my function (a = mf.my_func(...)) but I always have this error message:

NameError: name 'processing' is not defined

I tried to import 'procesing' in both of my script but I always have the same problem. What I find strange is that importing my script doesn't seem to make a problem, and I didn't have this problem when I tested the function as a script before.

Does anyone have some idea to solve this issue ?

Thanks!


Solution

  • OK, I finally found a workaround. I created a processing tool based on my function and I used it in the other script.