On Thu, Jun 25, 2009 at 12:50 PM, Luke<[email protected]> wrote: > > I'm trying to subclass the StrPrinter and PrettyPrinter so that I can > customize the display of some classes I have created for PyDy. I have > had success with getting StrPrinter, but I found it to have some weird > unicode issues, so I am using plain old strings for my sublcass of > StrPrinter, and would like to reserve all unicode stuff for the > PrettyPrinter. > > The way I am subclassing StrPrinter is as follows: > 1) My PyDy classes are subclassed from Basic. I override the __str__() > method of each of my PyDy classes to look like: > def __str__(self): > return pydy_str(self) > > where pydy_str(self) looks like: > def pydy_str(e): > p = PyDyStrPrinter() > return p.doprint(e) > > 2) I subclass StrPrinter, and add methods entitled > _print_<MyPyDyClass>, as follows: > def _print_UnitVector(self, e): > .... > > These _print_*** methods return a string of how I want each class to > be displayed. > > Nowhere in any of my classes, or in my subclassing of StrPrinter, do I > have printmethod defined. Everything above works just fine. > > The problem is when I try the same approach with subclassing > PrettyPrinter. I created class methods entitled _sympypretty_() for > each of my classes, then define a pydy_pretty() function, and then > subclass PrettyPrinter, analogously to my approach above. It doesn't > work. Specifically, I get infinite recursion runtime errors. I tried > adding the printmethod class attribute to my PyDyPrettyPrinter, but it > didn't make any difference, I still get infinite recursion errors. > > I have spent many hours on this and I am sure it is probably a very > simple fix and that I am just not using things correctly. Does > anybody have any recommendations on how this should be done properly? > Ideally, some example code would be the best that way there would be > no confusion as to how this should be done. > > It seems to me that the approach that should be taken to subclassing > either StrPrinter or PrettyPrinter should be conceptually the same, > but perhaps this isn't the case? > > Also, is the approach I am using above for customizing the StrPrinter > the recommended way to do it?
Please create a new branch in your repository with the above problem and show here how to reproduce it, so that people can have a look. Ondrej --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---
