New answers tagged

3

Field Calculator and python interpreter are different tools. The former post-process what you introduce as expression and should not be treated "strictly" as a python interpreter. The error message says once processed, Field Calculator tool treats your code's + "\\" + as a code line continuation character (i.e., , for more details have ...


0

I could easily be wrong on this one and what you're trying be valid, but I've only ever seen examples for or personally used a calculate field expression that is a single string. As I understand it, the string provided here is passed in and then parsed, so it can contain strings itself as long as you use single quote for the outer and double for strings ...


1

You can use !Var2!.replace('<problem char>', '<replacement string>')in your calculation to modify the value held in Var2 as needed.


3

What you are seeing is due to the fact that and takes precedence over or. a and b or c is the same as (a and b) or c and not a and (b or c), as you assumed. As mentioned in the other answer, you can use parentheses to change the precedence (because parentheses have a higher precedence than either of and and or), or even better, use in. You can also turn your ...


2

This works for me def format_address(address_string): # Declare variables hn ="" ha ="" # Separate the address string into parts address_string = address_string.split() # Traverse through the address parts for add in address_string: if add.isnumeric(): hn += add else: ha += ...


4

Logical operator precedence and order of operators is causing your issue. Try grouping your ors in parentheses: e.g. Wrong: def Reclass(gridcode, CWHR_TYPE): if gridcode == 1 and CWHR_TYPE == "Annual Grassland" or CWHR_TYPE == "AGS" or CWHR_TYPE == "Perennial Grassland": return "Avena Grassland" elif gridcode ==...


4

Maybe there are easier ways, but here's one using Python. In the Field Calculator window, select the Python parser Check Show Codeblock The Pre-logic Script code defines a method that returns only values greater than 0. def greater_than_0 (value): return value > 0 The code for the MIN field is min (filter (greater_than_0, [ !FromLeft!, !FromRight!,...


Top 50 recent answers are included