>>> import arcpy ... fc = r'O:\path here...\Storm.gdb\Storm\JunctionBox' ... ... desc = arcpy.Describe(fc) ... fields = desc.fields ... ... for field in fields: ... if field.Type == "String": ... with arcpy.da.UpdateCursor(fc, str(field.name)) as cursor: ... for row in cursor: ... if row[0] == None: # Check for "<Null>" ... continue ... else: ... any(x.islower() for x in row[0]) == True ... row[0] = row[0].upper() ... cursor.updateRow(row)
Hello all,
I have this code that I pieced together in the past with your help. But it references a specific feature class on my network. How can I get it to now reference my sql express geodatabase feature class instead? The feature class is in my mxd where I run this, so can I just reference the feature class within this current map document somehow?
Thank you in advance,
Andrea
Solved! Go to Solution.
Nope, I'm not. I didn't figure I had to since I manually start editing before I run the code. But after starting to read the help it looks like I need something like that.
So three people actually helped me answer this question as I had to look at the help for arcpy.da.Editor to copy the sample code there. Thank you for your help! Code that works below.
import arcpy import os fc = 'Database Connections/DEFAULT@Ozark.sde/Ozark.DBO.Storm/Ozark.DBO.BoxCulvert' workspace = 'Database Connections/DEFAULT@Ozark.sde' #start an edit session. Must provide the workspace. edit = arcpy.da.Editor(workspace) #Edit session is started without an undo/redo stack for versioned data. So True for versioned data. edit.startEditing(False, True) #start edit operation edit.startOperation() desc = arcpy.Describe(fc) fields = desc.fields for field in fields: if field.Type == "String": with arcpy.da.UpdateCursor(fc, str(field.name)) as cursor: for row in cursor: if row[0] == None: # Check for "<Null>" continue else: any(x.islower() for x in row[0]) == True row[0] = row[0].upper() cursor.updateRow(row) #stop the edit session edit.stopOperation() #Stop the edit session and save the changes edit.stopEditing(True)
If youre database is a SQL SDE, you can use a function and trigger to do this real-time as data is edited. A slight modification of this SQL Code will do the trick, the modification being you'd have to alter the function to upper-case every character.