Using this page as my resource: ArcGIS Help (10.2, 10.2.1, and 10.2.2)
I came up with this:
import arcpy
from arcpy import env
env.workspace = "C:\"
inTable = "c:\test.csv"
outLocation = "c:\test.dbf"
outTable = "test"
arcpy.TableToTable_conversion(inTable, outLocation, outTable)
However, it's failing:
Traceback (most recent call last):
File "c:\test.py", line 4, in <module>
arcpy.TableToTable_conversion("c:\test.csv", "c:\test.dbf", "test")
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\conversion.py", line 1904, in TableToTable
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Rows: Dataset c:\test.csv does not exist or is not supported
ERROR 000732: Output Location: Dataset c:\test.dbf does not exist or is not supported
Failed to execute (TableToTable).
Is it clear where I'm going wrong?
Solved! Go to Solution.
Your paths are wrong, for Python. '\t' happens to mean tab. You can get around it by always prefacing paths with an 'r' to denote raw string format.
For example:
inTable = r"c:\test.csv"
Your paths are wrong, for Python. '\t' happens to mean tab. You can get around it by always prefacing paths with an 'r' to denote raw string format.
For example:
inTable = r"c:\test.csv"
Thank you. I got it working. I had a few things wrong.
Here is my new WORKING code:
import arcpy
from arcpy import env
env.workspace = r"C:\test"
inTable = r"C:\test\test.csv"
outLocation = r"C:\test\output"
outTable = "test.dbf"
arcpy.TableToTable_conversion(inTable, outLocation, outTable)
Can't you also use double backslash in place of the regular backslash in order to make the path correct?
inTable = "c:\\test.csv"
Adrian Welsh wrote: Can't you also use double backslash in place of the regular backslash in order to make the path correct?
inTable = "c:\\test.csv"
Yes. And forward slashes work as well:
inTable = "c:/test.csv"
I was going to mention that too! You beat me to it!
Yes, but double backslashes are more typing. As Luke points out, you can also use forward slash, but then you need to remember whether it's forward or backslashes you can't use. It's personal preference, but I use 'r'.
I tend to use r'' as well. Except when it doesn't work.
Good to know. I can't say I've ever run into that situation (e.g. r'\'), but the lengthy and pointed discussion certainly makes me think it comes up more often than my brief experience.
It's not just r'\', but any trailing backslash, i.e r'C:\'