Below I attach the updated script and the error message. I also changed 'float' to 'short' in expression line, because my attribute is saved as short, but it did not change anything.
# Import system modules
import arcpy
# Set environment settings
arcpy.env.workspace = "E:/CLC_data"
# Set local variables
inFeatures = "CLC"
fieldName = "NEW_code"
#fieldPrecision = 9
#fieldAlias = "refcode"
fieldLength = 50
# Execute AddField for new fields
arcpy.AddField_management(inFeatures, fieldName, "TEXT", field_length=fieldLength)
# Set local variables
inTable = "CLC"
expression = "getClass(short(!CLC1!))"
#Create NEW_code for CLC1
codeblock = """
def getClass(CLC1):
if (CLC1 == 1):
return 'A_1'
elif (CLC1 == 2):
return 'A_2'
elif (CLC1 == 3):
return 'A_3'
else:
return 'error'"""
# Execute CalculateField
arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON3",
codeblock)
Runtime error Traceback (most recent call last): File "<string>", line 3, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 3183, in CalculateField raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000800: The value is not a member of VB | PYTHON | PYTHON_9.3. Failed to execute (CalculateField).
>>>