FW: [Tutor] Trying to d0 HTTP GET

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Apr 19 19:34:49 CEST 2005

On Tue, 19 Apr 2005, Ertl, John wrote:

> I have figured out a bit more.  I can get the binary values from the
> service but I think they come back as a single string.  How do I read
> that into an array?

Hi John,

> The code below will read the first number into the array and print it
> out but how would I read the whole thing into an array...I would like to
> skip the step of putting the raw binary numbers into a variable and
> instead read it directly into the binvalues array.

Do you know how large the array of numbers will be?  Let's check

>>> import struct
>>> struct.calcsize("f")

It looks like each float will be four bytes long, as expected.  Do you
remember if your web service provides these values in little-endian or
big-endian format?

You might be able to get away with just using the 'struct' module,


with its useful 'unpack' function():

import urllib2
import struct

url = ("http://dsd1u:7003/GRID:U:NOGAPS:2005041800:global_360x181:" +
rawdata = urllib2.urlopen(url).read()
numberOfValues = len(rawdata) / struct.calcsize("f")
values = struct.unpack("!%df" % numberOfValues,

I'm assuming for the moment that the only data in rawdata are those
floats, and that the floats are in big-endian "network" byte order.

More information about the Tutor mailing list