summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Reiss <dreiss@apache.org>2009-01-05 20:14:52 +0000
committerDavid Reiss <dreiss@apache.org>2009-01-05 20:14:52 +0000
commit888f88b05d25eb7b07541ed916f05234e1229138 (patch)
tree2d5057532ed64b61d99897f4498f068e2fea4a8c
parent41687fc6cfa179883da9b18d094ad56f6be669da (diff)
downloadthrift-888f88b05d25eb7b07541ed916f05234e1229138.tar.gz
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
-rw-r--r--compiler/cpp/src/generate/t_py_generator.cc7
1 files 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 85eb3f67a..8c9747a03 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