Hi,
Is there any practical way to convert scripts from arcmap to arcgis pro?
I need to convert several scripts, and for example this snippet I'm having a lot of problems.
arcpy.CalculateField_management("temp_informe_Layer", "EST_SUBREP", "" + anoAtual + " - Right( [PLANTIO],4 )", "VB", "")
would anyone know help me with the correct syntax for Arcgis PRO?
Thank´s
Solved! Go to Solution.
The issue you may be running into is that VB doesn't care about data type, if you throw a string function at it, it will use a string rep of the value. For example, you can add "1" and "1" and get 2. In Python you need to convert data types yourself, so, assuming your PLANTIO is a date field, you may be able to get what you want like this:
expr = 'float(' & str(anuAtual) & ') - float(time.strftime(!PLANTIO!,"%Y"))'
# at runtime, expr will be something like:
# float(1999) - float(time.strftime(!PLANTIO!,"%Y"))
arcpy.CalculateField_management("temp_informe_Layer", "EST_SUBREP",
expr, "PYTHON")
More on handling dates in Calculate Field in the help!
Thank´s,
Thank you very much for your suggestion. It's a great option too!
For some reason this popped up in my email so I thought I'd add that using string formatting is easier to understand and debug. This is especially true if your expression is complex.
For example:
expr = 'float({}) - float(time.strftime(!PLANTIO!,"%Y"))'.format(anuAtual)
# at runtime, expr will be something like:
# float(1999) - float(time.strftime(!PLANTIO!,"%Y"))
arcpy.CalculateField_management("temp_informe_Layer", "EST_SUBREP",
expr, "PYTHON")