Select to view content in your preferred language

Make All Fields All Capitial

277
4
4 weeks ago
Labels (3)
FlightDeck
Frequent Contributor

Hey all,

I understand I can use FieldName!.upper() to make one field upper case. Is there an equally easy way to make this apply to all fields simultaneously rather than applying this one field at a time? 

0 Kudos
4 Replies
DavidSolari
MVP Regular Contributor

You can use Calculate Fields to do multiple calculations in one pass.

0 Kudos
FlightDeck
Frequent Contributor

Can you elaborate? I see you linked out to the Calculate fields Documentation but I'm not sure how to apply that to my current use case. It looks like most of the examples are pulling multiple fields to calculate one field where I just need to Capitalize all fields. Sorry pretty new to python and such so still deep in the learning curve...

0 Kudos
DavidSolari
MVP Regular Contributor

The tool lets you pick multiple fields to run calculations on, so you can add every field you want to capitalize and then set each expression to be !That_Field!.upper().

If you want to do this with Python you can use an Update Cursor, play around with that on your test data and you should get good results.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Something like the following should work or get you close:

tbl = # full path to table or feature class
text_fields = [
    field.name 
    for field 
    in arcpy.Describe(tbl).fields 
    if field.type == "String"
]
with arcpy.da.UpdateCursor(tbl, text_fields) as cur:
    for row in cur:
        row = [
            item.upper() if item else None
            for item
            in row
        ]
        cur.updateRow(row)