Python CSV编写器截断字符串

时间:2015-04-08 00:23:32

标签: python csv truncate

我有将列表列表写入CSV文件的脚本。除一个问题外,工作正常:数据中的某个列总是被截断为输出文件中的256个字符。 我在写入之前检查了数据(使用“print”命令),它似乎包含全长(~600个字符)。更奇怪的是,还有另一列具有典型数据~1000个字符且不会被截断。

编辑:这是一个可以重现问题的最小代码。请注意,第二个字符串比第三个字符串短得多,但它仍然在csv中被截断,但第三个字符串完全写入而没有截断。

import csv
mylist = [[0.43,
          "+/Men-s-Casual-British-Style-Canvas-Sports-Shoes--0.jpg::Men's Casual British Style Canvas Sports Shoes ;+/Men-s-Casual-British-Style-Canvas-Sports-Shoes--1.jpg::Men's Casual British Style Canvas Sports Shoes ;+/Men-s-Casual-British-Style-Canvas-Sports-Shoes--2.jpg::Men's Casual British Style Canvas Sports Shoes ;+/Men-s-Casual-British-Style-Canvas-Sports-Shoes--3.jpg::Men's Casual British Style Canvas Sports Shoes ;+/Men-s-Casual-British-Style-Canvas-Sports-Shoes--4.jpg::Men's Casual British Style Canvas Sports Shoes ;+/Men-s-Casual-British-Style-Canvas-Sports-Shoes--5.jpg::Men's Casual British Style Canvas Sports Shoes ",
          "<span style='font-size:14px;'><span style=''><strong>Description:</strong></span><br />\n<span style=''>Men&#39;s Casual British Style Canvas Sports Shoes</span><span style=''> are made of high quality material.It&#39;s Very comfortable.It&#39;s your best choice to go to sport.If you take it,The Simple British design will creates an eye-catching visual effect. It is a perfect gift for someone special or treats for you.<br />\n<br />\nMaterial:Canvas<br />\nColor:Black,Yellow,Blue<br />\nOccasion: Sport<br />\n<br />\n<strong>Details&nbsp;in&nbsp;size:</strong></span></span><br />\n<table border='0' cellpadding='1' cellspacing='1' height='81' width='500'>\n\t<tbody>\n\t\t<tr>\n\t\t\t<td style='text-align: center;'>\n\t\t\t\t<span style='font-size:14px;'><span style=''>US Size</span></span></td>\n\t\t\t<td style='text-align: center;'>\n\t\t\t\t<span style='font-size:14px;'><span style=''>9</span></span></td>\n\t\t\t<td style='text-align: center;'>\n\t\t\t\t<span style='font-size:14px;'> Text goes on and on and on.</span></span></div>\n"]]
with open("test.csv", mode='wb') as f:
    dataWriter = csv.writer(f)
    dataWriter.writerows(mylist)

有没有人遇到过这个?任何暗示都会有所帮助。我使用Python 2.7(Anaconda发行版)

感谢。

0 个答案:

没有答案