Print String

Jeff Epler jepler at
Tue Jun 1 20:25:04 CEST 2004

I'd try something along these lines:
    def GeneratePrefix(expr):
        if expr.__class__ == E:
            yield str(expr.operator)
            for i in GeneratePrefix(expr.left): yield i
            for i in GeneratePrefix(expr.right): yield i
            yield str(expr)
The successive elements produced by this (untested) code should be the
same as the elements printed by your code.

To join these into a string without any whitespace, you could write
    def StringPrefix(expr):
        return "".join(GeneratePrefix(expr))
and you could re-write the original PrintPrefix as
    def PrintPrefix(expr):
        for item in expr:
            print item,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <>

More information about the Python-list mailing list