Problem with python array's...

MangoMan mangoman at kitsuneaye.co.uk
Fri Oct 10 12:37:28 EDT 2003


Hi there,

Currently i am having a problem with python's array class.

I am reading 3 arrays from a file (self.buffer32, self.buffer16,
self.buffer8 from self.fs) :

# ... 
self.Allocated32 = offset16
self.Allocated16 = offset8-offset16
self.Allocated8  = totalSize-offset8
print "Array should be size %d %d %d (32, 16, 8)" % (self.Allocated32,
self.Allocated16, self.Allocated8)

self.buffer32.fromfile(self.fs,self.Allocated32)
self.buffer16.fromfile(self.fs,self.Allocated16)
self.buffer8.fromfile(self.fs,self.Allocated8)
# ...

According to my code, each array should be 6 items long. However, when
printing out the buffer's after reading, i get :

Array should be size 6 6 6 (32, 16, 8)
Buffers :
array('b', [72, 73, 0, 72, 73, 0, 1, 2, 3])
array('h', [0, 1, 657, 0, 1, 657, 666, 2, 3])
array('i', [0, 2000, 1000, 0, 2000, 1000, 1, 2, 3])

And if you wish to know, the buffer's should be :

array('b', [72, 73, 0, 1, 2, 3])
array('h', [0, 1, 657, 666, 2, 3])
array('i', [0, 2000, 1000, 1, 2, 3])

(b is buffer8, h is buffer16, i is buffer32)
Mysteriously, 3 extra items are added onto each array, in exactly the same
place. When looking at the file in a hex editor, these number's do not
exist at all!

Can anyone suggest what on earth is going on?

Version output of python -v :
Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
(Simply Redhat 9 with the Python 2.2.2)


Thanks for any help
-MangoMan






More information about the Python-list mailing list