首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用IronPython从Spotfire中读取临时文件中的大数据

问如何使用IronPython从Spotfire中读取临时文件中的大数据
EN

Stack Overflow用户
提问于 2017-02-14 19:51:12
回答 1查看 754关注 0票数 2

我需要使用IronPython从Spotfire的临时文件中读取大量数据。

首先,我使用exported text()方法将我的Tibco数据表导出到一个临时文件中:

代码语言:javascript
复制
 #Temp file for storing the TablePlot data
tempFolder = Path.GetTempPath()
tempFilename = Path.GetTempFileName()

 #Export TablePlot data to the temp file
tp = tablePlotViz.As[TablePlot]()
writer = StreamWriter(tempFilename)
tp.ExportText(writer)

然后,使用open()方法打开临时文件。

代码语言:javascript
复制
f = open(tempFilename)

现在,当我开始从打开的文件中读取数据并将其写回字符串变量时,这会花费太多时间。我的Spotfire屏幕停止工作了。

有人知道这是怎么回事吗?

我的数据表是8MB大小。

代码为:

代码语言:javascript
复制
from Spotfire.Dxp.Application.Visuals import TablePlot, HtmlTextArea

import clr
import sys
clr.AddReference('System.Data')
import System
from System.Data import DataSet, DataTable, XmlReadMode
from Spotfire.Dxp.Data import DataType, DataTableSaveSettings
from System.IO import StringReader, StreamReader, StreamWriter, MemoryStream, SeekOrigin, FileStream, FileMode,Path, File
from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers
from System.Threading import Thread
from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import RowSelection
from Spotfire.Dxp.Data import DataValueCursor
from Spotfire.Dxp.Data import DataSelection
from Spotfire.Dxp.Data import DataPropertyClass
from Spotfire.Dxp.Data import Import

from Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettings
from System import Array
from Spotfire.Dxp.Application.Visuals import VisualContent
from Spotfire.Dxp.Application.Visuals import TablePlot
from System.IO import Path, StreamWriter
from System.Text import StringBuilder


 #Temp file for storing the TablePlot data
tempFolder = Path.GetTempPath()
tempFilename = Path.GetTempFileName()

 #Export TablePlot data to the temp file
tp = tablePlotViz.As[TablePlot]()
writer = StreamWriter(tempFilename)
tp.ExportText(writer)

#Build the table
sb = StringBuilder()

 #Open the temp file for reading
f = open(tempFilename)

#build the html table
html = " <TABLE id='table' style='display:none;'>\n"
html += "<THEAD>"
html += " <TR><TH>"
html += " </TH><TH>".join(f.readline().split("\t")).strip()
html += " </TH></TR>"
html += "</THEAD>\n"
html += "<TBODY>\n"

for line in f:
   html += "<TR><TD>"
   html += "</TD><TD>".join(line.split("\t")).strip()
   html += "</TD></TR>\n"


#Assigned the all HTML data in the text area
print html

该代码可以很好地处理短数据。

EN

回答 1

Stack Overflow用户

发布于 2017-02-20 00:07:35

如果我没弄错的话,代码背后的意图是将Table Plot可视化数据读取到一个字符串中,以便在HTML文本区域中进一步使用。有一种替代方法可以做到这一点,而无需将数据写入临时文件。我们可以使用内存流导出数据,并将导出的文本转换为字符串以供进一步重用。示例代码可以从here参考。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42225436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档