After updating a script from Python 2 to Python 3, I am now getting an 'ERROR 00539: Indentation Error: Unexpected indent <<expression>, line 1' on a line in my script. The line is not indented, and I tried removing all spaces and also re-adding spaces (ensuring no tabs were used). I am not sure where the error is. The line ran without error using Python 2.
This is the original line:
arcpy.CalculateField_management (SubLayer_pp_trans_GUJoin_UniqueSubs, "SUB1SUB2", ' [SUB_1] + "," + [SUB_2] ')
I've tried:
arcpy.CalculateField_management(SubLayer_pp_trans_GUJoin_UniqueSubs,"SUB1SUB2",' !SUB_1! +","+ !SUB_2! ')
and (and various renditions of removing spaces)
arcpy.CalculateField_management(SubLayer_pp_trans_GUJoin_UniqueSubs,"SUB1SUB2",' [SUB_1] + "," + [SUB_2] ')
with no luck. Any suggestions?
Thanks!
Solved! Go to Solution.
did you add "PYTHON_9.3" in order to use python... as in
arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON_9.3")
and I think the indentation may be the first space in your expression. In python ! marks replace [ and ] as field delimiters From the help topic for map and for Pro
Did you switch from ArcMap to Pro then?
I see that you are not passing an expression type, which means you are evaluating VB and not Python. Are you trying to work with VB or Python expressions?
The ArcGIS Pro Calculate Field—Data Management toolbox documentation has a note of caution about VB expressions:
Caution:
Field calculations with a VB Expression type are not supported on 64-bit products, including ArcGIS Pro, ArcGIS Desktop—Background Geoprocessing (64-bit)—and ArcGIS Server. To successfully use Calculate Field in these products, expressions should be converted to Python, or in the case of Background Geoprocessing (64-bit), background processing can alternatively be disabled.
I did switch from ArcMap to Pro. It sounds like Python expressions would be best. Makes sense. Thanks!
did you add "PYTHON_9.3" in order to use python... as in
arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON_9.3")
and I think the indentation may be the first space in your expression. In python ! marks replace [ and ] as field delimiters From the help topic for map and for Pro
This seemed to do the trick. Thanks!
arcpy.CalculateField_management(SubLayer_pp_trans_GUJoin_UniqueSubs, "SUB1SUB2",'!SUB_1! + "," + !SUB_2!', "PYTHON_9.3")
gardtayou should mark Dan's answer as correct. It shows others a solution was found and acknowledges Dan's help.
Agreed. For some reason, I do not have the 'Mark as Correct' option. I am viewing the discussion in All Places > Developers > GIS Developers > Python > Discussions in Chrome. I have also tried accessing it from both the email notification link and from my profile. I am logged in. I also referred to this document, and the button is not showing up on my discussion screen as shown.
...I don't remember the button not showing up for past discussions and have used it frequently in the past. Maybe I'm missing something. I apologize for any inconveniences.
Tess... that is because this isn't a 'question' but a 'discussion'.. only 'questions' have the 'correct answer' option. Discussions don't. Glad I could help in any event
Makes sense. I'll keep that in mind and will be sure to pay a bit more attention to where I am posting. Thanks again, and sorry about that!
So should I! I had not noticed this was a "discussion" instead of a "question". I think we can forgive each other as there appears to be almost no difference except for a small icon under your title.