I'm new with python programming and I need some help for my case. I want to use inverse distance weighted function to interpolate precipitation values using values from 78 weather stations. so I create this sequence of processing algorithms that run perfectly one time and produce an interpolate raster layer as I wantedbold. The problem is that I wanted to run these sequence all the times I need. All bold "9" values in code should be run to numbers 2, 3, 4 ..., 10, including number 10. Any ideas for helping me?

processing.runalg("qgis:joinattributestable", "D:\PATRICIA\IG\QGIS\DIST_COSTA_etrs89.shp", "D:\PATRICIA\DOCUMENTOS\ESTACOES METEOROLOGICAS\DADOS METEOROLOGICOS\HR\H_1999_1_**9**.xlsx", "EST", "num", "D:\PATRICIA\IG\QGIS\FWI\HR\ETACOES_HR_1999_1_**9**")
processing.runalg("qgis:selectbyattribute", "D:\PATRICIA\IG\QGIS\FWI\HR\ETACOES_HR_1999_1_**9**.shp", "H", 1, "NULL", "D:\PATRICIA\IG\QGIS\FWI\HR\ETACOES_HR_1999_1_**9**.shp")
processing.runalg("qgis:saveselectedfeatures", "D:\PATRICIA\IG\QGIS\FWI\HR\ETACOES_HR_1999_1_**9**.shp", "D:\PATRICIA\IG\QGIS\FWI\HR\ESTACOES_HR_1999_1_**9**_SF_Int.shp")
processing.runalg("qgis:selectbyattribute", "D:\PATRICIA\IG\QGIS\FWI\HR\ESTACOES_HR_1999_1_**9**_SF_Int.shp", "H", 1, "-999.9", "D:\PATRICIA\IG\QGIS\FWI\HR\ESTACOES_HR_1999_1_**9**_SF_Int.shp")
processing.runalg("qgis:saveselectedfeatures", "D:\PATRICIA\IG\QGIS\FWI\HR\ESTACOES_HR_1999_1_**9**_SF_Int.shp", "D:\PATRICIA\IG\QGIS\FWI\HR\ESTACOES_HR_1999_1_**9**_SF.shp")
processing.runalg("saga:inversedistanceweighted", "D:\PATRICIA\IG\QGIS\FWI\HR\ESTACOES_HR_1999_1_**9**_SF.shp", "H", 0, 2, 0, 1, 100, 0, 0, 8, "-152444.0, 180000.0, -302911.0, 280000.0", 100, "D:\PATRICIA\IG\QGIS\FWI\HR\Python_HR_Viz8_Cell100_**9**") 
  • I see by your file path syntax that you're not running in linux which is a shame. If you were, you could run batches of processing.runalg commands in parallel as described in purplelinux.co.nz/?p=190
    – Mr Purple
    Mar 21, 2018 at 7:30

1 Answer 1


Write a for loop and use string replacement to replace the "bold 9" with the current value of i, as in

for i in range(2,11): path = "D:\PATRICIA\IG\QGIS\FWI\HR\ETACOES_HR_1999_1_%d" %(i)

  • @PatríciaFernandes please upvote helpful answers and accept answers which solve your problem by clicking the tick mark on the left side of the answer.
    – underdark
    May 19, 2015 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.