IronPython 2 vs Python 3 Print Terminal

Hello,

I am curious if there is a way to get the Terminal view of a print function to show the same data between IronPython 2 and Python 3.

I use the ghpythonlib.components library frequently, and I check my work through the print() function. However, in Python 3 the result in the Terminal is IronPython.Runtime.List

I can view the opaque list easily enough if I add an extra line: div_list = [i for i in div]
But I was hoping there was a way to change this so when I print() I can see what my data is.

Thanks!

@Schuyler_McAuliffe

Thanks for reporting this. The problem is really in the NodeInCode module that handles the ghp.DivideCurve() runs the grasshopper node, and grabs the returned data. Currently it specifically constructs a new IronPython.Runtime.List and that is what is passed back to the Python 3 code. print statement in IronPython knows how to handle this but in Python 3, the __str__ or __repr__ method is called printing IronPython.Runtime.List or <IronPython.Runtime.List object at 0x...>. I do not wish to change this behaviour to avoid breaking legacy code that depends on it.

You can fix this by calling list() on the returned data, and while you are at it, use the pprint module for nicer printing

from pprint import pprint
import ghpythonlib.components as ghp
div = ghp.DivideCurve(x, 10, False)[0]
pprint(list(div))

@eirannejad, that makes sense. I assumed it had to do with legacy code and was therefore unable to change, but I appreciate your response anyway.

And thank you for the pprint() tip! I’ve seen that before, but it isn’t a habit yet. :grinning_face:

1 Like