Learn how to write back to a text file using Iron Python
Introduction
Writing back to a text file can serve different purpose and different needs. The basic concept on how to write to a text file from Spotfire is using a StreamWriter
Exporting data from Cross Table, Table Plot or Summary Table
These visualizations have the ExportText method. With a few lines of code, we can export the data from these visualizations. Here is an example exporting data to a text file from a CrossTable:
from Spotfire.Dxp.Application.Visuals import CrossTablePlot from System.IO import StreamWriter targetFile = "c:\\temp\\test\\crosstable.txt" writer = StreamWriter(targetFile) crossTable = vis.As[CrossTablePlot]() crossTable.ExportText(writer)
To append data to a file, keep the StreamWriter second argument as True to keep the stream open. Here is an example that writes a line to a text file
from System.IO import StreamWriter #targetFileName = "\\\\company.com\\your\\folder\\ratings.txt" targetFileName = "C:\\temp\\ratings.txt" #Write to file writer = StreamWriter(targetFileName,True) #True to append writer.Write("hello world!") writer.Close()
Recommended Comments
There are no comments to display.