Search code examples
ironpythonspotfire

Output Spotfire 'print' to text file


I have been struggling with something I hope to be a simple question. I would like to output values (String / Real / Stringlist) from Spotfire to a text file on my computer. My final solution would need document properties to be listed and saved, but for now let's use a working script from stackoverflow: Is it possible to use IronPython to return the path of the current *.dxp project as a string?

Two variables: path and analysis are 'printed'. How can I print those to a text file?

Something similar is done here: http://spotfired.blogspot.co.uk/2014/04/export-image-from-visualization.html where a .bmp image is created.

Many thanks,


Solution

  • writing to a file isn't unique to IronPython; the Python docs go over this fairly well. in any case:

    f = open('c:\\filename.txt', 'w')
    
    f.write(path)
    f.write(analysis)
    
    my_list = ['one','two','three']
    
    for item in my_list:
        f.write(item)    # write the item's content
        f.write('\n')    # add a line break (optional)
    
    f.close()
    

    will do you fine.

    IronPython is a derivative of regular Python that can interact with .NET APIs such as Spotfire's API. thus, you can typically find non-Spotfire-specific solutions by looking at Python resources.