Select to view content in your preferred language

Calculate field python coding problems

457
2
12-09-2020 07:38 PM
AnastasiaStats
New Contributor

Hello All,

I have included my code as it is now. I am using python in calculate field to try to categorize some data. It tells me the expression is undefined. Please put this in the simplest terms this is my first time coding and I can't move on in the project until I nail this. 

 

Screenshot (33).png

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

This makes it easier on people trying to help...

Code formatting ... the Community Version - GeoNet, The Esri Community

I can't get past your first line since the mxd path name isn't "raw encoded"

See the example... the "r" in front of the path name is required if you are using backslashes in filenames.

mxd = r"C:\Users\Books\Documents"

mxd = "C:\Users\Books\Documents"
  File "<ipython-input-278-7b950ad9b491>", line 1
    mxd = "C:\Users\Books\Documents"
         ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

 


... sort of retired...
JoshuaBixby
MVP Esteemed Contributor

Once you get past the file path issue Dan points out, your next issue is that Calculate Field doesn't operate on an MXD file.  It would be good to review Calculate Field—Help | Documentation (arcgis.com)