Writing "None" to a file in python

Viewed 7007

I have a txt file that contains rows of JSON objects. I'm parsing this file in Python, and I'm writing a file that every row in it will be a record (Comma separated) I've built from the JSON object.

Now, when I'm building this file - some of the values can be Null (or None in Python). So this is what I write:

a = 'abc'
b = None
str = a + "," + b
file.write(str+\n)

But I keep getting this error: TypeError: coercing to Unicode: need string or buffer, NoneType found

So my question is - How can I write "Null" values into the file, in a string, so when I load the file into the table - the value in that position will actually be Null? How can I keep this value in a file?

Thank you!

2 Answers
Related