From 888f88b05d25eb7b07541ed916f05234e1229138 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Mon, 5 Jan 2009 20:14:52 +0000 Subject: [PATCH] THRIFT-241. python: Generate a better implementation of __repr__ git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@731685 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/src/generate/t_py_generator.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc index 85eb3f67..8c9747a0 100644 --- a/compiler/cpp/src/generate/t_py_generator.cc +++ b/compiler/cpp/src/generate/t_py_generator.cc @@ -614,11 +614,10 @@ void t_py_generator::generate_py_struct_definition(ofstream& out, // Printing utilities so that on the command line thrift // structs look pretty like dictionaries out << - indent() << "def __str__(self):" << endl << - indent() << " return str(self.__dict__)" << endl << - endl << indent() << "def __repr__(self):" << endl << - indent() << " return repr(self.__dict__)" << endl << + indent() << " L = ['%s=%r' % (key, value)" << endl << + indent() << " for key, value in self.__dict__.iteritems()]" << endl << + indent() << " return '%s(%s)' % (self.__class__.__name__, ', '.join(L))" << endl << endl; // Equality and inequality methods that compare by value -- 2.17.1