Customer Banners (Ads) - SpiceUp. AX and SpotfireX Disclaimer



If you find this site useful and you want to support, buy me a coffee   to keep this site alive and without ads.

IronPython Terminal

script to run ironPython scripts

import sys
from io import StringIO
code = Document.Properties["input"] 

capturer = StringIO()
sys.stdout = capturer

try:
exec(code)
sys.stdout = sys.__stdout__
output = capturer.getvalue()
except Exception as e:
output = str(e)

Document.Properties["output"]=output

script to run Python code via a data function

import sys
from io import StringIO
capturer = StringIO()
sys.stdout = capturer

try:
exec(code)
sys.stdout = sys.__stdout__
output = capturer.getvalue()
except Exception as e:
output = str(e)


html

<SpotfireControl id="input field multiple lines property control" />
<SpotfireControl id="action control that runs the above script" />

<pre style="height:50%;background:blue;color:yellow;overflow:auto;padding:10px;border:3px inset">
<SpotfireControl id="output document property (Label)" /></pre>



Example code to list python packages on TIBCO Cloud spotfire from this termnal

import pandas as pd
import pkg_resources

installed_packages = pkg_resources.working_set
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
    for i in installed_packages])
package_list = [[r.split('==')[0],r.split('==')[1]] for r in installed_packages_list]

packages = pd.DataFrame(columns=["Package Name", "Package Version"])

idx = 0
for pkg in package_list:
    packages.loc[idx] = [pkg[0], pkg[1]]
    idx += 1

print(packages.to_string())




Note: if you put this code on a data function and you want to return a data table with the list of packages, then remove the last line and set the output parameter to point to the packages variable

Note: Please be careful running this script in production environments.

With great power comes great responsibiliy

No comments: