buffer interface problem

Chris Rebert clp2 at rebertia.com
Thu Jan 7 10:13:50 CET 2010

On Thu, Jan 7, 2010 at 12:19 AM, Andrew Gillanders
<andrew.gillanders at uqconnect.edu.au> wrote:
> I have run into a problem running a Python script that is part of the
> TerraGear suite for building scenery for FlightGear. I am using Mac OS X
> 10.4, running Python (version 3.0.1) in a Unix terminal.
> The purpose of the script is to walk a directory tree, unzipping files, and
> passing the contents to an executable C program. The problem occurs here:
>    gzin = GzipFile(fname, 'rb')
>    data = gzin.readline()
>    min_x,min_y = map(atoi,data.split()[:2])
> The input file, when uncompressed, is an ASCII file with a line with two
> numbers, then a line of four numbers, then many long lines of numbers. I can
> see what the last is trying to do: split the string into two words, convert
> them to integers, and assign them to min_x and min_y.
> At the third line, I get the message "expected an object with the buffer
> interface". Which object is it referring to?

The elements of the list produced by `data.split()[:2]`, which are
either Unicode strings or bytestrings, neither of which are buffers.

> Have some functions been
> changed to pass buffer objects instead of strings? How can I fix the source
> code to make it run?

The error is being raised by the atoi() function (in the future,
please post the full Traceback, not just the final error message).
What module/library does your atoi() function come from (look for an
`import` statement mentioning it)?
The only functions by that name in the Python standard library both
operate on strings, not buffers, and thus can't be the same one your
code is using.

In any case, replacing `atoi` with `int` in your code will likely
solve the problem. The built-in int() function* can convert strings to


*Not really a function, but close enough for newbie explanatory purposes.

More information about the Python-list mailing list