RuntimeError using searchCursor

1046
5
Jump to solution
10-02-2014 02:16 AM
JuttaSchiller
New Contributor III

I always get the following error. I really don’t know what to do. Also tried to work with a fgdb and got the same error. Do you have an idea what I’m doing wrong? This is just a part of the code...

runningtime.PNG

import arcpy

import os

from arcpy import env

env.overwriteOutput = True

env.workspace = r"D:\Users\julia\erste_aufg\cities_UA"

env.qualifiedFieldNames = False

fcResult = arcpy.ListFeatureClasses("*_result.shp")

for shpresult in fcResult:

    shpresultName = os.path.splitext (shpresult) [0]

    print shpresultName

    outputfile = env.workspace + "\\" + shpresultName + "_.txt"

    f = open (outputfile, 'w')

    f.write ("ID,Combi1,Combi2,Combi3\n")

    f.close ()

    f = open (outputfile, 'a')

    valueDict = {}   

    with arcpy.da.SearchCursor(env.workspace + "\\" + shpresultName, ["Id", "GRIDCODE"]) as searchRows:

        for searchRow in searchRows:

                keyValue = searchRow[0]

                gridcode = searchRow[1]

                if not keyValue in valueDict:

                        valueDict[keyValue] = [gridcode]

                elif not gridcode in valueDict[keyValue]:

                        valueDict[keyValue].append(gridcode)

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JuttaSchiller
New Contributor III

Find my mistake: I just had to enter shpresult instead of env.workspace + "\\" + shpresultName in the cursor.

Sorry, for the question.

View solution in original post

0 Kudos
5 Replies
JuttaSchiller
New Contributor III

Find my mistake: I just had to enter shpresult instead of env.workspace + "\\" + shpresultName in the cursor.

Sorry, for the question.

0 Kudos
JohannesBierer
Occasional Contributor III

Wird denn die txt in dem Ordner erstellt?

0 Kudos
JuttaSchiller
New Contributor III

ja, dass wird sie.

0 Kudos
JohannesBierer
Occasional Contributor III

Ja wunderbar - gelöst - selbst ist die Frau

0 Kudos
JuttaSchiller
New Contributor III

Yes!

0 Kudos