PyQGIS – Difference Between Processing.runalg() and General.runalg() Explained

pyqgisqgis-processing

In the discussion from a question I asked several days ago (Using the processing framework in a PyQGIS standalone application), someone suggested that I use general.runalg() instead of processing.runalg() for running QGIS algorithms.

I've now used both, and haven't noticed a difference in either performance or syntax between them. I'm just wondering what sort of differences there are between these two methods, and which one I should be using.

Best Answer

Open a QGIS Python Console and run this:

import processing 
help( processing.runalg )

You will get:

Help on function runalg in module processing.tools.general:

runalg(algOrName, *args, **kwargs)

Which indicates us that by using processing.runalg(), you're actually calling general.runalg().

Note that if you want to call general.runalg() explicitly, you need to import the general module from processing.tools.

In summary, use whatever you want, just make sure you initialize Processing (Processing.initialize()) before calling runalg() if you're running a standalone PyQGIS script.