using (if namefield LIKE '% value%')

231
2
11-26-2019 04:52 AM
CarlosBustamante
New Contributor

I am calculating a field with arcpy, but I have not been able to obtain the expected results.

expression2="getClass(!DESCRIPCION!)"

codeblock2="""def getClass(DESCRIPCION):

    if '"DESCRIPCION" LIKE ' + "'%CODE%":
        return 1 """

arcpy.CalculateField_management(in_table=out_gdb +   "\Compilado\AccesoriosLineasMecanicas",
                                field="TIPO_EMPALME",
                                expression=expression2,
                                expression_type="PYTHON_9.3",
                                code_block=codeblock2)

for all records in the TIPO_EMPALME field the result is 1, I should do a filter for %CODE%

0 Kudos
2 Replies
JoshuaBixby
MVP Esteemed Contributor

You are setting the code block to Python but using SQL syntax, so it isn't a surprise the code isn't working.  Try using Python syntax, something along the lines of:

if 'CODE' in DESCRIPCION:
    return 1
JoshuaBixby
MVP Esteemed Contributor

Carlos Bustamante‌, still having issues?

0 Kudos