1

I try to dissolve layer having multiple fields statistics calculated. I prepared a string variable which has all the information in it. When I paste printed variable into dissolve it works. However I'm not able to use the variable itself. EDIT: OutFields is string.

Variable:

print(OutFields)
[[Fields_i[0], "SUM"],[Fields_i[1], "SUM"],[Fields_i[2], "SUM"],[Fields_i[3], "SUM"],[Fields_i[4], "SUM"],[Fields_i[5], "SUM"],[Fields_i[6], "SUM"],[Fields_i[7], "SUM"]]

It works this way:

arcpy.Dissolve_management(IntPolygon, OutPolygon, ToID, [[Fields_i[0], "SUM"],[Fields_i[1], "SUM"],[Fields_i[2], "SUM"],[Fields_i[3], "SUM"],[Fields_i[4], "SUM"],[Fields_i[5], "SUM"],[Fields_i[6], "SUM"],[Fields_i[7], "SUM"]], "", "")

And it doesn't this way:

arcpy.Dissolve_management(IntPolygon, OutPolygon, ToID, OutFields, "", "")
0

1 Answer 1

1

If it works when you pass a list of lists [[Fields_i[0], "SUM"],[...

But not with a string representation of a list of lists:

"[[Fields_i[0], "SUM"],[F.." #Fields_i[0] inside a string wont work/fetch correct fieldname.

Then pass a list of lists. Try something like this:

import arcpy

fc = r'C:\somedb.gdb\somedata'

Fields_i = [f.name for f in arcpy.ListFields(dataset=fc)] #Or whatever way you list your fields

OutFields = [[Fields_i[j], "SUM"] for j in range(0,8)]

Then dissolve

arcpy.Dissolve_management(IntPolygon, OutPolygon, ToID, OutFields, "", "")

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.