FW: [Tutor] Trying to d0 HTTP GET
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?
> 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
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
You might be able to get away with just using the 'struct' module,
with its useful 'unpack' function():
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