Guido van Rossum <gvanrossum at gmail.com> wrote: > Even more mysterious > is that the array implementation appears to support the buffer API and > yet it can't be used as an argument to write(). What's going on? It supports the "read" buffer API but not the "character" buffer API, so the file has to be opened in binary mode for it to work: >>> a = array.array('c', 'fish') >>> open('/dev/null', 'w').write(a) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: argument 1 must be string or read-only character buffer, not array.array >>> open('/dev/null', 'wb').write(a) >>> That restriction(?) comes from this in file_write: PyArg_ParseTuple(args, f->f_binary ? "s#" : "t#", ... where s# requires a read buffer and t# requires a character buffer. array.array is the only type in the core that's a read buffer but not a character buffer, and I can't find any semantic differences between read and character buffers. If someone can explain the differences or confirm that there aren't any, I'll make this work. The easiest thing to do would be to make array support the character buffer API (but maybe only for [cbBu] types?). Dima.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4