2

Generating an error in what should be a basic field calculation.

I have two text fields: MyAddress and AreaName. Both are text. I would like to use MyAddress to populate AreaName with everything except the street type. E.g. "Eagle View Ln" just becomes "Eagle View".

The code that I thought would work:

!MyAddress!.split(" ")[:-1]

I've tried it using the code block, same result.

This generates error 001156. The help documentation suggests it may be a disagreement between field type or length. I have double checked both, and been trying with a few different fields. It seems to be something with the indexing, as str() generates a string version of he appropriate list.

str(!MyAddress!.split(" ")[:-1])

returns ["Eagle", "View"] in the field.

But basic indexing seems to work on the field:

!MyAddress![:-1]

Returns Eagle View L

What am I missing here?

1

You're really close.

An extra step is needed to rejoin the list values back together. Enter 'Join'

myAddress = "Eagle View Ln"
myAddressAsList = myAddress.split(" ")[:-1] ## Returns a list: ['Eagle', 'View']
myNewAddressAsString = " ".join(tempList) ### Returns a string: 'Eagle View'

# Or simplified to just one line would be:
otherNewAddress = " ".join(myAddress.split(" ")[:-1])

Lastly, if calculated using a Code-Block in ArcGIS Pro's "Calculate Field" tool, it might look something like this:

Calculate Field example

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.