[x3d-public] Thoughts for x3d.py str() calls
John Carlson
yottzumm at gmail.com
Thu Oct 19 07:56:53 PDT 2023
I’m guessing I can override float.__str__() and maybe the list.__str__()
methods. Do I do that in x3d.py or my code?
I’m on unfamiliar ground and will have to do some testing unless someone
has a definitive response.
I hope this works. I will run through the smoke tests provided.
I will probably modify the Blender X3DV exporter first, and if that doesn’t
work, proceed to modify x3d.py. I don’t think it’s a good idea to modify
x3d.py itself.
So far, I haven’t seen anyone replacing the str() function.
John
On Mon, Oct 16, 2023 at 11:10 AM GPU Group <gpugroup at gmail.com> wrote:
> It seems possible to override functions in python, if there are just a few
> to override.
> And one suggestion for x3d.py imperfections is to apply fixes at runtime
> in some initialization function.
> - that assumes/requires just a few target functions, not 480 functions
> that need to be repaired
> - so for some fixes it may be helpful to change the upstream x3d.py to
> call a function that can be easily replaced.
> -Doug
> Example:
> file myclass.py
> class Wonky:
> def __init__(self):
> self.color = "Red"
> def func1(self, color :str) -> bool:
> if color == self.color:
> return True
> return False
>
> file override.py
> from myclass import *
>
> mc = Wonky()
> print("match with Blue? "+str(mc.func1("Blue")))
>
> def func2(self, color: str) -> bool:
> if self.color != color:
> return True
> return False
> Wonky.func1 = func2 # <<<<<<<<<<<< OVERRIDE
> print("don't match with Blue? "+str(mc.func1("Blue")))
>
> output:
> match with Blue? False
> don't match with Blue? True
> -Doug
>
> On Mon, Oct 16, 2023 at 9:55 AM John Carlson <yottzumm at gmail.com> wrote:
>
>> Instead of calling str() to print out a value, call a function that does
>> precision floating point formatting on floats according to a user’s
>> wishes. If the value is a list, call the function recursively with a list
>> comprehension, otherwise, call str.
>>
>> I think this is doable by mere humans.
>>
>> Thanks,
>>
>> John
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20231019/5aa16ba8/attachment.html>
More information about the x3d-public
mailing list