Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is meant with a buffer in python

Tags:

python

io

buffer

In the python documentation for struct, the word buffer is used without explanation:

http://docs.python.org/library/struct.html

struct.unpack_from(fmt, buffer[,offset=0])

Unpack the buffer according to the given format. The result is a tuple even if it contains exactly one item. The buffer must contain at least the amount of data required by the format (len(buffer[offset:]) must be at least calcsize(fmt)).

What is meant here with a buffer. Is a string a buffer, or a file descriptor? What methods must a 'buffer' have?

like image 872
Peter Smit Avatar asked Oct 11 '22 10:10

Peter Smit


1 Answers

It's a memory buffer: in Python 2, a string (str), in Python 3, a binary string (bytes), or alternatively an object constructed with buffer.

like image 186
Fred Foo Avatar answered Nov 05 '22 09:11

Fred Foo