Python doesn't work in field calculator

210
1
Jump to solution
12-26-2021 02:36 PM
RicardoSanabria1
New Contributor II

Merry Christmas to everyone,

I'm trying this code in field calculator tool but something is wrong with python. It seems that doesn't validate the code, doesn't recognize the len and replace function as reserved words. And, when I tries to execute the tool it shows an error "2 parameters are missing or invalid".

RicardoSanabria1_0-1640558151880.png

I tried restarting the laptop, but it doesn't work.

 

Best regards,

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

your code block has to be a "def" as in the help topics

Examples of using Calculate Value—ArcGIS Pro | Documentation

modify the example to suit

txt = "a, b, c, d"

def func(val):
    """replace"""
    return len(val) - len(val.replace(",", ""))
    

func(txt)
3

 


... sort of retired...

View solution in original post

1 Reply
DanPatterson
MVP Esteemed Contributor

your code block has to be a "def" as in the help topics

Examples of using Calculate Value—ArcGIS Pro | Documentation

modify the example to suit

txt = "a, b, c, d"

def func(val):
    """replace"""
    return len(val) - len(val.replace(",", ""))
    

func(txt)
3

 


... sort of retired...