Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Help with UpdateCursor

$
0
0
Hi, I'm new to python and trying to figure some things out here. I have this bit that I'm working on but once I run it I have to close down PythonWin to be able to run it again. It works up until the part where I start with the cursor. I'm guessing that it creates a lock when the cursor starts but from what I read it should release the lock once the script is done.

I've also tried adding del row and del cursor to the end of the script but it has the same problem. Runs once then I have to close PythonWin to run it again.

Code:

import arcpy

# Set Workspace
from arcpy import env
env.workspace = "C:/EsriPress/Python/Data/Test"

# Variables
cl = "cl.shp"
cl_split = "cl_split.shp"
newfield = "CASE"
fieldtype = "TEXT"
oldfield = "FID"

# Splitline
arcpy.SplitLine_management(cl, cl_split)

# Adds new CASE field
arcpy.AddField_management(cl_split, newfield, fieldtype)

# Sets new CASE field equal to FID
cursor = arcpy.UpdateCursor(cl_split)
for row in cursor:
    row.setValue(newfield, row.getValue(oldfield))
    cursor.updateRow(row)

I'm about to head home for the weekend and was hoping someone could help me understand what is happening here so I can move on and finish the rest of my first script next week.

Thanks in advance!

Viewing all articles
Browse latest Browse all 2485

Trending Articles