Field Calculator String Issue

693
3
Jump to solution
05-17-2019 10:30 AM
AndrewRiggs1
New Contributor

Very new to ArcPro and have hit a wall. I can't seem to find a solution anywhere so here goes...

Using Field Calculator to populate a new Text (50) field.

In ArcMap I would have entered [Field1] & "-" & [Field2].

In ArcPro I've entered !Field1! + '-' + !Field2!.

The '-' turns red and the process fails. I've also tried "-".

Expression type set to Python3.

Advice on this seemingly simple task?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
AndrewRiggs1
New Contributor

Chris, 

Thanks for your response. It wasn't giving me much detail. I actually just figured out what the issue was a few minutes ago. 

I was entering it as follows: [Field1] & "-" & [Field2]

I entered it as: [Field1]&"-"&[Field2]    <Removing the spaces resolved the issue. 

View solution in original post

0 Kudos
3 Replies
ChrisRingo
Occasional Contributor

Did you click on "View details" to get more information on the error? (You can get to the tool's results, including any error messages, either by clicking on "View details" in the error window that pops up, or by going to the Catalog tab, clicking on "History", and mousing-over the tool name in the list.) It could be that the new field isn't wide enough to hold the concatenated values.  I think a quoted string will always turn red in the field calculator.

AndrewRiggs1
New Contributor

Chris, 

Thanks for your response. It wasn't giving me much detail. I actually just figured out what the issue was a few minutes ago. 

I was entering it as follows: [Field1] & "-" & [Field2]

I entered it as: [Field1]&"-"&[Field2]    <Removing the spaces resolved the issue. 

0 Kudos
DanPatterson_Retired
MVP Emeritus
'{}-{}'.format(!Field1!, !Field2!)

the format approach in python handles type conversion automatically to string/text regardless of the input

0 Kudos