2

This is what my program looks like right now:

def getdata(file_name):
    with open(file_name, errors='ignore') as f:
        rowdata = []
        reader = csv.reader(f)
        for row in reader:
            rowdata.append(row)
    return rowdata

I keep getting this error

for row in reader:

Error: line contains NUL
Anggari Ayu
  • 21
  • 1
  • 2

1 Answers1

-1

I am guessing you have a NULL value in the file. You can test that with

if '\0' in open('filename').read():
  print("you have null value in your file")
else:
  print("you don't")

if you do, replace null values with space.

reader = csv.reader(x.replace('\0', '') for x in filename)

then you can hopefully read file without error

Talha Ramzan
  • 120
  • 5
  • 1
    This is a feasible workaround if you know what you are doing, but blindly replacing invalid data with different invalid data just to remove the symptom is a horrible approach. – tripleee Mar 16 '21 at 06:48