Hello people,
I cam across an error,
AttributeError: ValueObject: Get attribute __class__ does not exist
when I run the script tool, I will get the error for the line, "df = pd.read_excel(spreadsheet)"
This simple code to read the spreadsheet has not problem in Python IDE but it will fail with the error in script tool.
As I have not figure out the error message, any advice is much appreciated.
Thanks in advance for your help!
Solved! Go to Solution.
if you are providing the path, did you try
spreadsheet = arcpy.GetParameterAsText(0)
Have you specified the full path to "spreadsheet".
perhaps the script tool hasn't specified the workspace/folder where it is to be found
Thanks for our reply!
I am having this problem when running script tool on ArcGIS Pro. The full path is to be defined via the tool with parameter setting as below.
And the code for the script tool is simple as below.
import pandas as pd
import arcpy
def ScriptTool(spreadsheet):
arcpy.AddMessage('Start')
df = pd.read_excel(spreadsheet)
name_values = df["Name"].unique()
query = "Name IN {}".format(tuple(name_values))
arcpy.AddMessage(query)
if __name__ == '__main__':
spreadsheet = arcpy.GetParameter(0)
ScriptTool(spreadsheet)
I'm new to Arcpy, but from scripting point of view, I can suggest you to put a print statement after this line
spreadsheet = arcpy.GetParameter(0)
to print(spreadsheet) and double check what you are passing to pandas.read_excel(). This should be either a str or path object, maybe arcpy.GetParameter(0) is not returning what you expect.
Thanks Mahgi_Ch for your reply!
It was a just my careless mistake in the code.
if you are providing the path, did you try
spreadsheet = arcpy.GetParameterAsText(0)
Thanks Dan for pointing out!
That was my careless mistake, I excluded AsText somehow - it works now.
Apart from that, I have a question. A code using GetParameter(0) works in both Python window and Python IDE. But this does not work it the code is embedded in a Script tool. Do you know why this occurs?
I am not sure, I use custom toolboxes rather than python toolboxes, so I can specify my parameter types there and I always use GetParameterAsText and let arcpy's behind the scenes handle any stuff from arcobjects conversions
I see, thanks Dan!