11

You have to include quotes within your expression string. Try this: fcList = arcpy.ListFeatureClasses() fieldName1 = "Author" expression1 = "\"John Doe\"" for fc in fcList: arcpy.AddField_management(fc,fieldName1, "TEXT") arcpy.CalculateField_management(fc, fieldName1, expression1) By adding in escaped double ...


10

I'll try to explain this the best I can so hopefully you can move forward. The short answer is, if your PYTHONPATH is pointing at an actual version of Python, when a product loads up and needs Python it's going to see this directory. In the case of ArcGIS Pro (64bit, using Python 3.4) and ArcMap (32bit, using Python 2.7)... well the use of PYTHONPATH and ...


9

I think this is just a bug/limitation of the Python parser with the field calculator/Calculate Field tool. If a newline is encountered within the text field, a SyntaxError: EOL while scanning string literal occurs no matter what you try. I can reproduce the issue at 10.1 SP1 by importing the following CSV file into a file geodatabase, adding a field and ...


8

From the ArcGIS Help: Note: The Raster Calculator tool is intended for use in the ArcGIS for Desktop application only as a GP tool dialog box or in ModelBuilder. It is not intended for use in scripting and is not available in the ArcPy Spatial Analyst module. That said, you can use it with arcpy.gp.RasterCalculator_sa, but you need to pass it a ...


7

You have a repeated typo: match.fabs instead of math.fabs. math is a python library, fabs is the absolute value function.


6

the syntax !SPECIES!.lower() is a correct Python statement. The type of your input field is obviously text so the problem is not there. Of course you need to check the Python box as suggested by @Brad, but error 539 is usually associated with Python (so I think you did). The source of the problem is therefore most probably in the output field type. Check ...


6

In this example, the "soils" field is text and the "WScore" field is double. The following approach should work for you: Pre-logic Script Code: def reclass(x): if x in ["Ds", "Oo", "Mu", "P", "Se"]: return 2.5 else: return 0 reclass(!soils!)


6

As was mentioned in the comments, your formula should read: (12.56637 * !AREA_GEO!) / (!PERIM_GEO! ** 2) or (12.56637 * !AREA_GEO!) / (!PERIM_GEO! * !PERIM_GEO!) This page on python operators shows that the ^ operator is Bitwise XOR.


6

You are only passing one variable into your function: PropType. But on the first line of your function, you refer to a variable named PropClass. Your function has no idea what this variable is, because you haven't defined it inside the function, and you haven't passed it into the function as an input. It sounds like you want to do that, so your function's ...


5

Use lower-case, quoted values (strings), this is apparently what the model expects for preconditions. e.g. return "true" or return "false"


5

Try: expression = "!" + CoInset.datasetName +".OBJECTID!" instead of: expression = "!" + CoInset.name +".OBJECTID!" The joined fieldnames should reflect the feature class/annotation's workspace name, not table-of-contents name.


5

The problem with your script is the expression. The expression must have the variable in single quotes since it is a string. There are a number of ways to format this. My favorite is as follows: expression = """'{}'""".format(name) Note the casting to string is not necessary since .format will do so automatically


5

Per the Esri documentation, this tool is not available in arcpy scripting: http://desktop.arcgis.com/en/arcmap/latest/tools/spatial-analyst-toolbox/raster-calculator.htm Note: The Raster Calculator tool is intended for use in the application only as a GP tool dialog box or in ModelBuilder. It is not intended for use in scripting and is not available ...


4

The work around for this since my feature class table originated in excel was to use the following excel command: =CLEAN method to remove all return or new line characters. You can then join or import the table into your GIS database.


4

