arcpy.TableToTable_conversion CSV to DBF help

5485
12
Jump to solution
02-03-2016 01:19 PM
DannyLackey
New Contributor II

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?

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor

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"

View solution in original post

12 Replies
DarrenWiens2
MVP Honored Contributor

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"

DannyLackey
New Contributor II

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)

0 Kudos
AdrianWelsh
MVP Honored Contributor

Can't you also use double backslash in place of the regular backslash in order to make the path correct?

inTable = "c:\\test.csv"

0 Kudos
Luke_Pinner
MVP Regular Contributor
Adrian Welsh wrote:

Can't you also use double backslash in place of the regular backslash in order to make the path correct?
  1. inTable = "c:\\test.csv" 
inTable = "c:\\test.csv" 

Yes. And forward slashes work as well:

inTable = "c:/test.csv"  
AdrianWelsh
MVP Honored Contributor

I was going to mention that too! You beat me to it!

0 Kudos
DarrenWiens2
MVP Honored Contributor

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'.

0 Kudos
Luke_Pinner
MVP Regular Contributor

I tend to use r'' as well. Except when it doesn't work.

DarrenWiens2
MVP Honored Contributor

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.

0 Kudos
Luke_Pinner
MVP Regular Contributor

It's not just r'\', but any trailing backslash, i.e r'C:\'

0 Kudos