Select to view content in your preferred language

XLS / CSV issues in a script

2706
10
11-22-2010 11:52 AM
NolanGeise
Deactivated User
I'm very new to Python and haven't had any classes yet so I'm feeling my way around so far. Also if I'm in the wrong forum, please let me know.

I have a script that I am trying to build using python that takes a CSV and creates a shapefile, saves it to a specific location then moves the CSV to a backup folder. Sounds easy right?

I'm calling up the table to point tool from the Military Analyst toolbox which works but the issue that I'm running into is the formatting of the CSV. I have a field called ID that I need to be a text field, and is a text field if I open the CSV in Excel, but when I open it in Arc, it's a Double field. The field data looks like this in excel (s001, s002, v1, v2, s003a, s003b) and like this in Arc (1, 2, 1, 2, NULL, NULL).

When I manually open the CSV in Excel and save it out as an XLS file, it looks fine in Arc but I'm trying to do all of this automatically. The analyst puts the CSV in a "drop box" folder then my script grabs it, makes the shapefile and moves the CSV. So I guess I'm thinking I need to know how to either:

A.) fix the formatting issue and use the current CSV file and then figure out how to move it

or

B.) figure out how to have the script open excel, save the file as an xls do the processing then create a CSV and put it in the backup folder.

Thoughts?
Tags (2)
0 Kudos
10 Replies
NolanGeise
Deactivated User
I'm sorry for the long delays between posts, I keep getting pulled away for other things while I'm trying to work on this. So am I anywhere close with this:

ftxt = 'c:/temp/test.csv'
fcsv = open(ftxt,'r')
creader = csv.reader(fcsv)
for lst in creader:
     insertRows = gp.insertcursor(new_shapefile)
     insertRow = insertRows.newrow()

Also, if I am inserting lines into a shapefile, should I just create a new shapefile or should I insert them into a table and then create a shapefile from that, and if I do, can I run a script say once a day while I am logged in, but away from my desk (after duty hours) without Arc being open but calling on tools in the toolbox?
0 Kudos