Hi Luke, I think all your questions are answered in the docstring of printing/printer.py. There it tells you in which order it is tried to print an object.
1) Let the object print itself if it has the method defined as printmethod. 2) Use the method defined in the Printer if available. 3) Use some fallback printer. Luke wrote: > Sorry, I accidentally clicked send before I had finished. A few > questions: > > So here is part of my PyDyPrinter class: > class PyDyPrinter(StrPrinter): > printmethod = "_pydystr_" > ... > def _print_sin(self, e): > name = str(e.args[0]) > if name[0] == "q": > index = name[1] > return "s%s" % index > else: > return str(e) > ... > > > And here is a convenience function. > > def print_pydy(e): > pp = PyDyPrinter() > return pp.doprint(e) > > Question 1) What does printmethod do / control? Does this control > what the name of my print methods in each of my classes needs to be? Is explained above. > Question 2) Do I need to have _sympystr_ defined in the classes I > wish to customize the printing for? Or should it be: _pydystr_, since > that is what is printmethod is defined to be. If all your classes are handled in your own printer you don't need any additional methods. > Question 3) Do I put the printing code for my class into > myclassname._sympystr_ (or ._pydystr_), or does it go inside my > subclass of StrPrinter, PyDyPrinter? That's your choice, use what you like more. > Question 4) If the printing code goes in my subclass of StrPrinter > (in my case PyDyPrinter), then do I just put in the _sympystr_ method > of my class something like: return print_pydy(self)? Okay this influences question3. If you have one (or only a few) common base class, you can just overwrite the __str__ and __repr__ methods there. For an example look into core/basic.py into the Base class. Otherwise it may be better to just write the printing code into _sympystr_ methods in every class. > > I've read the printing documentation, and the wiki, and the mailing > list, and I'm still not clear how the Printing system works. In some > examples I have seen there is no printingmethod variable set, and I'm > not clear what it does exactly. Maybe somebody could post a complete > example, that would show their subclassing of StrPrinter, as well as > the code inside their cusstom class, and any other relevant code as a > complete example of how to properly customize the printing? Just go through the printers implemented in the printing directory. Especially printer.py is useful and for some full implementation examples you can go through str.py and repr.py. I hope this helps, Sebastian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---