Print String

Jeff Epler jepler at unpythonic.net
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
        else:
            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,

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040601/ca7c2c2c/attachment.pgp>


More information about the Python-list mailing list