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

Raymond Hettinger raymond.hettinger at gmail.com
Thu Jul 15 08:39:46 CEST 2010


On Jul 14, 2010, at 3:43 PM, M.-A. Lemburg 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>'
> 
> I would have expected str(m) == 'abc'.

That is also my expectation.

A memoryview object is iterable, so str(memviewobj) should return ''.join(memviewobj).

In your example, that would be:

>>> list(m)
['a', 'b', 'c']
>>> ''.join(m)
'abc'


Raymond


More information about the Python-Dev mailing list