Skip to main content
Inspiring
April 18, 2024

Printing python objects for from scripts/plugins in Sampler

  • April 18, 2024
  • 1 reply
  • 211 views

I noticed that if I try to use python's print function on python objects in Sampler, it doesn't print anything in the Sampler log window, like it does for internal types like str, list, or dict.

 

See below for an example:

 

class MyObject():
    object_attr = "attribute"

x = [1,2,3]
y = {"a": "b"}
z = MyObject()
print("printing objects")
print(f"x = {x}")
print(f"y = {y}")
print(f"z = {z}")

 

output:

 

printing objects
x = [1, 2, 3]
y = {'a': 'b'}
z = 

 

 Normally I would expect something like:

 

z = <__main__.MyObject object at 0x10849b040>

 

as it is, it makes it a little more difficult to debug things using the log output and for a while I thought something was broken in my code when it was just the print statement that was not printing the info I expected.

1 reply

Inspiring
April 18, 2024

Also, trying to print some of the return values from the API calls result in errors:

import substance_sampler as ssa
materials = ssa.get_materials()
print(materials)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 12: invalid start byte