AnsweredAssumed Answered

Replacing record from a field with a List

Question asked by BrunodeDeus on Feb 18, 2018
Latest reply on Feb 22, 2018 by xander_bakker

Hi,

I've Feature Class which keeps changing (e.g. S_pol_Din_DepL82270692015146eAnt015130) and I would like use Arcpy to replace a text (like 2015178eAnt015146) from him field (d2clust200m). Some rows are empty, e.g <Null>, and I don't want change them. But, I can't use replace with a text from ListFeatureClass, it shows that is done, But, isn't.

The text that will be replaced is always the same from the last piece's name from the another FC (it always starts with "pol_din").

If it's too hard be done by arcpy, I can use MB. Or even replace just what isn't null.

Next, I show all tries I've done.

import arcpy
...
... # Local variables:
... arcpy.env.workspace = r'C:\Teste_Auto_CLEIA\Auto_Classi\Dinamica_GDB.gdb'
... 
... #List FC # line 6
... FC = arcpy.ListFeatureClasses("S_pol_Din*")
... Feature = FC[0]
... print"Feature: "+str(Feature)
... strFeature = str(Feature)
... print"strFeature: "+strFeature
...
... #List FC # line 13
... FCName = arcpy.ListFeatureClasses("pol*")
... FC_Name = FCName[1]
... print"FC_Name: "+str(FC_Name)
... FCNameCut = FC_Name[-17:]
... print"FCNameCut "+FCNameCut
...
... #Calculate field (D2clust200m)             #Line 20
... arcpy.CalculateField_management (Feature, "D2clust200m", "!D2clust200m!.replace('"'FCNameCut'"', \"test\")","PYTHON")
... print"Try 1 Calculated"
...
... #Calculate field (D2clust200m)            
... #arcpy.CalculateField_management (Feature, "D2clust200m", "!D2clust200m!.replace(\"FCNameCut\", \"test\")","PYTHON")
... #print"2nd try Calculated"
...
... #Calculate field (D2clust200m)             
... #arcpy.CalculateField_management (Feature, "D2clust200m", '!D2clust200m!.replace('"'FCNameCut'"', '"'test'"')',"PYTHON")
... #print"Try 3 Calculated"
...
... #Calculate field (D2clust200m)  #This one works if I don't use a list's word          
... #arcpy.CalculateField_management (Feature, "D2clust200m", '!D2clust200m!.replace(\"FCNameCut\", \"test\")',"PYTHON")
... #print"4th try Calculated"
... print"Done"
...
Feature: S_pol_Din_DepL82270692015146eAnt015130
strFeature: S_pol_Din_DepL82270692015146eAnt015130
FC_Name: pol_Din_DepL82270692015178eAnt015146
FCNameCut 2015178eAnt015146
Try 1 Calculated
Done

Thanks

 

*I'm using Arcmap 10.4 with Python 2.7, but I appreciate if it works on ArcMap 10.1

Outcomes