New answers tagged

0

Very nearly thanks BERA - but \W includes "(" and ")" as well as spaces, dashes and underscores. I think building on your code and, looking at the help for re (https://docs.python.org/3/library/re.html), this does it (uses only spaces, dashes and underscores): import re fc = r'my dbf file' fieldnames = ['inField','outField'] with arcpy....


2

The easiest is probably to chain replace: import arcpy fc = r'C:\data.gdb\features' fieldnames = ['infield','newfield'] with arcpy.da.UpdateCursor(fc, fieldnames) as cursor: for row in cursor: row[1] = '_'.join(row[0].replace('-',' ').replace('_', ' ').split()).title() cursor.updateRow(row)


1

While @Hornbydd's answer directly addresses your question, I wanted to point out that another approach to solving this would be to use Label Classes, which are the built-in solution for accomplishing exactly what what you are trying to do: label different features different ways depending on a specific set of criteria. A very very basic primer on label ...


2

You are mixing languages (VB and python), that's why your code is not working. Make sure the parser is set to PYTHON and here is an example of either printing the label in upper case or in italics: def FindLabel ( [TYPE] , [LABEL] ): if [TYPE] == "School": return [LABEL].upper() else: return "<ITA> " + [LABEL] + "&...


2

Your if statement needed a little work. I re-wrote the first condition to a shorter equivalent of class=='motorway' or class=='primary' or class=='trunk' def Reclass(class): if class in ('motorway','primary','trunk'): return 'Primary' elif class == 'secondary': return 'Secondary'


1

Try using the da.SearchCursor to list all values, then update/calculate using da.UpdateCursor: import arcpy fc = r'C:\GIS\ArcMap_default_folder\Default.gdb\fs_riks_Buffer' freqfield = 'Frequency' ratiofield = 'ratio' sql = 'ORDER BY {0}'.format(arcpy.AddFieldDelimiters(datasource=fc, field=arcpy.Describe(fc).OIDFieldName)) frequencies = [row[0] for row in ...


Top 50 recent answers are included