[Python-Dev] The buffer() function (original) (raw)

Thomas Heller theller at python.net
Thu Jul 13 18:52:33 CEST 2006


I just answered a question on comp.lang.python for someone who was asking about how to convert the internal buffer of a ctypes instance into base64 coding, without too much copying:

"The conversion calls in the base64 module expect strings as input, so right now I'm converting the binary blocks to strings first, then converting the resulting string to base64. This seems highly inefficient and I'd like to just go straight from binary to a base64 string."

Naturally I tried to call base64.encodestring(buffer(ctypes_instance)) and it worked, so that was my answer.

As it turns out the guy (unusal!) tried to look up information about the buffer function in the documentation. What he found is this:

"Python programmers, trainers, students and bookwriters should feel free to bypass these functions without concerns about missing something important".

Not an encouragement to use this function. So, what is the real state of the buffer() function, and the buffer object?

IIUC, the buffer object was broken some time ago, but I think it has been fixed. Can the 'status' of the buffer function be changed? To quote the next question from the OP:

"Is buffer safe to use? Is there an alternative?"

My thinking is that it is safe to use, and that there is no alternative (but imo also no alternative is needed).

Thanks, Thomas



More information about the Python-Dev mailing list