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
something.
######
>>> import struct
>>> struct.calcsize("f")
4
######
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,
http://www.python.org/doc/lib/module-struct.html
with its useful 'unpack' function():
#####
import urllib2
import struct
url = ("http://dsd1u:7003/GRID:U:NOGAPS:2005041800:global_360x181:" +
"air_temp:ht_sfc:00020000:00000000:fcst_ops:0240")
rawdata = urllib2.urlopen(url).read()
numberOfValues = len(rawdata) / struct.calcsize("f")
values = struct.unpack("!%df" % numberOfValues,
rawData)
######
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.
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor