读取包含python中特殊字符的逗号分隔文本文件

时间:2012-12-23 19:01:26

标签: python csv

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()

收到错误,说“行包含NULL字节”!!

1 个答案:

答案 0 :(得分:0)

我的另一个猜测是open(phile, "rt")应该是open(phile, "rb")

您还可以通过以下方式调试(或之前)发生的行号:

for line_number, each in enumerate(lines):
    print line_number, each