Is there any possible fetching row using Python script?
Solved! Go to Solution.
If I understand correctly you could use following script:
cursor = arcpy.UpdateCursor("testFC") gridDict = {} for row in cursor: print row.getValue("GridNo") gridNo = row.getValue("GridNo") if(gridDict.has_key(gridNo)): gridDict[gridNo] = gridDict[gridNo] + 1 else: gridDict[gridNo] = 1 name = "{0}_{1}".format(gridNo, str(gridDict[gridNo]).zfill(3)) row.setValue("Name",name) cursor.updateRow(row)
Make sure to correct the feature class path and field names as they are.
Thanks,
Mahtab
This is the direct link to "searchcursor"
http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-data-access/searchcursor-class.htm
There is a whole of lot of reading in the arcpy module, its classes and functions which should be read to put this in context.
The last link is useful. But it is not clear my problem. I have attribute table that have Name and Grid no field. I have to update Name field using Grid no. For Example in the Grid Field (Grid1, Grid2, Gird2, Grid1, Grid1) so I have update Name field like as (Grid1_001, Grid2_001, Grid2_002, Grid1_002, Grid1_003). Kindly suggest me.
Try searching for arcpy.da.UpdateCursor that will get you where you want to go
If you have another column which contains the "001", "002" or perhaps just the number, you could probably just do a concatenation with the field calculator.
If you havn't got this second field, what governs the "001", "002" part connecting to "Grid1" etc?
There is no column which contains the "001", "002".
Show the fields you have. It is not clear whether you want to add new fields, or change the name of existing fields. In both cases, emulate the code in.
Add
http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/add-field.htm
Alter/Rename
http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/alter-field-properties.htm
If I understand correctly you could use following script:
cursor = arcpy.UpdateCursor("testFC") gridDict = {} for row in cursor: print row.getValue("GridNo") gridNo = row.getValue("GridNo") if(gridDict.has_key(gridNo)): gridDict[gridNo] = gridDict[gridNo] + 1 else: gridDict[gridNo] = 1 name = "{0}_{1}".format(gridNo, str(gridDict[gridNo]).zfill(3)) row.setValue("Name",name) cursor.updateRow(row)
Make sure to correct the feature class path and field names as they are.
Thanks,
Mahtab
Thanking you so much. It was very useful.
I had created the Python toolbox. Is there any possible to hide our source in the Python toolbox.
I am afraid you can't do this. Search for python obfuscation and you will get the answer.