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

得到错误说“行包含空字节”!

4

1 回答 1

0

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

您还可以通过执行以下操作来调试发生在(或之前)的行号:

for line_number, each in enumerate(lines):
    print line_number, each
于 2012-12-23T19:29:53.637 回答