[Python-ideas] Memoryview tolist() method is misleading

4 views
Skip to first unread message

Stefan Krah

unread,
Sep 14, 2012, 4:00:09 PM9/14/12
to python...@python.org
Alexander Belopolsky wrote:
> Consider this:
> >>> memoryview(b'x').cast('B', ()).tolist()
> 120
>
> The return value of to list() is an int, not a list.


That's because NumPy's tolist() does the same thing:

>>> x = numpy.array(120, dtype='B')
>>> x
array(120, dtype=uint8)
>>> x.tolist()
120


If you implement tolist() recursively like in _testbuffer.c and choose
the zeroth dimension as the base case, you arrive at single elements.
So at least it's not completely unnatural.


Stefan Krah


_______________________________________________
Python-ideas mailing list
Python...@python.org
http://mail.python.org/mailman/listinfo/python-ideas
Reply all
Reply to author
Forward
0 new messages