I am attempting to use python to change values in a field named CableName. I am trying to change the capitalization for the first word/words in the field to only the first letter capitalized. For example PRESTON Avenue 420 to Preston Avenue 420. Or N HIGHLAND Avenue 519 to N Highland Avenue 519. I am trying to just focus on the values that contain the word Avenue so I can exclude any variation and then I will replace Avenue with Street, Cove, Road, etc. I've tried to use copilot and I have had some success with other scripts but this one is giving me some trouble. Here are some scripts that have worked for me in the past:
!CableName! .replace("St.", "Street")
!LegacyName! if !CableName! is None else !CableName!
I am trying to get Copilot to write this in a similar format but here is what it gives me:
def capitalize_first_letter(word):
# Check if the word is in all caps
if word.isupper():
# Capitalize the first letter and make the rest lowercase
return word.capitalize()
else:
return word
# Usage example:
# Call the function with the field value
result = capitalize_first_letter(!CableName!)
resultI am new to using Python but if I could get this to work it would save me months of work. Would really appreciate any help with this.