wang-xinhong / protobuf

Automatically exported from code.google.com/p/protobuf
Other
0 stars 0 forks source link

[Python] output difference between cpp & pure python #264

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a protocol with repeated fields
2. Compare repr() output between cpp & pure python versions.

What is the expected output? What do you see instead?

In [1]: from protocols import Alerts_pb2

In [2]: d=Alerts_pb2.Datum(data=['2', '3'])

In [3]: d
Out[3]: <protocols.Alerts_pb2.Datum object at 0xa2f5294>

In [4]: print d
data: "2"
data: "3"

In [5]: d.data
Out[5]: <google.protobuf.internal.cpp_message.RepeatedScalarContainer object at 
0xa2f2e6c>

If you use the pure python version the output is:

Out[5]: [u'2', u'3']

This is easily fixed:

In [6]: from google.protobuf.internal import cpp_message

In [7]: cpp_message.RepeatedScalarContainer.__repr__ = lambda self: 
repr(list(self))

In [8]: d.data
Out[8]: [u'2', u'3']

What version of the product are you using? On what operating system?

protobuf 2.4.0a on Ubuntu 10.04 LTS

Please provide any additional information below.

Original issue reported on code.google.com by klep...@gmail.com on 24 Feb 2011 at 2:50

GoogleCodeExporter commented 9 years ago
Forgot to note, the RepeatedCompositeContainer has a similar problem which is 
probably jutt as easy to fix.

Original comment by klep...@gmail.com on 24 Feb 2011 at 2:51

GoogleCodeExporter commented 9 years ago

Original comment by kenton@google.com on 17 Apr 2011 at 7:47

GoogleCodeExporter commented 9 years ago

Original comment by xiaof...@google.com on 10 Oct 2014 at 1:06