Python 为什么我的字符串在输出到CSV时限制为32758个字符?
我正在运行一个Python2.7.12程序来处理大量数据,我创建的一个字符串存储了大量数据,但我注意到,当我将字符串输出为CSV时,它的上限为32758个字符 我正在Ubuntu-16.04虚拟机上的开发服务器上运行我的脚本,可以访问20GB的RAM 为什么我的一根弦的上限是32758?是否有解决方法或方法来修复此问题,以便我能够在字符串中存储更多内容Python 为什么我的字符串在输出到CSV时限制为32758个字符?,python,string,python-2.7,ubuntu-16.04,export-to-csv,Python,String,Python 2.7,Ubuntu 16.04,Export To Csv,我正在运行一个Python2.7.12程序来处理大量数据,我创建的一个字符串存储了大量数据,但我注意到,当我将字符串输出为CSV时,它的上限为32758个字符 我正在Ubuntu-16.04虚拟机上的开发服务器上运行我的脚本,可以访问20GB的RAM 为什么我的一根弦的上限是32758?是否有解决方法或方法来修复此问题,以便我能够在字符串中存储更多内容 import os import pdfkit import re import requests import urllib2 #pdfmin
import os
import pdfkit
import re
import requests
import urllib2
#pdfminer
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
from cStringIO import StringIO
#Opening my files
#with open("GoodData.csv", 'w') as output: this does the same thing as what I have currently
output = open("GoodData.csv", 'w')
output.write("Company|Classification|ID Number|Incorporation State/Country|Address|Link to Metadata|Link to Data|Data" + '\n')
count = 0
counter = 0
archive = open("archive.txt", 'w')
qwerty = open("ProblemLinks.txt", 'r')
for item in qwerty:
#for item in linkList:
print(" ")
print("Number of documents parsed: " + str(count))
#This loop is for testing, to go to a specific link
if counter == 0:
#So I get the links out of this
meta = metaData(item)
pdfkit.from_url(meta[0], 'out.pdf')
file = "/home/project/out.pdf"
holder = convert_pdf_to_txt(file)
if holder == None:
output.write(''.join(['|'.join([str(meta[3]), str(meta[1]), str(meta[2]), str(meta[4]), str(meta[5]), str(item).rstrip(), str(meta[0]), "No risk data found"]), '\n']))
else:
output.write(''.join(['|'.join([str(meta[3]), str(meta[1]), str(meta[2]), str(meta[4]), str(meta[5]), str(item).rstrip(), str(meta[0]), holder]), '\n']))
count = count + 1
else:
counter = counter + 1
在解析完成之前,我可以打印
holder
,并且整个文档都存储在那里。好吧,我算出了
它与我输出文件的方式无关,也与我的代码无关,它的Excels错误
显然,当我将CSV文件加载到excel工作表中时,它会将字符串剪切为32位字符串
输出。写入(…)
?你是否忘记了.flush
你的文件对象,或者更好的是,.close()
当你完成时,或者最好是使用上下文管理器为你自动完成这项工作?@juanpa.arrivillaga我从来都不是的头。flush
我有一个上下文管理器。我没有包括.close()
,因为在我需要关闭CSV文件之前,它需要解析几千个文件。它正在写入CSV文件。您可以提供您用于写入文件的实际代码吗?@juanpa.arrivillaga我描述中的最后一行是我用于写入文件的代码,我开始认为这可能是对.join
的限制,它可能会将字符串转换为32位string@smci我使用的是python 2.7.12,我包含了更多的代码,这些代码应该提供更多的上下文,我做了len()
的事情,字符串长度始终超过100000个字符。我将在上运行更多测试。加入