2017-02-14 107 views
2

我需要使用IronPython從Spotfire中的臨時文件讀取大量數據。如何使用IronPython從Spotfire中的臨時文件讀取大量數據

首先,我已使用導出的文本()方法導出我的Tibco的數據表中臨時文件:

#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()方法打開的臨時文件。

f = open(tempFilename) 

現在,當我開始從打開的文件中讀取數據並寫回到String變量中時,它會花費太多時間。我的Spotfire屏幕停止工作。

有沒有人想過這個?

我的數據表是8MB大小。

代碼是:

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 

代碼工作正常短數據。

回答

0

如果我得到正確,代碼背後的意圖是將Table Plot可視化數據讀入一個字符串,以供在HTML文本區域中進一步使用。 有一種替代方法可以做到這一點,而無需將數據寫入臨時文件。我們可以使用內存流來導出數據並將導出的文本轉換爲字符串以供進一步重用。示例代碼可以參考here

+0

謝謝Vivek。當然,我會試試這個,讓你知道結果:) – Aashi

相關問題