Override .NET/Python __str__ method. #1715
Unanswered
dorpinelli-daitan
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Environment
Details
I'm fairly noob in .NET<->Python so this is definitely not an issue, but I'm not being able to achieve what I want so any help is appreciated.
I'm trying to monkey-patch/override (or something along these lines) a .NET class.
My goal is to change how the
__str__method works, add some formatting to it.I have a .NET DLL that fires a callback with an event. This event has many attributes, one of them has the datatype
System.Drawing.SizeF, so when Istr(event.Size)it prints{Width=116,4981, Height=83,67346}.I want to change how
SizeF.__str__works, so I can format this data before returning.What I've tried so far
But I get
AttributeError: attribute is read-only, which makes sense.Another approach, if the code wasn't trigged by the SDK, would be to subclass SizeF:
Then I could just use CustomSizeF. But it's the DLL that sends me this object (a very complex and nested one), so I'd have to iterate the whole object searching for SizeF instances and replace them by CustomSizeF.
Is there a way of achieving this?
Sorry if this is not the best place for asking.
All reactions