引号字段内的CSV换行符和qoute

时间:2013-11-27 13:36:40

标签: python csv

我在csv.reader中尝试了很多选项,但它没有用。我是python的新手并且几乎尝试了所有参数,我的csv文件中的单个凌乱的消息看起来像这样

"Hey Hi

how are you all,I stuck into this problem,i have tried with such parameter but exceeding the existing number of records,in short file is not getting read properly.
\"I have tried with 
datareader=csv.reader(csvfile,quotechar='"',lineterminator='\n\n\n\r\r',quoting=csv.QUOTE_ALL)

Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode? \"......... hence the problem continue.

"

正如预期的那样,由于 \“ \ n 消息获取更多记录或记录中断,我尝试使用不同的行终止符以及您可以看到在消息中但没有成功,这是我现在的代码..

with open("D:/Python/mssg5.csv", "r") as csvfile:
        datareader = csv.reader(csvfile,quotechar='"' ,lineterminator='\n',quoting=csv.QUOTE_ALL)
        count = 0
    #csv_out = open('D:/Python/mycsv.csv', 'wb')
    #mywriter = csv.writer(csv_out)
        for row in datareader:
            count = count + 1
            print "COUNT is :%d" % count

任何形式的帮助,谢谢。

1 个答案:

答案 0 :(得分:1)

在csv文件中尝试的几件事

  1. 将凌乱的字符串放入引号“”“字符串”“”
  2. 在凌乱字段中每行的末尾使用continue char \