(This question is related to this one)
I am reading parsing csv content, which has been previously loaded into memory:
def ReadTxtIntoColumns(txt, columns):
rows = []
print txt
print txt.find('\x00')
print txt.count('\x00')
f = StringIO(txt)
try:
reader = csv.reader(f, delimiter=' ', skipinitialspace=True)
for row in reader:
# Merge all extra columns
if len(row) >= columns:
rest = ' '.join(row[columns-1:])
del row[columns-1:]
row.append(rest)
# And now set missing columns to None
for i in range (len (row), columns):
row.append(None)
rows.append(row)
except csv.Error, e:
log.error('ReadTxtIntoColumns > Problems reading csv from string > line %d: %s', reader.line_num, e)
finally:
f.close()
return rows
The input data has been hand-written by me (a simple textfile, space separated). There is no '\x00' at all in my input data, but csv complains about it:
ReadTxtIntoColumns > Problems reading csv from string > line 1: line contains NULL byte
What does the error message mean then?
EDIT
This is my simplified input data, which I have verified is still causing the same problem:
#COMMAND USER DIRECTORY SAFE COMMAND
uname - - FALSE uname -a
sleep - - FALSE sleep 100