print object attributes recursively

lallous lallous at
Tue Sep 29 17:30:14 CEST 2009


Suppose I have this code:

class X:
    def __init__(self, n):
        self.L = [x for x in xrange(0, n+1)]

class Y:
    def __init__(self, n):
        self.M = [X(x) for x in xrange(0, n)]

t = Y(5)

How can I easily print "t" and all its nested attributes? (Something like 
PHP's print_r())


More information about the Python-list mailing list