[Python-Dev] Re: adding a bytes sequence type to Python (original) (raw)
M.-A. Lemburg mal at egenix.com
Tue Aug 17 23:58:27 CEST 2004
- Previous message: [Python-Dev] Re: adding a bytes sequence type to Python
- Next message: [Python-Dev] Re: adding a bytes sequence type to Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Roman Suzi wrote:
On Tue, 17 Aug 2004, M.-A. Lemburg wrote:
Michael Hudson wrote:
Anthony Baxter <anthony at interlink.com.au> writes:
A big +1 for a bytes() type, though. I'm not sure on the details, but it'd be nice if it was possible to pass a bytes() object to, for instance, write() directly. If bytes() doesn't implement the read buffer interface, someone somewhere is going to need shooting :-) Is there any reason you cannot use buffer() ?! Is it mutable? My guess: no:
The buffer object itself can be read-only or read-write. Unfortunately, the buffer() built-in always returns read-only buffers. At C level it is easy to create a buffer object from a read-write capable object.
d = u'123124' ddd[0] '1'
ddd[1] '\x00' ddd[1] = '1' Traceback (most recent call last): File "", line 1, in ? TypeError: buffer is read-only It already implements all the necessary things and has been available for many years. It was in the shadows because we had byte-strings.
Right, so why not revive it ?!
Anyway, this whole discussion about a new bytes type doesn't really solve the problem that the b'...' literal was intended for: that of having a nice way to define (read-only) 8-bit binary string literals.
We already have a number of read-write types for storing binary data, e.g. arrays, cStringIO and buffers. Inventing yet another way to spell binary data won't make life easier.
However, what will be missing is a nice way to spell read-only binary data.
Since 'tada' will return a Unicode object in Py3k, I think we should reuse the existing 8-bit string object under the new literal constructor b'tada\x00' (and apply the same source code encoding semantics we apply today for 'tada\x00').
-- Marc-Andre Lemburg eGenix.com
Professional Python Services directly from the Source (#1, Aug 17 2004)
Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::
- Previous message: [Python-Dev] Re: adding a bytes sequence type to Python
- Next message: [Python-Dev] Re: adding a bytes sequence type to Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]