1

I have tried all of below snippets to use Python Parser in Field Calculator and update the values of a field called type based on a filed called MamerMN but in all of them I am getting Syntax error in Geoprocessing result window!

if !MamerMN! <= 0.151560:
    return 1

and

if (!MamerMN! <= 0.151560):
    return 1

and

if (MamerMN <= 0.151560):
    return 1

and

def(MamerMN)
if MamerMN <= 0.151560:
    return 1

and

def(MamerMN)
if (MamerMN <= 0.151560):
    return 1

Can you please let me know what I am doing wrong?

Update

def foo(MamerMN):
  if MamerMN <= 0.151560:
     return 1
9
  • did you push the python radio button?
    – Brad Nesom
    Aug 18, 2015 at 19:59
  • Are you placing this in the codeblock? You need to make sure you're using proper indentation as well. The last two are not proper python syntax either. it should be def foo(bar): return bar**bar
    – Paul
    Aug 18, 2015 at 20:00
  • Yes Brad , I already did
    – Suffii
    Aug 18, 2015 at 20:00
  • @Paul , can you please let me know what do you mean by codeblock?
    – Suffii
    Aug 18, 2015 at 20:01
  • 1
    Ok, so if that is your code block then the expression should look like foo(!MamerMN!)
    – Paul
    Aug 18, 2015 at 20:14

1 Answer 1

2

Thanks to Paul

Here is the solution: in Pre-logic Script Code Box:

def foo(MamerMN): 
  if (MamerMN <= 0.200000): 
     return 1
  elif (MamerMN >= 0.200001 and  MamerMN <= 0.400000):
     return 2
  elif (MamerMN >= 0.400001 and  MamerMN <= 0.600000):
     return 3
  elif (MamerMN >= 0.600001 and  MamerMN <= 0.800000):
     return 4
  elif (MamerMN >= 0.800001):
     return 5

and in Expression box

foo( !MamerMN! )

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