[x3d-public] Thoughts for x3d.py str() calls
GPU Group
gpugroup at gmail.com
Mon Oct 16 09:09:59 PDT 2023
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/20231016/22251203/attachment.html>
More information about the x3d-public
mailing list