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? Commented 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 Commented Aug 18, 2015 at 20:00
  • Yes Brad , I already did Commented Aug 18, 2015 at 20:00
  • @Paul , can you please let me know what do you mean by codeblock? Commented Aug 18, 2015 at 20:01
  • 1
    Ok, so if that is your code block then the expression should look like foo(!MamerMN!) Commented 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! )

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.