So I am trying to put the result of a query in a string. Let’s say row by row (I don’t need all the fields by the way), but that’s not the point. I am using python against a sqlite db.
the problem is that when some of the fields are null, python will write None instead of “” or some blank neutral thing.
example:
t = "%s %s %s %s" % (field[1],field[2],field[3],field[4])
If field[3] is null for instance, t will be something like
"string1 string2 None string4"
instead of
"string1 string2 string4"
yes I would need to remove also the double space in case. I cannot just replace “None” with “” because some string might contain itself “None” since it is a common word. Of course I don’t have only 4 field, they are a lot, and I am not trying to import every field of the row, only specific ones. I need a fast and easy way to fix this behavior. I cannot manually check if each field is None, that’s insane. I cannot use
str.strip(field[i])
because when the field is None I get an error.
what could be a good approach?
There is the str.replace option if “None ” is unique to NULL fields:
Or you can pre-filter the strings: