[x3d-public] Thoughts for x3d.py str() calls
Brutzman, Donald (Don) (CIV)
brutzman at nps.edu
Tue Oct 24 19:22:17 PDT 2023
I have no idea what you are talking about because you have not created a test case that explains what you want. Sorry.
all the best, Don
--
Don Brutzman Naval Postgraduate School, Code USW/Br brutzman at nps.edu
Watkins 270, MOVES Institute, Monterey CA 93943-5000 USA +1.831.656.2149
X3D graphics, virtual worlds, navy robotics https://faculty.nps.edu/brutzman
From: John Carlson <yottzumm at gmail.com>
Sent: Thursday, October 19, 2023 9:16 AM
To: GPU Group <gpugroup at gmail.com>
Cc: Brutzman, Donald (Don) (CIV) <brutzman at nps.edu>; Peitso, Loren (CIV) <lepeitso at nps.edu>; X3D Graphics public mailing list <x3d-public at web3d.org>
Subject: Re: Thoughts for x3d.py str() calls
There are 239 instances of "str" in X3duomToX3dPythonPackage.xslt. 208 of them are not related to isinstance
Please advise before I go sailing in modifying them to another function. This looks like a major modification.
On Thu, Oct 19, 2023 at 11:09 AM John Carlson <yottzumm at gmail.com <mailto:yottzumm at gmail.com> > wrote:
Redeclaring the float class doesn't seem to work, isinstance fails
Monkey patching doesn't work:
def custom_float_str(value):
return f"{value:.5g}"
# Monkey-patch the float class
float.__str__ = custom_float_str
Overriding the str function doesn't work, because that overrides the str type as well.
Adding methods to SFFloat doesn't seem to work.
I'm pretty much bamboozled, and the next step is to replace many str() calls in x3d.py with my own function, which was my original idea.
Another idea is to convert all floating point input to x3d.py to strings.
Hmm! I don't like python much, as a beginner.
On Thu, Oct 19, 2023 at 9:56 AM John Carlson <yottzumm at gmail.com <mailto:yottzumm at gmail.com> > wrote:
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 <mailto: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 <mailto: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/20231025/5acd84b1/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5464 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20231025/5acd84b1/attachment-0001.p7s>
More information about the x3d-public
mailing list