5
votes

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?

1

1 Answers

4
votes

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.