Converting float to 32bit signed Integer value? (newbie)
MangoMan
mangoman at kitsuneaye.co.uk
Sat Oct 11 13:26:42 EDT 2003
Hi there,
Currently i am reading an array of signed int's from a file :
fs = open("somefile", "rb")
self.buffer32 = array('i')
self.buffer32.fromfile(fs)
# ...
fs.close()
However, i need to read a float from this array, but of course, the
following code does not work :
value = float(self.buffer32.pop(0))
e.g instead of getting a value like 2.456 i get 2
How could i properly extract floats from this buffer in phython?
Additionally, how could i store floats into this buffer?
e.g(which doesn't work) :
value = 2.234
self.buffer32.append(int(value))
(In the C code, the float is written to the buffer using a typecast,
e.g buff[pos] = (int)value)
Thanks for any help,
-MangoMan
More information about the Python-list
mailing list