2

I want to read from my numbers-sheet some data. The first row is a "title" row, containing names of each column, and every other row contains data. I wrote a simple program in python to read this, however every time when I run this code I get:

File "dataReader.py", line 11, in <module>
    for row in fileReader:
_csv.Error: line contains NULL byte

I was trying to encode each line, but it doesn't helped. Below I past my code (in this one I am not calling the utf_8_encoder function, but even if I try to use it - I still have errors). I want to read row by row from my file, and read it as a string. How can I do that?

import csv
import codecs

def utf_8_encoder(unicode_csv_data):
    for line in unicode_csv_data:
        yield line.encode('utf-8')

if __name__ == "__main__":
    dataFile = open("file.numbers", 'rU')
    fileReader = csv.reader(dataFile)
    for row in fileReader:
        print row 

Here is also a sample of my file: enter image description here

4
  • Perhaps try using fileReader = csv.reader(x.replace('\0', '') for x in dataFile) Commented Apr 17, 2015 at 23:08
  • May be open file in binary mode (rb instead of rU)? Commented Apr 18, 2015 at 0:08
  • How did you create the data file? More specifically, did you save it as a CSV file? Commented Apr 18, 2015 at 6:26
  • @Robᵩ Us you can see, the file is saved as .numbers, not .csv Commented Apr 18, 2015 at 9:35

1 Answer 1

2

You have saved the file as a .numbers file, not as a CSV file. The csv module is used to read CSV (comma-separated value) files, and cannot interpret a .numbers file.

To make your program work, save your data as a CSV file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.