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
it's because you have overridden *both* _pretty_ and
_print_GreenEggsAndHam(). You only should override one of those, then
it will work.
It's true we should improve the Printer code to handle such case too,
patches welcome.
Another problem is that if you use unicode, you have to change
"\xC2\xB7" to u"\xC2\xB7"
Yet another problem with the above code is that PrettyPrinter expects
StringPict() instance, so you can fake it by your own class that
implements render.
Another problem is that print_GreenEggsAndHam returns the result, but
you want to print it. Anyways, with all the above things fixed, it now
prints:
i love sympy⋅·
GreenEggsAndHam(I LOVE SYMPY)
Is this what you want?
The fixed script is below.
Ondrej
--------------------
from sympy import Basic
from sympy.printing.str import StrPrinter
from sympy.printing.pretty.pretty import PrettyPrinter, xsym, pprint
class GreenEggsAndHam(Basic):
def __init__(self, string):
self.s = string
#def _pretty_(self):
# return print_GreenEggsAndHam(self)
class HamPrinter(PrettyPrinter):
printmethod = '_pretty_'
def _print_GreenEggsAndHam(self, e):
class Fake(object):
def render(self, *args, **kwargs):
return e.s.lower() + xsym('*') + u"\xC2\xB7"
return Fake()
def print_GreenEggsAndHam(e):
pp = HamPrinter()
return pp.doprint(e)
MyBreakfast = GreenEggsAndHam('I LOVE SYMPY')
print print_GreenEggsAndHam(MyBreakfast)
pprint(MyBreakfast)