0

I created a tool for a team, which worked perfectly. Once I started changing the directories of where things are saved it stopped working. I keep getting error 000732 for my code. I think it's because where the team are working, their folders have path names

Below are the first few lines of code, and where the error occurs

import arcpy, os, sys, datetime, xlrd, csv
from arcpy import env

env.workspace = r"S:\Acoustics\Projects\T3487.3 - C231 HS2 Phase 2b\10 Baseline Modelling\08 Datasets Input and Output Toolbox\Ronan_Test.mxd"
arcpy.env.overwriteOutput = True
pointfc = arcpy.GetParameter(0) # This is a point feature class
excel = arcpy.GetParameterAsText(1) #this is their excel sheet
outputloc = arcpy.GetParameterAsText(2) # this is a GDB to store results
Name = arcpy.GetParameterAsText(3) #String
Model_Run = arcpy.GetParameterAsText(4) #String
today = datetime.datetime.today().strftime('%y%m%d')

# This is to convert the excel into a CSV file that can be put through the tool
def csv_from_excel():
    wb = xlrd.open_workbook(excel)
    sh = wb.sheet_by_index(0)
    csv_temp = open('csv_temp.csv', 'w')
    wr = csv.writer(csv_temp, quoting=csv.QUOTE_ALL)
    for rownum in range(sh.nrows):
        wr.writerow(sh.row_values(rownum))
    csv_temp.close()

csv_from_excel()

excelscript = r"S:\Acoustics\Projects\T3487.3 - C231 HS2 Phase 2b\10 Baseline Modelling\08 Datasets Input and Output Toolbox\Ronan Scripts\csv_temp.csv"

# This is to copy to the points layer, to append the data from the excel sheet to it and save it out
arcpy.CopyRows_management(excelscript, r"S:\Acoustics\Projects\T3487.3 - C231 HS2 Phase 2b\10 Baseline Modelling\08 Datasets Input and Output Toolbox\Ronan Scripts\Testsheet")
pfc_temp = r"S:\Acoustics\Projects\T3487.3 - C231 HS2 Phase 2b\10 Baseline Modelling\08 Datasets Input and Output Toolbox\Ronan Scripts\Testsheet"
arcpy.FeatureClassToFeatureClass_conversion(pointfc, outputloc, "pfc_temp2")
pfc_temp2 = r"S:\Acoustics\Projects\T3487.3 - C231 HS2 Phase 2b\10 Baseline Modelling\08 Datasets Input and Output Toolbox\Ronan Scripts\pfc_temp2"
arcpy.JoinField_management(pfc_temp2, "al_id", pfc_temp, "al_id")

When working from my C drive with folders that have no spaces it works fine, but not with the new folders. The most common error I get is;

spaces in the path or file name are not supported for INFO tables or coverages.

Is there a work around? I'm not sure it's feasible for me to rename all the folders on other teams as it may mess up work they have going on in different areas.

1

First of all you have set your workspace to an MXD called Ronan_Test. A workspace is a folder or geodatabase. So firstly I suggest you read the help file so you understand what and how to use the workspace environment correctly.

The error is exactly what it is, you can't create an INFO table with the file paths you are using. Whoever allowed such path names to evolve clearly does not understand basic file management as you have spaces, hyphens, full stops at multiple levels, what a nightmare! Maybe they should be retrained?

I believe the source of problem stems from the CopyRows tool as you make a copy of the data what name are you using for your output table? It is Testsheet and there lies the issue, you have only called it Testsheet so ArcPy will create an ESRI INFO table because you have not ended it with any file extension such as .dbf for dBase format. dBase format has many limitations.

If you had set your workspace correctly, say to outputloc and set the CopyRows tool to be:

arcpy.CopyRows_management(excelscript, r"TestSheet")

then this would be creating a table in a file geodatabase, if your comments for parameter 2 are to believed and then this error will go away.

  • Thanks for your response and help so far. I've put in the edits you recommend, but now it's having an issue with the excelscript in the same line for CopyRows, with the same error – ronanemmet Feb 12 at 10:31
  • Your excelscript is a silly and misleading name, it is a CSV file. Suggest you do away with your CSV file and function call to create it and simply use the Excel to Table tool. Search Help file for that to understand it's syntax. – Hornbydd Feb 12 at 12:11
  • thanks hornbydd for everything – ronanemmet Feb 12 at 13:17
1

When I run this code snippet (that I pulled from the code that you have presented) it appears that having a space in the pathname does not cause it to fail:

import arcpy
pointfc = r"C:\Temp space\TestProject\TestProject.gdb\pointfc"
outputCSV = r"C:\Temp space\test.csv"
arcpy.CopyRows_management(pointfc,outputCSV)

When I run this code it works too (the folder was renamed and the test.csv deleted in between):

import arcpy
pointfc = r"C:\Temp.space\TestProject\TestProject.gdb\pointfc"
outputCSV = r"C:\Temp.space\test.csv"
arcpy.CopyRows_management(pointfc,outputCSV)

When I run this code it works too (the folder was renamed and the test.csv deleted in between):

import arcpy
pointfc = r"C:\Temp-space\TestProject\TestProject.gdb\pointfc"
outputCSV = r"C:\Temp-space\test.csv"
arcpy.CopyRows_management(pointfc,outputCSV)

I ran these tests using ArcGIS Pro 2.3.0 so it looks like, at least at that version, it is possible to use a space, period or hyphen within the pathname of the input to CopyRows_management().

If you write some tests very similar to the above but using one of your full failing pathnames and variants of them then you should be able to determine whether the pathname is the problem, and if so what within it causes your code to break.

The above notwithstanding I agree wholeheartedly with @hornbydd saying that the pathnames you are working with are likely to cause problems.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.