# CSV wriitng blank fields

**URL:** <https://forum.inductiveautomation.com/t/csv-wriitng-blank-fields/19833>\
**Category:** Ignition\
**Created:** [September 26, 2018, 12:35pm UTC](https://forum.inductiveautomation.com/t/csv-wriitng-blank-fields/19833 "2018-09-26T12:35:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [September 26, 2018, 12:35pm UTC](https://forum.inductiveautomation.com/t/csv-wriitng-blank-fields/19833/1 "2018-09-26T12:35:14Z")

</div>

I’m writing a CSV file and need some blank fields inserted.

```auto
try:
		fo = open(filepathw, "a") 
		fw = csv.writer(fo, delimiter=';')#, quotechar=' ', quoting=csv.QUOTE_MINIMAL)
		fw.writerow([wid, wksn, wksnbar, wktn, wktnbar, wI, wr, wcode, wncode, wprofile,])
		
	
		fo.close()
	
	except Exception,e:

```

What I need is e.g.: fw.writerow([wid, wksn, wksnbar, “;;;;;;” wktn, wktnbar, wI, wr, “;;;” wcode, wncode, wprofile,])

However when the CSV is written the quotes are included. The rest of the data, wksn etc, comes from a scalarPrepQuery, so I tried having a static column in SQL with a semi-colon in it, but it still gets quote marks. As you can see from the commented out section I tried adding quoting style, no joy.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [September 26, 2018, 3:09pm UTC](https://forum.inductiveautomation.com/t/csv-wriitng-blank-fields/19833/2 "2018-09-26T15:09:07Z")

</div>

And to tag another problem onto this thread, if I save the file as .txt all the lines appear one after the other with no blank rows. If I rename as CSV and open in excel, every other row is blank :S

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 26, 2018, 3:43pm UTC](https://forum.inductiveautomation.com/t/csv-wriitng-blank-fields/19833/3 "2018-09-26T15:43:14Z")

</div>

Try adding `[None]` in the list you’re sending to writerow, eg:  
`fw.writerow([wid, wksn, wksnbar, None, None, None, None, None, wktn, wktnbar, wI, wr, None, None, None, wcode, wncode, wprofile])`

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [September 26, 2018, 5:29pm UTC](https://forum.inductiveautomation.com/t/csv-wriitng-blank-fields/19833/4 "2018-09-26T17:29:56Z")

</div>

Thanks, I’ll give that a go tomorrow. The blank row thing is a show stopper as the machine that then reads the CSV see’s it as a null entry and can’t handle it. Perhaps if I explicitly write is as a CSV, not a TXT?

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [September 27, 2018, 7:23am UTC](https://forum.inductiveautomation.com/t/csv-wriitng-blank-fields/19833/5 "2018-09-27T07:23:55Z")

</div>

OK great, the ‘None’ method works… and as for the blank rows, fo = open(filepathw, “ab”) was the solution… thanks!

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [September 27, 2018, 8:41pm UTC](https://forum.inductiveautomation.com/t/csv-wriitng-blank-fields/19833/6 "2018-09-27T20:41:54Z")

</div>

OK, so I’d actually ran into the quote issue before, with the header row. Having it as 1 field in the db static which I call at the start of each write, I was getting quotes around it.

So I gave up after a while of google’whacking and created a template.txt file with the header and had code to copy and rename that for every file, not very elegant. And, even with “ab” append binary, there was a blank row between the header row and the first row of proper data. I guess a way around it, which I’ll try tomorrow, is to have 32 static fields in its own table, each with the header value, that I call once at the file create stage.

But I’d like to know why this is?

When I output the file as CSV, open it in notepad, the quotes are there. When I then open it in Excel, the quotes aren’t there, and when I close the file it asks if I want to save it, which then removes the quotes permanently.

Any insight?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 27, 2018, 8:51pm UTC](https://forum.inductiveautomation.com/t/csv-wriitng-blank-fields/19833/7 "2018-09-27T20:51:49Z")

</div>

Setting the quoting to quote minimal or off entirely definitely _should_ work - I’ve never noticed issues with it before. As for the Notepad vs Excel - that’s just Excel being “helpful” and manipulating the data for you. The `csv` module is even supposed to default to an Excel friendly format, so I’m honestly not sure what’s going on. Can you post what a row of your data looks like in the DB?

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [September 27, 2018, 9:08pm UTC](https://forum.inductiveautomation.com/t/csv-wriitng-blank-fields/19833/8 "2018-09-27T21:08:25Z")

</div>

Yes, I’ll post tomorrow. I’ll try my hack-around first (static separate table with 32 columns) as, based on the fact the other data is coming from scalar-prep query’s and works, I think it will work. Just not too elegant.

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [September 28, 2018, 12:00am UTC](https://forum.inductiveautomation.com/t/csv-wriitng-blank-fields/19833/9 "2018-09-28T00:00:11Z")

</div>

Well seeing as it’s kinda tomorrow (past midnight)… I remembered I have a file on USB pen drive at home. OK,[test6.csv](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/9c9033adbfed78f88bbbf0e8a66b20dab296b246.csv) (4.8 KB)  
you asked for the raw DB end but might give some clues…

Edit; so yeah the hack-around works…

here’s the table screenshot:  
(all field datatypes, barr index and off\_fk, are ‘varchar’)

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/2/2f747af0500f19366f1ea65fbe46f650c50150c5.png)
