Writing Results to Existing Specific CSV Column

740
6
Jump to solution
11-01-2018 02:05 PM
AdamThompson3
New Contributor III

Hey Everyone,

Running into a bit of a problem that I am not sure how to resolve after researching for awhile, What I would like to do is write my results from a search cursor to an existing column in a csv file. 

So currently this is the code I have;

The first portion of my code works exactly how I want it too, and prints how I would like it to be displayed in the csv file. Now what I would like to do is take those values and write them to an existing Field in my CSV called "Play", I am not sure how to go about this. This is what I have gotten so far for my results..

The highlighted portion is what I want to write to the specific column "Play" in my csv, I can read the file and find out the column position is row[0] but cant write to it.

Any help is appreciated!

0 Kudos
1 Solution

Accepted Solutions
AdamThompson3
New Contributor III

I took a read through it all, was quite a lot of information to take in but I ended up getting it to work with just one hiccup, 

My data that is put into that column contains a space between each one, as seen below;

not sure why.. but other then that it works!

Here is the code

View solution in original post

0 Kudos
6 Replies
DarrenWiens2
MVP Honored Contributor

You need a writer to write. Check the example here: 13.1. csv — CSV File Reading and Writing — Python 2.7.15 documentation 

AdamThompson3
New Contributor III

I took a read through it all, was quite a lot of information to take in but I ended up getting it to work with just one hiccup, 

My data that is put into that column contains a space between each one, as seen below;

not sure why.. but other then that it works!

Here is the code

0 Kudos
DarrenWiens2
MVP Honored Contributor

Weird, do you see anything funny (newline character) if you open it in a simple text editor?

0 Kudos
AdamThompson3
New Contributor III

No when I open it with just notepad it looks correct, 

Although NotePad ++ gives me the same as the excel as well

very weird indeed! Anyways thank you for the link to the CSV Writer info though, that was very helpful.

0 Kudos
DarrenWiens2
MVP Honored Contributor

Oh, try using 'wb' mode rather than 'w' with Python 2 on Windows.

AdamThompson3
New Contributor III

Yup that did it! 

0 Kudos