<div dir="ltr"><div dir="ltr">There are 239 instances of "str" in X3duomToX3dPythonPackage.xslt.  208 of them are not related to isinstance</div><div dir="ltr"><br></div><div>Please advise before I go sailing in modifying them to another function.  This looks like a major modification.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 19, 2023 at 11:09 AM John Carlson <<a href="mailto:yottzumm@gmail.com">yottzumm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Redeclaring the float class doesn't seem to work, isinstance fails<div><br></div><div>Monkey patching doesn't work:</div><div><br></div><div><div>def custom_float_str(value):</div><div>    return f"{value:.5g}"</div><div><br></div><div># Monkey-patch the float class</div><div>float.__str__ = custom_float_str</div><div><br></div><div>Overriding the str function doesn't work, because that overrides the str type as well.</div><div><br></div><div>Adding methods to SFFloat doesn't seem to work.</div><div><br></div><div>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.</div><div><br></div><div>Another idea is to convert all floating point input to x3d.py to strings.</div><div><br></div><div>Hmm! I don't like python much, as a beginner.</div><div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 19, 2023 at 9:56 AM John Carlson <<a href="mailto:yottzumm@gmail.com" target="_blank">yottzumm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">I’m guessing I can override float.__str__() and maybe the list.__str__() methods.  Do I do that in x3d.py or my code?</div><div dir="auto"><br></div><div dir="auto">I’m on unfamiliar ground and will have to do some testing unless someone has a definitive response.</div><div dir="auto"><br></div><div dir="auto">I hope this works.  I will run through the smoke tests provided.</div><div dir="auto"><br></div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto">So far, I haven’t seen anyone replacing the str() function.</div><div dir="auto"><br></div><div dir="auto">John </div><div dir="auto"><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 16, 2023 at 11:10 AM GPU Group <<a href="mailto:gpugroup@gmail.com" target="_blank">gpugroup@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">It seems possible to override functions in python, if there are just a few to override.<div>And one suggestion for x3d.py imperfections is to apply fixes at runtime in some initialization function.</div><div>- that assumes/requires just a few target functions, not 480 functions that need to be repaired</div><div>- so for some fixes it may be helpful to change the upstream x3d.py to call a function that can be easily replaced.</div><div>-Doug</div><div>Example:</div><div>file myclass.py<div><div>class Wonky:</div><div>  def __init__(self):</div><div>    self.color = "Red"</div><div>  def func1(self, color :str) -> bool:</div><div>    if color == self.color:</div><div>      return True</div><div>    return False</div></div><div><br></div><div>file override.py</div><div><div>from myclass import *</div><div><br></div><div>mc = Wonky()</div><div>print("match with Blue? "+str(mc.func1("Blue")))</div><div><br></div><div>def func2(self, color: str) -> bool:</div><div>  if self.color != color:</div><div>    return True</div><div>  return False</div><div>Wonky.func1 = func2 # <<<<<<<<<<<< OVERRIDE<br></div><div>print("don't match with Blue? "+str(mc.func1("Blue")))<br></div></div><div><br></div><div>output:</div><div><div>match with Blue? False</div><div>don't match with Blue? True</div></div><div>-Doug</div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 16, 2023 at 9:55 AM John Carlson <<a href="mailto:yottzumm@gmail.com" target="_blank">yottzumm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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.<div dir="auto"><br></div><div dir="auto">I think this is doable by mere humans.</div><div dir="auto"><br></div><div dir="auto">Thanks,</div><div dir="auto"><br></div><div dir="auto">John</div>
</blockquote></div>
</blockquote></div></div>
</blockquote></div>
</blockquote></div>