On Thu, Mar 22, 2012 at 11:14 PM, Alexey U. Gudchenko <[email protected]> wrote: > 23.03.2012 07:46, smichr пишет: >> Within an interactive session I can override the printing of a matrix >> as follows: >> >> >>> Matrix.__repr__ = mrepr >> >>> randMatrix(2,2) >> [34 16] >> [33 54] >> >> When I try this in a docstring, it doesn't change the output. Does >> anyone know what I should override in the docstring to get this to >> work? >> > > If you use SymPy doctest utility, then sympy printer is used and it can > check property "_sympystr": > > """ > >>> from sympy.matrices import * > >>> def mrepr(self, printer): > return "777" > >>> Matrix._sympystr = mrepr > >>> randMatrix(2) > """ > > Failed example: > randMatrix(2) > Expected nothing > Got: > 777 > > > This will work also and in interactive session. > > > Note also, that there is "_sympyrepr" (may be obsolated, it calls by > "srepr" function)
It's not obsolete. This is a hook for the repr printer, whereas _sympystr is the hook for the string printer. See http://docs.sympy.org/dev/modules/printing.html. Note that we use srepr() instead of repr() for repr because of the way that list calls repr() on its elements with str(). Aaron Meurer > > And "_pprint" for pretty print overloading. > > > > --- > Alexey. > > -- > 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. > -- 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.
