2
import csv,sys

phile="E:/Users/san/Documents/phonebook.txt"
ph=open(phile,"rt")
try:
    lines= csv.reader(ph)


    for each in lines:
        print each,
except Exception as er:
       print er
finally: ph.close()

getting error saying that " line contains NULL byte" !!

Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197
  • 4
    If you post a sample line from the .txt file that is causing the problem, that would be helpful. – oathead Dec 23 '12 at 19:03
  • wish i could but this is all the error i get and its a phonebook exported from my phone in text format.. – Ciasto piekarz Dec 23 '12 at 19:05
  • i guess it was the first line of text file , i saved it as ansi and it printed well except the first line conatains this text "" which i guess is thecause but i do not see it when i open the file in notepad – Ciasto piekarz Dec 23 '12 at 19:11
  • Take a look at this [post](http://stackoverflow.com/questions/4166070/python-csv-error-line-contains-null-byte) , it sounds like the same problem. – oathead Dec 23 '12 at 19:16

1 Answers1

0

My other guess is that the open(phile, "rt") should just be open(phile, "rb").

You can also debug which line number this happens on (or one before) by doing this:

for line_number, each in enumerate(lines):
    print line_number, each
gak
  • 32,061
  • 28
  • 119
  • 154