0

I am attempting to run my Python script using the Processing Toolbox in QGIS 2.0. I've used the built-in Python function map() and zip() several times and am now receiving a syntax error even though these functions worked fine in python console. Thanks in advance.

*I was asked to post a little more of my code, so i've edited and added a different chunk as I don't run into these errors when loading the vector layers by pathname…This makes me wonder if there's something wrong with the way these layers input into the Processing script. Mahalo:

from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from processing.core.VectorWriter import VectorWriter
import numpy
import processing

##input1=vector
##input2=vector
##Attribut=field input1
##output=output file

indivLayer = processing.getobject(input1)
grosLayer = processing.getobject(input2)

indivprovider = indivLayer.dataProvider()
grosprovider = grosLayer.dataProvider()

#Break grosLayer dictionary into list of lists (keys represent names of zones)
for key in CG_IDdict.keys():
    listofzones = CG_IDdict.values()

#Get sum of list of zones and put in dictionary with CG_ID keys
sumList = map(sum, listofzones)
sumdict = dict(zip(CG_IDlist, sumList)
#Count in zone
countList = map(len, listofzones)
#Get max and min value of zones
maxValue = map(max, listofzones)
minValue = map(min, listofzones)
#Get average value
meanValue = map(numpy.mean, listofzones)

Error message:

Traceback (most recent call last):
File "C:\Documents and Settings\user/.qgis2/python/plugins\processing\core\GeoAlgorithm.py", line 150, in execute
self.processAlgorithm(progress)
File "C:\Documents and Settings\user/.qgis2/python/plugins\processing\script\ScriptAlgorithm.py", line 213, in processAlgorithm
exec(script) in ns
File "<string>", line 74
countList = map(len, listofzones)
^
SyntaxError: invalid syntax
  • Please include the full traceback as well as the script, if possible. – Jason Scheirer Mar 5 '14 at 0:53
  • PLEASE include the actual error message. And at this point your code and the question don't even match up, there is no map() call whatsoever there. – Jason Scheirer Mar 5 '14 at 1:39
1

You did not close the paren on the line before.

sumdict = dict(zip(CG_IDlist, sumList)

should be

sumdict = dict(zip(CG_IDlist, sumList))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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