I have a CSV file in my toolbox folder. I would like to import the CSV file into my arcpy script to run in conjunction with my arcpy script.
Folder structure:
- src
- data
- my_csv.csv
- mytoolbox.pyt
- data
How would I import the my_csv.csv into the mytoolbox.pyt?
I receive an error when I try running through ArcGIS Pro GUI.:
FileNotFoundError: [Errno 2] No such file or directory: ../data/my_csv.csv
code:
def execute(self, parameters, messages):
"""The source code of the tool."""
# Open layer and process!!
arcpy.AddMessage(os.getcwd()) # output is AppData folder for windows
df_cat_codes = pd.read_csv("../data/my_csv.csv")
arcpy.AddMessage("CSV shape: ", df_cat_codes.shape)
return
I am using the template from: https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/a-template-for-python-toolboxes.htm
os.path
to manipulate paths.__file__
points to (I'm not sure in the case of a *.pyt)data/my_csv.csv
? According to your bullet points, mytoolbox.pyt and data are at the same level.