I am creating a text/csv file (using a python script). The file contains data to import into ArcMap. I have several fields that look like numbers but have leading zeros ("0012") etc. that I want to preserve. I thought I could force this on ArcMap by adding a dummy line at the beginning of the file that has obvious text in it (like an "X").
In the screenshot below, I have an X in several of the fields at the beginning (including ACCTID in the first column) for the file but ArcMap has made them into integers anyway. To clarify, I'm just trying to add the file into ArcMap directly using "Add Data".
Excel seems to treat them similarly. I do not want to open this in Excel and fiddle with the formatting of over 100 fields if I can avoid it and it seems preposterous that I would have to do that. I found similar questions but nothing exactly like this. Some folks had the reverse issue (wanting numbers and getting text) and others were working with Excel files rather than plain text.
The code I'm using to write the CSV (if that matters) looks like this ...
with open(filehandle, 'wb') as csvfile:
data_writer = csv.writer(csvfile, delimiter = ",")
if printHeaders:
csvfile.write(', '.join(these_headers) + '\n')
if dummy:
csvfile.write(dummy + '\n')
further down I have ...
if linecount < linelimit and printline:
data_writer.writerow(theDict[acct])
linecount += 1
I am actually running a search cursor through this file to use to run against an update cursor using a key (the ACCTID).