From: David Reiss Date: Mon, 5 Jan 2009 20:14:52 +0000 (+0000) Subject: THRIFT-241. python: Generate a better implementation of __repr__ X-Git-Tag: 0.2.0~386 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=888f88b05d25eb7b07541ed916f05234e1229138;p=common%2Fthrift.git 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 --- 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