I see two problems. First, the way it's indented won't iterate through the featureclasses and perform the process on each, it will just iterate through and print your print statement. Second, your expression should be built with quotes around it (at least that's the case for VB syntax) and called as a variable and not a string. Try the following: import ...


4

Try: def re_score(elev_t, contour): if elev_t.endswith('.5'): return "Midi" else: return contour and then: Countourtyp = re_score(!Elev_t!, !Contourtyp!)


4

An alternative solution may be to use a cursor: arcpy.UpdateCursor - (http://resources.arcgis.com/en/help/main/10.1/index.html#//018v00000064000000) Calculate Field is nice for in-application use (i.e. changing field values in ArcMap/Catalog or model builder, but cursors are much more powerful (and easier to use) when accessing attribute data in code. Try ...


4

Instead of: expression = str(fc[:5]) Try: expression = '"' + str(fc[:5]) + '"' Explanation: The contents of expression is evaluated by a second Python interpreter within the Calculate Field tool. Thus anything you want to be interpreted as a string literal needs to be enclosed with quotes.


4

When using Field Calculator in ArcPy, the code block needs to be defined within the arcpy.CalculateField_management function. Syntax: CalculateField_management (in_table, field, expression, {expression_type}, {code_block}) So, arcpy.CalculateField_management(out_fc_pm,'OSMI_ID',"calc_id('!POSTMILE!','!Front!')",'PYTHON_9.3',[yourcodeblock]) where [...


4

Based on your variable, you just need to make sure variables and strings are not confused field_1="!field_name1!" field_2="!field_name2!" arcpy.CalculateField_management("Layer", field_0, field_1 + " / " + field_2, "PYTHON_9.3") note that if you have the strings as variables without the "!", it is nicer to use format() field_1="field_name1" field_2="...


4

You need to pass the returned value in a variable, not reference the column itself. Expression: result Codeblock: if [ColumnB] > 0 then result = [ColumnA] / [ColumnB] else result = 0 end if Here's how the two parts fit together in the field calculator - my data doesn't have the same field names, but you get the idea.


4

As suggested, a possible answer is posted. It seems that arcgis-desktop can't call the raster calculator tool from within a python code, either with arcpy, or from python in model builder. Thus any call for raster calculator from a python code would end with an error. See attached link to ESRI support for thie error (#000539). As mentioned in ESRI support, ...


4

You want to reference the outputs of the Check Raster tool in your function definition, not the function name itself. Also from the help: In-line variable of type string should be enclosed within quotes ("%string variable%") in an expression. In-line variables of type numbers (double, long) do not require quotes (%double%). Try an expression like ...


4

You are trying to join a List.remove (returned from .split()), but a List.remove doesn't return anything, so you'd have to remove the item from the list and then join, or if you want to do it inline, I think this would work to exclude what you don't want: " & ".join(i for i in !IntersectAndEnds2.Streets!.split(" & ") if i <> !StreetSplit2....


4

You are missing two )) at the end


4

As mentioned in my comment above, adding triple quote marks around a string will allow you to use quote marks within the string """ your string that contains additional "double" and 'single' quotes should work too """ As you are wanting to include a value from your ID field, use python string formatting and have that add the value into your string. ...


4

In the CalculateField_management you are giving the desc.baseName as the expression parameter. It assumes the value of that variable is the name of a function that is not defined. This should work: arcpy.CalculateField_management(a, b, '"%s"' % desc.baseName)


3

Take the quotes completely off in the calculate field function: arcpy.CalculateField_management(fc, field, expression, "PYTHON") It's a variable, not a string. It stores the string you already set when doing expression = str(fc[:5]) See example 2 in the ArcGIS Help docs and you'll see how they set an expression to a variable and passes it to the ...


3

Whenever you are copying a code block to a Python snippet, the new line character \n is written instead as /n which is where you are getting your syntax error. It does the same thing on my machine, running 10.1 SP1. If you change all the forward slashes to backslashes, it should work. Another option would be to write the expression like so, as it's easier ...


3

I'm not certain I understand the problem, but I asked a question here previously about the syntax when using the Python Codeblock. The key misunderstanding I had was that you need to pass in your field names as arguments to the code block. Here is a small example: and the corresponding part of the attribute table: In your case, I think the easiest thing ...


Only top voted, non community-wiki answers of a minimum length are eligible