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?
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.
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?
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)?

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?

Thanks,
~Luke


On May 28, 3:23 pm, Luke <hazelnu...@gmail.com> wrote:
> I'm a little unclear about a few things with regards to how to
> properly subclassStrPrinter.
>
> On May 27, 5:08 pm, Ondrej Certik <ond...@certik.cz> wrote:
>
> > On Wed, May 27, 2009 at 6:05 PM, Luke <hazelnu...@gmail.com> wrote:
>
> > > I like the first way for the fact that it just has 'x' instead of 'x
> > > (t)', but I like the second way because it is simpler and easier to
> > > implement.
>
> > The first way needs patching sympy, exactly because it things that "x"
> > is just "x" and thus if the expression doesn't depend on "t", it
> > return 0 immediately.
>
> > > Is there a way to redefined how x = Symbol('x')(t) would print?  I
> > > guess subclassing would be one option, take care of it there, and then
> > > use the second approach for the auto substitution stuff.
>
> > In fact, just subclassStrPrinterand override _print_Symbol() or
> > _print_Function(). You have your own printer in pydy anyway, so just
> > add there one more method.
>
> > Ondrej
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to