Monday 23 January 2017

arcgis desktop - Concatenating strings from two fields using Python in ArcMap Field Calculator?


I'm new to Python scripting and I don't understand what is wrong with this code. I want to concatenate the string values from GRID1MIL and GRID100K. I've created a text column MGRS to begin with.


enter image description here


enter image description here


I also tried writing the following but it did not work:


enter image description here


enter image description here


Using VB Script I was able to do it easily but I want to learn how it's done with Python.


enter image description here




Answer



I think you're almost there, but you need to get your indentation consistent. Indentation is very important in Python and defines the scoping/grouping of statements. Suggested indentation is to add four spaces for every indentation level.


try keeping the same indentation for lines: c=a+b and return c


like this:


def addIt(a,b)
c = a + ' ' + b
return c

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...