[Python-Dev] str(memoryview('abc')) != 'abc' in Python 2.7

Antoine Pitrou solipsis at pitrou.net
Thu Jul 15 12:37:54 CEST 2010


On Thu, 15 Jul 2010 00:43:49 +0200
"M.-A. Lemburg" <mal at egenix.com> wrote:
> Is this intended or should I open a bug report for it:
> 
> >>> m = memoryview('abc')
> >>> m == 'abc'
> True
> >>> str(m) == 'abc'
> False
> >>> str(m)
> '<memory at 0x2b2bb6ee26d8>'

Well, I think this is intended. str(m) is the human-readable string
representation of the memoryview. In 3.x, you would write bytes(m)
instead to have its bytes contents.
Or, better again, use m.tobytes() in both versions.

Regards

Antoine.




More information about the Python-Dev mailing list