Python - how to publish string data (text) to csv file

I would like to publish string data to the a csv file using the CSVResultListener. I’m able to publish numeric data, but not string data. Is this possible?

Hi @mrha1, and welcome to the forum!

In theory it should not be a problem. Can you share how you publish the results?

Hi Rolf,

Thanks for the welcome and fast response, much appreciated…

I’m trying to publish something like:

self.PublishResult("MyTable", ["test", "status"], [1, 2])                 # This works
self.PublishResult("MyTable", ["test", "status"], ["Test-1", "Pass"])     # This generates an error

Here is the error that I’m seeing:

08:20:08.098  TestPlan     Error running "Waitfor Command (1)": 'str' value cannot be converted to System.Double.
08:20:08.100  TestPlan     PythonException: 'str' value cannot be converted to System.Double
08:20:08.138  TestPlan         File "C:\Program Files\OpenTAP\Packages\Python\", line 208, in PublishResult
08:20:08.138  TestPlan         r[i] = Double(rows[i])
08:20:08.138  TestPlan         File "C:\Program Files\OpenTAP\Packages\try_this\", line 51, in Run
08:20:08.138  TestPlan         self.PublishResult("MyTable", ["test", "status"], ["Test-1", "Pass"])
08:20:08.138  TestPlan         at Python.Runtime.PythonException.ThrowLastAsClrException()
08:20:08.138  TestPlan         at Python.Runtime.PyObject.Invoke(PyObject[] args)

Ok, looking at the code from, it seems like it expects the value to be something that can be converted to a double. I think we should fix that : Allow more than numeric values to be published from PyTestStep.PublishResult · Issue #91 · opentap/OpenTap.Python · GitHub

For now, you can take a slightly different approach to publishing results. If you see the “NumpyStep” from examples, it goes through the must efficient method of publishing multiple results.

you need to use
Array.CreateInstance(System.String, 1)

and then call self.Results.PublishTable("XY", columnNames, xx, yy)

If you need I can create a more complete example.

1 Like

Great, this works for me.
Thanks for the workaround!

1 Like