Custom object formatting in Python