I'm new to Python but am working with a very simple script to convert elevation units from meters to feet. It works in the Python window but not as a script tool. Below is my script.
import arcpy
arcpy.env.workspace = "C:\Users\keyesge\Desktop"
inputShp = "JunctionElev"
fieldName = "RASTERVALU"
expression = "!RASTERVALU! * 3.28084"
arcpy.CalculateField_management(inputShp, fieldName, expression,"PYTHON")
Any input is appreciated.
pth = "C:\Users\keyesge\Desktop"
File "<ipython-input-1-507cf8adcb68>", line 1
pth = "C:\Users\keyesge\Desktop"
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
# ---- use raw encoding
pth = r"C:\Users\keyesge\Desktop" # ---- a little r goes a long way
This is error I got when I tried your path... I would start there
Do you mean it to work as a functioning tool with different data inputs?
You need to replace your hard coded stuff with parameters
Different data inputs?
Do you plan to use the tool on different tables and field names or is it just to constantly update the one table?
If that's the case, just change the path as Dan Patterson has written out for you.
Yes different tables.
For future reference, it is always helpful to post the error message and traceback so GeoNet users have something specific to look at in terms of what is going wrong.
I didn't receive an error message... The field I was trying to update wasn't reflecting my script. The script tool gave me a message that the tool was successful, but nothing changed in the table...
As Dan indicates:
arcpy.env.workspace = "C:\Users\keyesge\Desktop"
should be:
arcpy.env.workspaces = r'C:\Users\keyesge\Desktop'
Using single or double quotes is just a matter of personal style/preference.
Just a typo for workspace at the end Joe.