Q:

"Dataset xxx does not exist or is not supported" using Table to Domain in Python

I have a directory of hundreds of *.csv files, containing code/description pairs for geodatabase domains. I'm trying to automate the creation of these domains using Python.

If I manually run the Table to Domain tool using a *.csv file in
ArcToolbox, the domain is correctly created
If I create a Model using the Table to Domain tool, hard-coding in the input file (and
all other parameters) then export this to a Python script, the
domain is correctly created when I run the Python script
If I try to iterate through all *.csv files in the directory, running the Table
to Domain tool for each file, I get the ""Dataset xxx does not exist
or is not supported" error message:

Failed to execute. Parameters are not valid.ERROR 000732: Input Table:
  Dataset C:\temp\01-01.csv does not exist or is not supported ERROR
  000308: Invalid field type Failed to execute (TableToDomain).

I suspect the problem is due to the path not being correct for the *.csv file, but I can't work out how to get it working. os.path.exists shows that the file does exist, so it may be an internal ArcGIS thing.
Note that the *.csv file does work correctly via ArcToolbox and the hard-coded Python script, so it's unlikely that the field type really is invalid.

A:

The problem was that the file was still open in Python while I was trying to use it in ArcGIS. The answer is to close the file in Python once it's been read in:
 f = open(file, 'r')
 header = f.readline().split(",")
 f.close()

There is arguably poor wording on the error message - it's not that the file doesn't exist, but that it was locked.

