Is this object counter code pythonic

jnair at ensim.com jnair at ensim.com
Mon Apr 10 06:54:56 EDT 2006


My Team  Lead says  my object counter  code seen below is not  pythonic

 class E(object):
    _count = 0
    def __init__(self):
        E._count += 1
    count = property(lambda self: E._count )

def  test():
    if __name__ == "__main__":
        e1 = E()
        print e1.count
        e2 = E()
        print e2.count
        e3 = E()
        print e3.count

test()



if  not  what would be the  pythonic way




More information about the Python-list mailing list