I am having an issue with the string representation of custom classes in Python 3. Previously, using Rhino 7 and Python 2, when creating a custom class I was able to inherit the ToString() methods from the default “object” class, and use it to control how the name of the class was displayed when passed between Grasshopper components.
This does not seem to work anymore in Python 3, as the value set in ToString() is not used, as you can see in the comparison below of two compnents running the same code. Any suggestion?
.ToString()
is a dotnet method, applicable only in IronPython context.
Pythonic way to override string conversion and representation is:
__str__(self)
- and
__repr__(self)
I think __repr__
is the correct approach in this case, but I’m not sure now which method Grasshopper uses to generate text representations of Python objects. Try both and see?
1 Like
Thanks for the help.
They both work, which is kind of interesting…